micromark / micromark-extension-directive

micromark extension to support generic directives (`:cite[smith04]`)
https://unifiedjs.com
MIT License
31 stars 16 forks source link

Add support for balanced brackets in labels #7

Closed EdAyers closed 3 years ago

EdAyers commented 3 years ago

Nested directives

Currrently micromark-extension-directive 1.1.2 doesn't seem to support nested directives. Perhaps this is unsupported or is not in the standard for some sensible reason.

Hello :i[Here is a :b[inner] thing].

Is sent to the following mdast

{
    "type": "paragraph",
    "children": [
        {
            "type": "text",
            "value": "Hello "
        },
        {
            "type": "textDirective",
            "name": "i",
            "attributes": {},
            "children": []
        },
        {
            "type": "text",
            "value": "[Here is a "
        },
        {
            "type": "textDirective",
            "name": "b",
            "attributes": {},
            "children": [
                {
                    "type": "text",
                    "value": "inner"
                }
            ]
        },
        {
            "type": "text",
            "value": " thing]."
        }
    ]
}

(ignoring position data).

We should expect the i textDirective to include all of the text between the two outer square brackets and have a nested b textDirective.

Here is the code that produced this output:

var unified = require('unified')
var directive = require('remark-directive')
var parse = require('remark-parse')

var x = unified()
  .use(parse)
  .use(directive)
  .parse("Hello :i[Here is a :b[inner] thing].")

console.log(JSON.stringify(x.children[0]))

versions:

    "remark-directive": "^1.0.1",
    "remark-parse": "^9.0.0",
    "unified": "^9.2.0",
wooorm commented 3 years ago

Hmm, I think I agree with you, that nested brackets should be supported. And also for leafs/containers.

wooorm commented 3 years ago

Released! https://github.com/micromark/micromark-extension-directive/releases/tag/1.2.0