Skip to content

Commit

Permalink
Fix to restrict colon after name in text directive
Browse files Browse the repository at this point in the history
Related to remarkjs/remark#651.
Closes GH-9.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
  • Loading branch information
wooorm authored Mar 16, 2021
1 parent 08f25b8 commit e0fe913
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/tokenize-directive-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ function tokenizeDirectiveText(effects, ok, nok) {
}

function afterName(code) {
return code === 91 /* `[` */
return code === 58 /* `:` */
? nok(code)
: code === 91 /* `[` */
? effects.attempt(label, afterLabel, afterLabel)(code)
: afterLabel(code)
}
Expand Down
9 changes: 7 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ He dies.
The `name` part is required. The first character must be a letter, other
characters can be alphanumerical and `-`.

The `[label]` part is optional (`:x` and `:x[]` are equivalent).
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*
c]`.

The `{attributes}` part is optional (`:x` and `:x{}` are equivalent).
The `{attributes}` part is optional (`:x` and `:x{}` are equivalent).
When used, it is handled like HTML attributes, such as that `{a}`, `{a=""}`,
, `{a=''}` but also `{a=b}`, `{a="b"}`, and `{a='b'}` are equivalent.
Shortcuts are available for `id=` (`{#readme}` for `{id=readme}`) and
Expand All @@ -161,6 +161,11 @@ When multiple ids are found, the last is used; when multiple classes are found,
they are combined: `{.red class=green .blue}` is equivalent to
`{.red .green .blue}` and `{class="red green blue"}`.

† there is one case where a name must be followed by an empty label or empty
attributes: a *text* directive that only has a name, cannot be followed by a
colon. So, `:red:` doesn’t work. Use either `:red[]` or `:red{}` instead.
The reason for this is to allow GitHub emoji (gemoji) and directives to coexist.

Containers can be nested by using more colons outside:

::::spoiler
Expand Down
6 changes: 6 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ test('micromark-extension-directive (syntax)', function (t) {
'should support a dash in a name'
)

t.equal(
micromark(':a:', options()),
'<p>:a:</p>',
'should *not* support a colon right after a name'
)

t.equal(
micromark(':a[', options()),
'<p>[</p>',
Expand Down

0 comments on commit e0fe913

Please sign in to comment.