Skip to content

Commit

Permalink
Implement fenced_divs syntax extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Witiko committed Nov 9, 2022
1 parent f44d032 commit a558018
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -21246,6 +21246,14 @@ parsers.fencehead = function(char)
* parsers.optionalspace * (parsers.newline + parsers.eof)
end

parsers.fencehead_with_attributes
= function(char)
return C(parsers.nonindentspace) / function(s) fenceindent = #s end
* Cg(char^3, "fencelength")
* parsers.optionalspace * Ct(parsers.attributes)
* parsers.optionalspace * (parsers.newline + parsers.eof)
end

parsers.fencetail = function(char)
return parsers.nonindentspace
* Cmt(C(char^3) * Cb("fencelength"), captures_geq_length)
Expand Down Expand Up @@ -23475,8 +23483,46 @@ end
M.extensions.fenced_divs = function()
return {
name = "built-in fenced_divs syntax extension",
extend_writer = function()
end, extend_reader = function()
extend_writer = function(self)
% \end{macrocode}
% \par
% \begin{markdown}
%
% Define \luamdef{writer->div} as a function that will transform an input
% fenced div with content `c` and with attributes `attr` to the output format.
%
% \end{markdown}
% \begin{macrocode}
function self.div(c, attr)
return {"\\markdownRendererFencedDiv{",c,"}{",attr,"}"}
end
end, extend_reader = function(self)
local parsers = self.parsers
local parse_blocks = self.parser_functions.parse_blocks
local writer = self.writer

local FencedDiv = parsers.fencehead_with_attributes(parsers.colon)
* Cs(parsers.fencedline(parsers.colon)^0)
* parsers.fencetail(parsers.colon)
/ function(attr, s)
local content = parse_blocks(s)
return writer.div(content, attr)
end

self.insert_pattern("Block after Verbatim",
FencedDiv, "FencedDiv")

local fencestart
if blank_before_div_fence then
fencestart = parsers.fail
else
fencestart = parsers.fencehead_with_attributes(parsers.colon)
end

local EndlineExceptions = parsers.EndlineExceptions + fencestart
self.update_rule("EndlineExceptions", EndlineExceptions)

self.add_special_character(":")
end
}
end
Expand Down

0 comments on commit a558018

Please sign in to comment.