Skip to content
Permalink
Browse files

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.
  • Loading branch information...
jgm committed Apr 29, 2019
1 parent 026ca82 commit 9b3c06d9647167c8b92caf118244dbdebd574e0c
Showing with 16 additions and 5 deletions.
  1. +16 −5 tools/make_spec.lua
@@ -23,15 +23,26 @@ 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 = {}
for cur, entering, node_type in cmark.walk(doc) do
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)

0 comments on commit 9b3c06d

Please sign in to comment.
You can’t perform that action at this time.