Skip to content

Commit

Permalink
fix: Incorrect header identifier in nested blocks in Djot
Browse files Browse the repository at this point in the history
  • Loading branch information
Omikhleia authored and Didier Willis committed Jul 24, 2023
1 parent f9ba0ab commit 5a1251b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions inputters/djot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ end

function Renderer:para (node)
if #node.c == 1 and node.c[1].t == "symbol" then
-- Tweak the standalone symbol to be marked as "kind of" a block element.
node.c[1]._standalone_ = true
end

Expand Down Expand Up @@ -106,15 +107,24 @@ function Renderer:div (node)
end

function Renderer:section (node)
self.currentid = node.attr and node.attr.id
-- djot.lua differs from djot.js
-- See https://github.com/jgm/djot/issues/213#issuecomment-1647755452
-- A section is inserted when a header is found at the document level.
-- The id is set on the section, not on the header.
-- But attributes are set on the header, not on the section with djot.lua
-- whereas they are set on the section with djot.js.
self.sectionid = node.attr and node.attr.id
local content = self:render_children(node)
return content
end

function Renderer:heading (node)
local options = node.attr or {}
local content = self:render_children(node)
options.id = self.currentid
-- See above:
-- At document level, the id is set on the section.
-- But in nested blocks (e.g. in divs), the id is set on the header.
options.id = options.id or self.sectionid
options.level = node.level
return utils.createCommand("markdown:internal:header", options, content)
end
Expand Down

0 comments on commit 5a1251b

Please sign in to comment.