Skip to content

Remove directive metadata copied to children #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/directives/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export class Code extends Directive {
content: data.body,
map: data.bodyMap
})
if (data.options["number-lines"]) {
token.attrSet("number-lines", data.options["number-lines"])
}
if (data.options.force) {
token.attrSet("force", data.options.force)
}
if (data.options.name) {
token.attrSet("name", data.options.name)
}
if (data.options.class) {
token.attrJoin("class", data.options.class.join(" "))
}
return [token]
}
}
Expand Down Expand Up @@ -77,6 +89,31 @@ export class CodeBlock extends Directive {
content: data.body,
map: data.bodyMap
})
if (data.options.linenos === null) {
token.attrSet("linenos", "true")
}
if (data.options["lineno-start"]) {
token.attrSet("lineno-start", data.options["lineno-start"])
}
if (data.options.dedent) {
token.attrSet("dedent", data.options.dedent)
}
if (data.options["emphasize-lines"]) {
token.attrSet("emphasize-lines", data.options["emphasize-lines"])
}
if (data.options.caption) {
token.attrSet("caption", data.options.caption)
}
if (data.options.force) {
token.attrSet("force", data.options.force)
}
if (data.options.name) {
token.attrSet("name", data.options.name)
}
if (data.options.class) {
token.attrJoin("class", data.options.class.join(" "))
}

return [token]
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/directives/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function runDirectives(directives: {
try {
const directive = new directives[token.info](state)
const data = directiveToData(token, directive)
const [content, opts] = parseDirectiveOptions(
const [content] = parseDirectiveOptions(
token.content.trim() ? token.content.split(/\r?\n/) : [],
directive
)
Expand All @@ -63,19 +63,13 @@ function runDirectives(directives: {
directiveOpen.content = content.join("\n").trim()
directiveOpen.meta = {
arg: token.meta.arg,
opts
opts: data.options
}
const newTokens = [directiveOpen]
newTokens.push(...directive.run(data))
const directiveClose = new state.Token("parsed_directive_close", "", -1)
directiveClose.hidden = true
newTokens.push(directiveClose)
// Ensure `meta` exists and add the directive options to parsed child
newTokens[1].meta = {
directive: true,
...data.options,
...newTokens[1].meta
}
finalTokens.push(...newTokens)
} catch (err) {
const errorToken = new state.Token("directive_error", "", 0)
Expand Down
3 changes: 3 additions & 0 deletions src/directives/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export class ListTable extends Directive {

// table opening
const tableOpen = this.createToken("table_open", "table", 1, { map: data.bodyMap })
if (data.options.name) {
tableOpen.attrSet("name", data.options.name)
}
if (data.options.align) {
tableOpen.attrJoin("class", `align-${data.options.align}`)
}
Expand Down