Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit e680a5b

Browse files
2nthonyegoist
authored andcommitted
fix(markdown): support vue's @ attribute names (#249)
* feat(marked): support `@` in attribute names * docs: using `@` shorthand * chore: add comment for modified * docs: remove `trade-off` section
1 parent 71fc2b0 commit e680a5b

File tree

9 files changed

+15
-21
lines changed

9 files changed

+15
-21
lines changed

src/utils/marked.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,11 @@ inline.autolink = edit(inline.autolink)
583583
.replace('email', inline._email)
584584
.getRegex()
585585

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

588592
inline.tag = edit(inline.tag)
589593
.replace('comment', block._comment)

website/docs/builtin-components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ A customized `<select>` component:
152152

153153
<!-- prettier-ignore -->
154154
````vue
155-
<docute-select :value="favoriteFruit" v-on:change="handleChange">
155+
<docute-select :value="favoriteFruit" @change="handleChange">
156156
<option value="apple" :selected="favoriteFruit === 'apple'">Apple</option>
157157
<option value="banana" :selected="favoriteFruit === 'banana'">Banana</option>
158158
<option value="watermelon" :selected="favoriteFruit === 'watermelon'">Watermelon</option>
@@ -176,7 +176,7 @@ module.exports = {
176176
```
177177
````
178178

179-
<docute-select v-on:change="handleChange" :value="favoriteFruit">
179+
<docute-select @change="handleChange" :value="favoriteFruit">
180180
<option value="apple" :selected="favoriteFruit === 'apple'">Apple</option>
181181
<option value="banana" :selected="favoriteFruit === 'banana'">Banana</option>
182182
<option value="watermelon" :selected="favoriteFruit === 'watermelon'">Watermelon</option>

website/docs/guide/customization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Apply custom fonts to your website is pretty easy, you can simply add a `<style>
131131
</style>
132132
```
133133

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

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

website/docs/guide/markdown-features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class SkinnedMesh extends THREE.Mesh {
174174
Adding a Vue mixin to the Markdown component:
175175

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

179179
```js {mixin:true}
180180
{
@@ -187,7 +187,7 @@ Adding a Vue mixin to the Markdown component:
187187
```
188188
````
189189

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

192192
```js {mixin:true}
193193
{

website/docs/guide/use-vue-in-markdown.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,3 @@ __Output__:
8080

8181
<ReverseText text="hello world" />
8282

83-
## Trade-offs
84-
85-
- `@` shorthand won't work
86-
87-
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.

website/docs/zh/builtin-components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ A customized `<select>` component:
151151

152152
<!-- prettier-ignore -->
153153
````vue
154-
<docute-select :value="favoriteFruit" v-on:change="handleChange">
154+
<docute-select :value="favoriteFruit" @change="handleChange">
155155
<option value="apple" :selected="favoriteFruit === 'apple'">Apple</option>
156156
<option value="banana" :selected="favoriteFruit === 'banana'">Banana</option>
157157
<option value="watermelon" :selected="favoriteFruit === 'watermelon'">Watermelon</option>
@@ -175,7 +175,7 @@ module.exports = {
175175
```
176176
````
177177

178-
<docute-select v-on:change="handleChange" :value="favoriteFruit">
178+
<docute-select @change="handleChange" :value="favoriteFruit">
179179
<option value="apple" :selected="favoriteFruit === 'apple'">Apple</option>
180180
<option value="banana" :selected="favoriteFruit === 'banana'">Banana</option>
181181
<option value="watermelon" :selected="favoriteFruit === 'watermelon'">Watermelon</option>

website/docs/zh/guide/customization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ body {
125125
</style>
126126
```
127127

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

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

website/docs/zh/guide/markdown-features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class SkinnedMesh extends THREE.Mesh {
171171
Adding a Vue mixin to the Markdown component:
172172

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

176176
```js {mixin:true}
177177
{
@@ -184,7 +184,7 @@ Adding a Vue mixin to the Markdown component:
184184
```
185185
````
186186

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

189189
```js {mixin:true}
190190
{

website/docs/zh/guide/use-vue-in-markdown.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,3 @@ __输出__:
8080

8181
<ReverseText text="hello world" />
8282

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

0 commit comments

Comments
 (0)