Skip to content

Commit

Permalink
fix(markdown): support vue's @ attribute names (#249)
Browse files Browse the repository at this point in the history
* feat(marked): support `@` in attribute names

* docs: using `@` shorthand

* chore: add comment for modified

* docs: remove `trade-off` section
  • Loading branch information
2nthony authored and egoist committed Jul 6, 2019
1 parent 71fc2b0 commit e680a5b
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 21 deletions.
6 changes: 5 additions & 1 deletion src/utils/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,11 @@ inline.autolink = edit(inline.autolink)
.replace('email', inline._email)
.getRegex()

inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/
// @modified
// old
// inline._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/
// new for support `@` attribute names
inline._attribute = /\s+[a-zA-Z@:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/

inline.tag = edit(inline.tag)
.replace('comment', block._comment)
Expand Down
4 changes: 2 additions & 2 deletions website/docs/builtin-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ A customized `<select>` component:

<!-- prettier-ignore -->
````vue
<docute-select :value="favoriteFruit" v-on:change="handleChange">
<docute-select :value="favoriteFruit" @change="handleChange">
<option value="apple" :selected="favoriteFruit === 'apple'">Apple</option>
<option value="banana" :selected="favoriteFruit === 'banana'">Banana</option>
<option value="watermelon" :selected="favoriteFruit === 'watermelon'">Watermelon</option>
Expand All @@ -176,7 +176,7 @@ module.exports = {
```
````

<docute-select v-on:change="handleChange" :value="favoriteFruit">
<docute-select @change="handleChange" :value="favoriteFruit">
<option value="apple" :selected="favoriteFruit === 'apple'">Apple</option>
<option value="banana" :selected="favoriteFruit === 'banana'">Banana</option>
<option value="watermelon" :selected="favoriteFruit === 'watermelon'">Watermelon</option>
Expand Down
2 changes: 1 addition & 1 deletion website/docs/guide/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Apply custom fonts to your website is pretty easy, you can simply add a `<style>
</style>
```

<button v-on:click="insertCustomFontsCSS">Click me</button> to toggle the custom fonts on this website.
<button @click="insertCustomFontsCSS">Click me</button> to toggle the custom fonts on this website.

By default a fresh Docute website will use system default fonts.

Expand Down
4 changes: 2 additions & 2 deletions website/docs/guide/markdown-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class SkinnedMesh extends THREE.Mesh {
Adding a Vue mixin to the Markdown component:

````markdown
<button v-on:click="count++">{{ count }}</button> people love Docute.
<button @click="count++">{{ count }}</button> people love Docute.

```js {mixin:true}
{
Expand All @@ -187,7 +187,7 @@ Adding a Vue mixin to the Markdown component:
```
````

<button v-on:click="count++">{{ count }}</button> people love Docute.
<button @click="count++">{{ count }}</button> people love Docute.

```js {mixin:true}
{
Expand Down
5 changes: 0 additions & 5 deletions website/docs/guide/use-vue-in-markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,3 @@ __Output__:

<ReverseText text="hello world" />

## Trade-offs

- `@` shorthand won't work

Since standard HTML attribute isn't allowed to start with `@`, the `@` shorthand for `v-on` directive won't be recognized as valid HTML by the markdown parser we use. Pull request is very welcome for fixing this.
4 changes: 2 additions & 2 deletions website/docs/zh/builtin-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ A customized `<select>` component:

<!-- prettier-ignore -->
````vue
<docute-select :value="favoriteFruit" v-on:change="handleChange">
<docute-select :value="favoriteFruit" @change="handleChange">
<option value="apple" :selected="favoriteFruit === 'apple'">Apple</option>
<option value="banana" :selected="favoriteFruit === 'banana'">Banana</option>
<option value="watermelon" :selected="favoriteFruit === 'watermelon'">Watermelon</option>
Expand All @@ -175,7 +175,7 @@ module.exports = {
```
````

<docute-select v-on:change="handleChange" :value="favoriteFruit">
<docute-select @change="handleChange" :value="favoriteFruit">
<option value="apple" :selected="favoriteFruit === 'apple'">Apple</option>
<option value="banana" :selected="favoriteFruit === 'banana'">Banana</option>
<option value="watermelon" :selected="favoriteFruit === 'watermelon'">Watermelon</option>
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/guide/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ body {
</style>
```

<button v-on:click="insertCustomFontsCSS">Click me</button> to toggle the custom fonts on this website.
<button @click="insertCustomFontsCSS">Click me</button> to toggle the custom fonts on this website.

By default a fresh Docute website will use system default fonts.

Expand Down
4 changes: 2 additions & 2 deletions website/docs/zh/guide/markdown-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class SkinnedMesh extends THREE.Mesh {
Adding a Vue mixin to the Markdown component:

````markdown
<button v-on:click="count++">{{ count }}</button> people love Docute.
<button @click="count++">{{ count }}</button> people love Docute.

```js {mixin:true}
{
Expand All @@ -184,7 +184,7 @@ Adding a Vue mixin to the Markdown component:
```
````

<button v-on:click="count++">{{ count }}</button> people love Docute.
<button @click="count++">{{ count }}</button> people love Docute.

```js {mixin:true}
{
Expand Down
5 changes: 0 additions & 5 deletions website/docs/zh/guide/use-vue-in-markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,3 @@ __输出__:

<ReverseText text="hello world" />

## Trade-offs

- `@` 简写语法不能工作

由于标准的 HTML 属性不允许以 `@` 开头,因此我们使用的 markdown 解析器不会将 `v-on` 的简写 `@` 识别为有效的 HTML。非常欢迎大家发起 Pull Request 解决该问题。

0 comments on commit e680a5b

Please sign in to comment.