diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-04-28 23:04:01 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-04-28 23:04:01 -0700 |
commit | 9b3c06d9647167c8b92caf118244dbdebd574e0c (patch) | |
tree | a53ec5c615e083127ad5a38ed4a025d63dd7e643 /tools | |
parent | 026ca8234ba2e7785beaff5416f7e9bb1a8edd98 (diff) |
Fix tools/make_spec.lua so it properly handles cross-refs.
Previously it broke in a few cases, e.g. with soft breaks.
This fixes the issue described in #578.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/make_spec.lua | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tools/make_spec.lua b/tools/make_spec.lua index 641bf58..05a1270 100644 --- a/tools/make_spec.lua +++ b/tools/make_spec.lua @@ -23,6 +23,18 @@ local render_number = function(tbl) return table.concat(buf, '.') end +local extract_label = function(cur) + local label = "" + for subcur, subentering, subnode_type in cmark.walk(cur) do + if subentering and subnode_type == cmark.NODE_TEXT then + label = label .. cmark.node_get_literal(subcur) + elseif subentering and subnode_type == cmark.NODE_SOFTBREAK then + label = label .. " " + end + end + return label +end + local extract_references = function(doc) local cur, entering, node_type local refs = {} @@ -30,8 +42,7 @@ 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 child = cmark.node_first_child(cur) - local label = trim(cmark.render_commonmark(child, OPT_DEFAULT + OPT_UNSAFE, 0)) + local label = extract_label(cur) local ident = to_identifier(label) if refs[label] then warn("duplicate reference " .. label) @@ -118,8 +129,7 @@ local create_anchors = function(doc, meta, to) node_type == cmark.NODE_HEADING) then local anchor - local child = cmark.node_first_child(cur) - local label = trim(cmark.render_commonmark(child, OPT_DEFAULT + OPT_UNSAFE, 0)) + local label = extract_label(cur) local ident = to_identifier(label) if node_type == cmark.NODE_LINK then if format == 'latex' then @@ -167,7 +177,8 @@ local create_anchors = function(doc, meta, to) end end end - local children = {}; + local children = {} + local child = cmark.node_first_child(cur) while child do children[#children + 1] = child child = cmark.node_next(child) |