diff --git a/dev/lib/factory-name.js b/dev/lib/factory-name.js index 29a1a8a..7d3d26d 100644 --- a/dev/lib/factory-name.js +++ b/dev/lib/factory-name.js @@ -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) } } diff --git a/readme.md b/readme.md index 0e66c70..a055e8e 100644 --- a/readme.md +++ b/readme.md @@ -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* diff --git a/test/index.js b/test/index.js index eb627e7..765f02b 100644 --- a/test/index.js +++ b/test/index.js @@ -62,11 +62,17 @@ test('micromark-extension-directive (syntax)', (t) => { ) t.equal( - micromark(':a-', options()), + micromark(':a-b', options()), '
', 'should support a dash in a name' ) + t.equal( + micromark(':a-', options()), + ':a-
', + 'should *not* support a dash at the end of a name' + ) + t.equal( micromark(':a_b', options()), '', @@ -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()), @@ -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' )