Skip to content

Commit

Permalink
Remove support for dash at end of name
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 8, 2021
1 parent 71af94a commit 472c259
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions dev/lib/factory-name.js
Expand Up @@ -27,7 +27,8 @@ export function factoryName(effects, ok, nok, nameType) {
}

effects.exit(nameType)
// To do next major: disallow `-` at end of name too, for consistency.
return self.previous === codes.underscore ? nok(code) : ok(code)
return self.previous === codes.dash || self.previous === codes.underscore
? nok(code)
: ok(code)
}
}
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -150,7 +150,7 @@ He dies.

The `name` part is required. The first character must be a letter, other
characters can be alphanumerical, `-`, and `_`.
`_` cannot end a name.
`-` or `_` cannot end a name.

The `[label]` part is optional (`:x` and `:x[]` are equivalent)†.
When used, it can include text constructs such as emphasis and so on: `x[a *b*
Expand Down
16 changes: 13 additions & 3 deletions test/index.js
Expand Up @@ -62,11 +62,17 @@ test('micromark-extension-directive (syntax)', (t) => {
)

t.equal(
micromark(':a-', options()),
micromark(':a-b', options()),
'<p></p>',
'should support a dash in a name'
)

t.equal(
micromark(':a-', options()),
'<p>:a-</p>',
'should *not* support a dash at the end of a name'
)

t.equal(
micromark(':a_b', options()),
'<p></p>',
Expand Down Expand Up @@ -403,7 +409,11 @@ test('micromark-extension-directive (syntax)', (t) => {
'should support a digit in a name'
)

t.equal(micromark('::a-', options()), '', 'should support a dash in a name')
t.equal(
micromark('::a-b', options()),
'',
'should support a dash in a name'
)

t.equal(
micromark('::a[', options()),
Expand Down Expand Up @@ -744,7 +754,7 @@ test('micromark-extension-directive (syntax)', (t) => {
)

t.equal(
micromark(':::a-', options()),
micromark(':::a-b', options()),
'',
'should support a dash in a name'
)
Expand Down

0 comments on commit 472c259

Please sign in to comment.