Skip to content

Commit

Permalink
Make fenced div and bracketed span writers produce attribute context …
Browse files Browse the repository at this point in the history
…renderers
  • Loading branch information
Witiko committed Nov 23, 2022
1 parent 80da903 commit 514aee1
Showing 1 changed file with 39 additions and 17 deletions.
56 changes: 39 additions & 17 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -20762,6 +20762,36 @@ function M.writer.new(options)
% \par
% \begin{markdown}
%
% Define \luamdef{writer->attributes} as a function that will transform
% input attributes `attr` to the output format.
%
% \end{markdown}
% \begin{macrocode}
function self.attributes(attr)
local buf = {}

table.sort(attr)
local key, value
for i = 1, #attr do
if attr[i]:sub(1, 1) == "#" then
table.insert(buf, {"\\markdownRendererAttributeIdentifier{",
attr[i]:sub(2), "}"})
elseif attr[i]:sub(1, 1) == "." then
table.insert(buf, {"\\markdownRendererAttributeClassName{",
attr[i]:sub(2), "}"})
else
key, value = attr[i]:match("([^= ]+)%s*=%s*(.*)")
table.insert(buf, {"\\markdownRendererAttributeKeyValue{",
key, "}{", value, "}"})
end
end

return buf
end
% \end{macrocode}
% \par
% \begin{markdown}
%
% Define \luamdef{writer->active\_attributes} as a stack of attributes
% of the headings that are currently active. The
% \luamref{writer->active\_headings} member variable is mutable.
Expand Down Expand Up @@ -20856,21 +20886,7 @@ function M.writer.new(options)
end

if self.is_writing then
table.sort(attributes)
local key, value
for i = 1, #attributes do
if attributes[i]:sub(1, 1) == "#" then
table.insert(buf, {"\\markdownRendererAttributeIdentifier{",
attributes[i]:sub(2), "}"})
elseif attributes[i]:sub(1, 1) == "." then
table.insert(buf, {"\\markdownRendererAttributeClassName{",
attributes[i]:sub(2), "}"})
else
key, value = attributes[i]:match("([^= ]+)%s*=%s*(.*)")
table.insert(buf, {"\\markdownRendererAttributeKeyValue{",
key, "}{", value, "}"})
end
end
table.insert(buf, self.attributes(attributes))
end

local cmd
Expand Down Expand Up @@ -22710,7 +22726,10 @@ M.extensions.bracketed_spans = function()
% \end{markdown}
% \begin{macrocode}
function self.span(s, attr)
return {"\\markdownRendererBracketedSpan{",s,"}{",attr,"}"}
return {"\\markdownRendererBracketedSpanAttributeContextBegin",
self.attributes(attr),
"\\markdownRendererBracketedSpan{",s,"}",
"\\markdownRendererBracketedSpanAttributeContextEnd{}"}
end
end, extend_reader = function(self)
local parsers = self.parsers
Expand Down Expand Up @@ -23490,7 +23509,10 @@ M.extensions.fenced_divs = function(blank_before_div_fence)
% \end{markdown}
% \begin{macrocode}
function self.div(c, attr)
return {"\\markdownRendererFencedDiv{",c,"}{",attr,"}"}
return {"\\markdownRendererFencedDivAttributeContextBegin",
self.attributes(attr),
"\\markdownRendererFencedDiv{",c,"}",
"\\markdownRendererFencedDivAttributeContextEnd"}
end
end, extend_reader = function(self)
local parsers = self.parsers
Expand Down

0 comments on commit 514aee1

Please sign in to comment.