aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorZhiming Wang <github@zmwang.pw>2018-10-04 12:26:36 -0400
committerJohn MacFarlane <jgm@berkeley.edu>2018-10-04 09:26:36 -0700
commit5dc2aed09a070c215d62f69998f9edd428eec2e6 (patch)
treea5959abbfe588532b0798cc3ad234e1d34270150 /tools
parent04b3fdede574c59aefed90cb6cbb7a42d4a7332d (diff)
make_spec.lua: fix migration of children nodes in create_anchors (#536)
* make_spec.lua: rename children to child Naming a variable "children" when it holds one child is confusing, and blocks naming actual children. * make_spec.lua: fix migration of children nodes in create_anchors Prior to this commit, when migrating the children of a node to a new one, children are moved as they are iterated via `cmark_node_next`; however, when a child is moved under the new node, its next relationship with its sibling is broken, so in fact at most one child is migrated, and the rest are lost. This resulted in cases like [Decimal numeric character references](@) consist of... (note the softbreak) being eventually rendered as <a ...>Decimal numeric character</a> consist of...
Diffstat (limited to 'tools')
-rw-r--r--tools/make_spec.lua19
1 files changed, 11 insertions, 8 deletions
diff --git a/tools/make_spec.lua b/tools/make_spec.lua
index 60bcb18..acfdb61 100644
--- a/tools/make_spec.lua
+++ b/tools/make_spec.lua
@@ -30,8 +30,8 @@ local extract_references = function(doc)
if not entering and
((node_type == cmark.NODE_LINK and cmark.node_get_url(cur) == '@') or
node_type == cmark.NODE_HEADING) then
- local children = cmark.node_first_child(cur)
- local label = trim(cmark.render_commonmark(children, OPT_DEFAULT, 0))
+ local child = cmark.node_first_child(cur)
+ local label = trim(cmark.render_commonmark(child, OPT_DEFAULT, 0))
local ident = to_identifier(label)
if refs[label] then
warn("duplicate reference " .. label)
@@ -118,8 +118,8 @@ local create_anchors = function(doc, meta, to)
node_type == cmark.NODE_HEADING) then
local anchor
- local children = cmark.node_first_child(cur)
- local label = trim(cmark.render_commonmark(children, OPT_DEFAULT, 0))
+ local child = cmark.node_first_child(cur)
+ local label = trim(cmark.render_commonmark(child, OPT_DEFAULT, 0))
local ident = to_identifier(label)
if node_type == cmark.NODE_LINK then
if format == 'latex' then
@@ -167,9 +167,13 @@ local create_anchors = function(doc, meta, to)
end
end
end
- while children do
- node_append_child(anchor, children)
- children = cmark.node_next(children)
+ local children = {};
+ while child do
+ children[#children + 1] = child
+ child = cmark.node_next(child)
+ end
+ for _,child in ipairs(children) do
+ node_append_child(anchor, child)
end
cmark.node_insert_before(cur, anchor)
cmark.node_unlink(cur)
@@ -289,4 +293,3 @@ else
io.stderr:write(msg)
os.exit(1)
end
-