summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/markdown/markdown.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2023-04-03 21:32:50 +0000
committerKarl Berry <karl@freefriends.org>2023-04-03 21:32:50 +0000
commit69c679a19d6d919414bc1268718ab445e225d930 (patch)
tree341cf0686552fc6a306b511ec0c19dc73e00f133 /Master/texmf-dist/tex/luatex/markdown/markdown.lua
parentf587320cb4c3114a76584fc12b89cdba7c1db07c (diff)
markdown (3apr23)
git-svn-id: svn://tug.org/texlive/trunk@66751 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/markdown/markdown.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/markdown/markdown.lua624
1 files changed, 486 insertions, 138 deletions
diff --git a/Master/texmf-dist/tex/luatex/markdown/markdown.lua b/Master/texmf-dist/tex/luatex/markdown/markdown.lua
index cd6aaf80c68..1e68b8ae84f 100644
--- a/Master/texmf-dist/tex/luatex/markdown/markdown.lua
+++ b/Master/texmf-dist/tex/luatex/markdown/markdown.lua
@@ -58,7 +58,7 @@
-- those in the standard .ins files.
--
local metadata = {
- version = "2.21.0-0-gee15b88",
+ version = "2.22.0-0-g5a3d0fe",
comment = "A module for the conversion from markdown to plain TeX",
author = "John MacFarlane, Hans Hagen, Vít Novotný",
copyright = {"2009-2016 John MacFarlane, Hans Hagen",
@@ -77,19 +77,24 @@ local unicode
unicode = {utf8 = {char=utf8.char}}
end
end)()
-local md5 = require("md5")
-local uni_case
+local md5 = require("md5");
(function()
+ local should_initialize = package.loaded.kpse == nil
+ or tex.initialize ~= nil
local ran_ok
- -- TODO: Stop loading kpse module to a global kpse variable
- -- after https://github.com/latex3/lua-uni-algos/issues/3 has been fixed.
- -- Remove kpse global also from file .luacheckrc.
ran_ok, kpse = pcall(require, "kpse")
- if ran_ok then
+ if ran_ok and should_initialize then
kpse.set_program_name("luatex")
- ran_ok, uni_case = pcall(require, "lua-uni-case")
end
if not ran_ok then
+ kpse = {lookup = function(f, _) return f end}
+ end
+end)()
+local uni_case
+(function()
+ local ran_ok
+ ran_ok, uni_case = pcall(require, "lua-uni-case")
+ if not ran_ok then
if unicode.utf8.lower then
uni_case = {casefold = unicode.utf8.lower}
else
@@ -163,9 +168,11 @@ defaultOptions.hashEnumerators = false
defaultOptions.headerAttributes = false
defaultOptions.html = false
defaultOptions.hybrid = false
+defaultOptions.inlineCodeAttributes = false
defaultOptions.inlineFootnotes = false
defaultOptions.inlineNotes = false
defaultOptions.jekyllData = false
+defaultOptions.linkAttributes = false
defaultOptions.lineBlocks = false
defaultOptions.footnotes = false
defaultOptions.notes = false
@@ -185,6 +192,8 @@ defaultOptions.tableCaptions = false
defaultOptions.taskLists = false
defaultOptions.texComments = false
defaultOptions.texMathDollars = false
+defaultOptions.texMathDoubleBackslash = false
+defaultOptions.texMathSingleBackslash = false
defaultOptions.tightLists = true
defaultOptions.underscores = true
local upper, format, length =
@@ -227,20 +236,9 @@ function util.encode_json_string(s)
s = s:gsub([["]], [[\"]])
return [["]] .. s .. [["]]
end
-util.lookup_files = (function()
- local ran_ok, kpse = pcall(require, "kpse")
- if ran_ok then
- kpse.set_program_name("luatex")
- else
- kpse = { lookup = function(f, _) return f end }
- end
-
- local function lookup_files(f, options)
- return kpse.lookup(f, options)
- end
-
- return lookup_files
-end)()
+function util.lookup_files(f, options)
+ return kpse.lookup(f, options)
+end
function util.expand_tabs_in_line(s, tabstop)
local tab = tabstop or 4
local corr = 0
@@ -2494,20 +2492,54 @@ function M.writer.new(options)
self.string = escape_typographic_text
self.uri = escape_programmatic_text
end
- function self.code(s)
- return {"\\markdownRendererCodeSpan{",self.escape(s),"}"}
+ function self.code(s, attributes)
+ local buf = {}
+ if attributes ~= nil then
+ table.insert(buf,
+ "\\markdownRendererCodeSpanAttributeContextBegin\n")
+ table.insert(buf, self.attributes(attributes))
+ end
+ table.insert(buf,
+ {"\\markdownRendererCodeSpan{", self.escape(s), "}"})
+ if attributes ~= nil then
+ table.insert(buf,
+ "\n\\markdownRendererCodeSpanAttributeContextEnd ")
+ end
+ return buf
end
- function self.link(lab,src,tit)
- return {"\\markdownRendererLink{",lab,"}",
- "{",self.escape(src),"}",
- "{",self.uri(src),"}",
- "{",self.string(tit or ""),"}"}
+ function self.link(lab, src, tit, attributes)
+ local buf = {}
+ if attributes ~= nil then
+ table.insert(buf,
+ "\\markdownRendererLinkAttributeContextBegin\n")
+ table.insert(buf, self.attributes(attributes))
+ end
+ table.insert(buf, {"\\markdownRendererLink{",lab,"}",
+ "{",self.escape(src),"}",
+ "{",self.uri(src),"}",
+ "{",self.string(tit or ""),"}"})
+ if attributes ~= nil then
+ table.insert(buf,
+ "\n\\markdownRendererLinkAttributeContextEnd ")
+ end
+ return buf
end
- function self.image(lab,src,tit)
- return {"\\markdownRendererImage{",lab,"}",
- "{",self.string(src),"}",
- "{",self.uri(src),"}",
- "{",self.string(tit or ""),"}"}
+ function self.image(lab, src, tit, attributes)
+ local buf = {}
+ if attributes ~= nil then
+ table.insert(buf,
+ "\\markdownRendererImageAttributeContextBegin\n")
+ table.insert(buf, self.attributes(attributes))
+ end
+ table.insert(buf, {"\\markdownRendererImage{",lab,"}",
+ "{",self.string(src),"}",
+ "{",self.uri(src),"}",
+ "{",self.string(tit or ""),"}"})
+ if attributes ~= nil then
+ table.insert(buf,
+ "\n\\markdownRendererImageAttributeContextEnd ")
+ end
+ return buf
end
function self.bulletlist(items,tight)
if not self.is_writing then return "" end
@@ -2612,8 +2644,14 @@ function M.writer.new(options)
local buf = {}
table.sort(attr)
+ local seen = {}
local key, value
for i = 1, #attr do
+ if seen[attr[i]] ~= nil then
+ goto continue -- prevent duplicate attributes
+ else
+ seen[attr[i]] = true
+ end
if attr[i]:sub(1, 1) == "#" then
table.insert(buf, {"\\markdownRendererAttributeIdentifier{",
attr[i]:sub(2), "}"})
@@ -2625,6 +2663,7 @@ function M.writer.new(options)
table.insert(buf, {"\\markdownRendererAttributeKeyValue{",
key, "}{", value, "}"})
end
+ ::continue::
end
return buf
@@ -3075,6 +3114,15 @@ parsers.title = parsers.title_d + parsers.title_s + parsers.title_p
parsers.optionaltitle
= parsers.spnl * parsers.title * parsers.spacechar^0
+ Cc("")
+
+parsers.indirect_link
+ = parsers.tag
+ * ( C(parsers.spnl) * parsers.tag
+ + Cc(nil) * Cc(nil) -- always produce exactly two captures
+ )
+
+parsers.indirect_image
+ = parsers.exclamation * parsers.indirect_link
-- case-insensitive match (we assume s is lowercase). must be single byte encoding
parsers.keyword_exact = function(s)
local parser = P(0)
@@ -3182,7 +3230,7 @@ parsers.tagentity = parsers.ampersand * C(parsers.alphanumeric^1)
-- parse a reference definition: [foo]: /bar "title"
parsers.define_reference_parser = parsers.leader * parsers.tag * parsers.colon
* parsers.spacechar^0 * parsers.url
- * parsers.optionaltitle * parsers.blankline^1
+ * parsers.optionaltitle
parsers.Inline = V("Inline")
parsers.IndentedInline = V("IndentedInline")
@@ -3192,7 +3240,26 @@ parsers.between = function(p, starter, ender)
return (starter * #parsers.nonspacechar * Ct(p * (p - ender2)^0) * ender2)
end
-parsers.urlchar = parsers.anyescaped - parsers.newline - parsers.more
+parsers.urlchar = parsers.anyescaped
+ - parsers.newline
+ - parsers.more
+
+parsers.auto_link_url = parsers.less
+ * C( parsers.alphanumeric^1 * P("://")
+ * parsers.urlchar^1)
+ * parsers.more
+
+parsers.auto_link_email
+ = parsers.less
+ * C((parsers.alphanumeric + S("-._+"))^1
+ * P("@") * parsers.urlchar^1)
+ * parsers.more
+
+parsers.auto_link_relative_reference
+ = parsers.less
+ * C(parsers.urlchar^1)
+ * parsers.more
+
parsers.lineof = function(c)
return (parsers.leader * (P(c) * parsers.optionalspace)^3
* (parsers.newline * parsers.blankline^1
@@ -3343,45 +3410,69 @@ function M.reader.new(writer, options)
-- List of references defined in the document
local references
- -- add a reference to the list
- local function register_link(tag,url,title)
- references[self.normalize_tag(tag)] = { url = url, title = title }
- return ""
+ function self.register_link(tag, url, title,
+ attributes)
+ tag = self.normalize_tag(tag)
+ references[tag] = {
+ url = url,
+ title = title,
+ attributes = attributes,
+ }
+ return ""
end
- -- lookup link reference and return either
- -- the link or nil and fallback text.
- local function lookup_reference(label,sps,tag)
- local tagpart
- if not tag then
- tag = label
- tagpart = ""
- elseif tag == "" then
- tag = label
- tagpart = "[]"
- else
- tagpart = {"[",
- self.parser_functions.parse_inlines(tag),
- "]"}
+ function self.lookup_reference(label, sps, tag,
+ attributes)
+ local tagpart
+ if not tag then
+ tag = label
+ tagpart = ""
+ elseif tag == "" then
+ tag = label
+ tagpart = "[]"
+ else
+ tagpart = {
+ "[",
+ self.parser_functions.parse_inlines(tag),
+ "]"
+ }
+ end
+ if sps then
+ tagpart = {sps, tagpart}
+ end
+ tag = self.normalize_tag(tag)
+ local r = references[tag]
+ if r then
+ local merged_attributes = {}
+ for _, attribute in ipairs(r.attributes or {}) do
+ table.insert(merged_attributes, attribute)
end
- if sps then
- tagpart = {sps, tagpart}
+ for _, attribute in ipairs(attributes or {}) do
+ table.insert(merged_attributes, attribute)
end
- local r = references[self.normalize_tag(tag)]
- if r then
- return r
- else
- return nil, {"[",
- self.parser_functions.parse_inlines(label),
- "]", tagpart}
+ if #merged_attributes == 0 then
+ merged_attributes = nil
end
+ return {
+ url = r.url,
+ title = r.title,
+ attributes = merged_attributes,
+ }
+ else
+ return nil, {
+ "[",
+ self.parser_functions.parse_inlines(label),
+ "]",
+ tagpart
+ }
+ end
end
-- lookup link reference and return a link, if the reference is found,
-- or a bracketed label otherwise.
- local function indirect_link(label,sps,tag)
+ local function indirect_link(label, sps, tag)
return writer.defer_call(function()
- local r,fallback = lookup_reference(label,sps,tag)
+ local r,fallback = self.lookup_reference(label, sps, tag)
if r then
return writer.link(
self.parser_functions.parse_inlines_no_link(label),
@@ -3394,9 +3485,9 @@ function M.reader.new(writer, options)
-- lookup image reference and return an image, if the reference is found,
-- or a bracketed label otherwise.
- local function indirect_image(label,sps,tag)
+ local function indirect_image(label, sps, tag)
return writer.defer_call(function()
- local r,fallback = lookup_reference(label,sps,tag)
+ local r,fallback = self.lookup_reference(label, sps, tag)
if r then
return writer.image(writer.string(label), r.url, r.title)
else
@@ -3404,6 +3495,19 @@ function M.reader.new(writer, options)
end
end)
end
+
+ parsers.direct_link_tail = parsers.spnl
+ * parsers.lparent
+ * (parsers.url + Cc("")) -- link can be empty [foo]()
+ * parsers.optionaltitle
+ * parsers.rparent
+
+ parsers.direct_link = (parsers.tag / self.parser_functions.parse_inlines_no_link)
+ * parsers.direct_link_tail
+
+ parsers.direct_image = parsers.exclamation
+ * (parsers.tag / self.parser_functions.parse_inlines)
+ * parsers.direct_link_tail
parsers.Str = (parsers.normalchar * (parsers.normalchar + parsers.at)^0)
/ writer.string
@@ -3496,55 +3600,42 @@ function M.reader.new(writer, options)
) / writer.emphasis
end
- parsers.AutoLinkUrl = parsers.less
- * C(parsers.alphanumeric^1 * P("://") * parsers.urlchar^1)
- * parsers.more
- / function(url)
- return writer.link(writer.escape(url), url)
- end
+function self.auto_link_url(url, attributes)
+ return writer.link(writer.escape(url),
+ url, nil, attributes)
+end
- parsers.AutoLinkEmail = parsers.less
- * C((parsers.alphanumeric + S("-._+"))^1
- * P("@") * parsers.urlchar^1)
- * parsers.more
- / function(email)
- return writer.link(writer.escape(email),
- "mailto:"..email)
- end
+function self.auto_link_email(email, attributes)
+ return writer.link(writer.escape(email),
+ "mailto:"..email,
+ nil, attributes)
+end
+
+ parsers.AutoLinkUrl = parsers.auto_link_url
+ / self.auto_link_url
+
+ parsers.AutoLinkEmail
+ = parsers.auto_link_email
+ / self.auto_link_email
parsers.AutoLinkRelativeReference
- = parsers.less
- * C(parsers.urlchar^1)
- * parsers.more
- / function(url)
- return writer.link(writer.escape(url), url)
- end
+ = parsers.auto_link_relative_reference
+ / self.auto_link_url
- parsers.DirectLink = (parsers.tag / self.parser_functions.parse_inlines_no_link)
- * parsers.spnl
- * parsers.lparent
- * (parsers.url + Cc("")) -- link can be empty [foo]()
- * parsers.optionaltitle
- * parsers.rparent
+ parsers.DirectLink = parsers.direct_link
/ writer.link
- parsers.IndirectLink = parsers.tag * (C(parsers.spnl) * parsers.tag)^-1
+ parsers.IndirectLink = parsers.indirect_link
/ indirect_link
-- parse a link or image (direct or indirect)
parsers.Link = parsers.DirectLink + parsers.IndirectLink
- parsers.DirectImage = parsers.exclamation
- * (parsers.tag / self.parser_functions.parse_inlines)
- * parsers.spnl
- * parsers.lparent
- * (parsers.url + Cc("")) -- link can be empty [foo]()
- * parsers.optionaltitle
- * parsers.rparent
+ parsers.DirectImage = parsers.direct_image
/ writer.image
- parsers.IndirectImage = parsers.exclamation * parsers.tag
- * (C(parsers.spnl) * parsers.tag)^-1 / indirect_image
+ parsers.IndirectImage = parsers.indirect_image
+ / indirect_image
parsers.Image = parsers.DirectImage + parsers.IndirectImage
@@ -3587,7 +3678,9 @@ function M.reader.new(writer, options)
+ parsers.lineof(parsers.underscore)
) / writer.thematic_break
- parsers.Reference = parsers.define_reference_parser / register_link
+ parsers.Reference = parsers.define_reference_parser
+ * parsers.blankline^1
+ / self.register_link
parsers.Paragraph = parsers.nonindentspace * Ct(parsers.Inline^1)
* ( parsers.newline
@@ -3667,7 +3760,7 @@ function M.reader.new(writer, options)
* Cc(false) * parsers.skipblanklines
) * Cb("listtype") / ordered_list
parsers.Blank = parsers.blankline / ""
- + parsers.Reference
+ + V("Reference")
+ (parsers.tightblocksep / "\n")
-- parse atx header
parsers.AtxHeading = Cg(parsers.heading_start, "level")
@@ -3752,6 +3845,7 @@ function M.reader.new(writer, options)
ExpectedJekyllData = parsers.fail,
Blank = parsers.Blank,
+ Reference = parsers.Reference,
Blockquote = parsers.Blockquote,
Verbatim = parsers.Verbatim,
@@ -3802,7 +3896,15 @@ function M.reader.new(writer, options)
previous_pattern = nil
extension_name = current_extension_name
end
- local pattern = get_pattern(previous_pattern)
+ local pattern
+ if type(get_pattern) == "function" then
+ pattern = get_pattern(previous_pattern)
+ else
+ assert(previous_pattern == nil,
+ [[Rule ]] .. rule_name ..
+ [[ has already been updated by ]] .. extension_name)
+ pattern = get_pattern
+ end
local accountable_pattern = { pattern, extension_name, rule_name }
walkable_syntax[rule_name] = { accountable_pattern }
end
@@ -4525,7 +4627,7 @@ M.extensions.fancy_lists = function()
* Cc(false) * parsers.skipblanklines
) * Cb("listtype") / fancylist
- self.update_rule("OrderedList", function() return FancyList end)
+ self.update_rule("OrderedList", FancyList)
end
}
end
@@ -4831,7 +4933,24 @@ M.extensions.header_attributes = function()
/ writer.heading
local Heading = AtxHeading + SetextHeading
- self.update_rule("Heading", function() return Heading end)
+ self.update_rule("Heading", Heading)
+ end
+ }
+end
+M.extensions.inline_code_attributes = function()
+ return {
+ name = "built-in inline_code_attributes syntax extension",
+ extend_writer = function()
+ end, extend_reader = function(self)
+ local writer = self.writer
+
+ local CodeWithAttributes = parsers.inticks
+ * Ct(parsers.attributes)
+ / writer.code
+
+ self.insert_pattern("Inline before Code",
+ CodeWithAttributes,
+ "CodeWithAttributes")
end
}
end
@@ -4873,6 +4992,131 @@ M.extensions.line_blocks = function()
end
}
end
+M.extensions.link_attributes = function()
+ return {
+ name = "built-in link_attributes syntax extension",
+ extend_writer = function()
+ end, extend_reader = function(self)
+ local parsers = self.parsers
+ local writer = self.writer
+ local options = self.options
+
+
+ local define_reference_parser = parsers.define_reference_parser
+ * ( parsers.spnl
+ * Ct(parsers.attributes))^-1
+
+ local ReferenceWithAttributes = define_reference_parser
+ * parsers.blankline^1
+ / self.register_link
+
+ self.update_rule("Reference", ReferenceWithAttributes)
+
+
+ local function indirect_link(label, sps, tag,
+ attribute_text,
+ attributes)
+ return writer.defer_call(function()
+ local r, fallback = self.lookup_reference(label, sps, tag,
+ attributes)
+ if r then
+ return writer.link(
+ self.parser_functions.parse_inlines_no_link(label),
+ r.url, r.title, r.attributes)
+ else
+ local buf = {fallback}
+ if attributes then
+ table.insert(buf, writer.string(attribute_text))
+ end
+ return buf
+ end
+ end)
+ end
+
+ local DirectLinkWithAttributes = parsers.direct_link
+ * (Ct(parsers.attributes))^-1
+ / writer.link
+
+ local IndirectLinkWithAttributes = parsers.indirect_link
+ * (C(Ct(parsers.attributes)))^-1
+ / indirect_link
+
+ local LinkWithAttributes = DirectLinkWithAttributes
+ + IndirectLinkWithAttributes
+
+ self.update_rule("Link", LinkWithAttributes)
+
+
+ local function indirect_image(label, sps, tag,
+ attribute_text,
+ attributes)
+ return writer.defer_call(function()
+ local r, fallback = self.lookup_reference(label, sps, tag,
+ attributes)
+ if r then
+ return writer.image(writer.string(label),
+ r.url, r.title, r.attributes)
+ else
+ local buf = {"!", fallback}
+ if attributes then
+ table.insert(buf, writer.string(attribute_text))
+ end
+ return buf
+ end
+ end)
+ end
+
+ local DirectImageWithAttributes = parsers.direct_image
+ * Ct(parsers.attributes)
+ / writer.image
+
+ local IndirectImageWithAttributes = parsers.indirect_image
+ * C(Ct(parsers.attributes))
+ / indirect_image
+
+ local ImageWithAttributes = DirectImageWithAttributes
+ + IndirectImageWithAttributes
+
+ self.insert_pattern("Inline before Image",
+ ImageWithAttributes,
+ "ImageWithAttributes")
+
+
+ local AutoLinkUrlWithAttributes
+ = parsers.auto_link_url
+ * Ct(parsers.attributes)
+ / self.auto_link_url
+
+ self.insert_pattern("Inline before AutoLinkUrl",
+ AutoLinkUrlWithAttributes,
+ "AutoLinkUrlWithAttributes")
+
+ local AutoLinkEmailWithAttributes
+ = parsers.auto_link_email
+ * Ct(parsers.attributes)
+ / self.auto_link_email
+
+ self.insert_pattern("Inline before AutoLinkEmail",
+ AutoLinkEmailWithAttributes,
+ "AutoLinkEmailWithAttributes")
+
+ if options.relativeReferences then
+
+ local AutoLinkRelativeReferenceWithAttributes
+ = parsers.auto_link_relative_reference
+ * Ct(parsers.attributes)
+ / self.auto_link_url
+
+ self.insert_pattern(
+ "Inline before AutoLinkRelativeReference",
+ AutoLinkRelativeReferenceWithAttributes,
+ "AutoLinkRelativeReferenceWithAttributes")
+
+ end
+
+ end
+ }
+end
M.extensions.notes = function(notes, inline_notes)
assert(notes or inline_notes)
return {
@@ -4932,7 +5176,7 @@ M.extensions.notes = function(notes, inline_notes)
/ register_note
local Blank = NoteBlock + parsers.Blank
- self.update_rule("Blank", function() return Blank end)
+ self.update_rule("Blank", Blank)
self.insert_pattern("Inline after Emph",
NoteRef, "NoteRef")
@@ -5174,9 +5418,11 @@ M.extensions.superscripts = function()
end
}
end
-M.extensions.tex_math_dollars = function()
+M.extensions.tex_math = function(tex_math_dollars,
+ tex_math_single_backslash,
+ tex_math_double_backslash)
return {
- name = "built-in tex_math_dollars syntax extension",
+ name = "built-in tex_math syntax extension",
extend_writer = function(self)
function self.display_math(s)
if not self.is_writing then return "" end
@@ -5194,35 +5440,120 @@ M.extensions.tex_math_dollars = function()
return (starter * C(p * (p - ender)^0) * ender)
end
- local inlinemathtail = B( parsers.any * parsers.nonspacechar
- + parsers.backslash * parsers.any)
- * parsers.dollar
- * -#(parsers.digit)
-
- local inlinemath = between(C( parsers.backslash^-1
- * parsers.any
- - parsers.blankline^2
- - parsers.dollar),
- parsers.dollar * #(parsers.nonspacechar),
- inlinemathtail)
+ local allowed_before_closing = B( parsers.backslash * parsers.any
+ + parsers.any * (parsers.nonspacechar - parsers.backslash))
+ local dollar_math_content = parsers.backslash^-1
+ * parsers.any
+ - parsers.blankline^2
+ - parsers.dollar
+
+ local inline_math_opening_dollars = parsers.dollar
+ * #(parsers.nonspacechar)
+
+ local inline_math_closing_dollars = allowed_before_closing
+ * parsers.dollar
+ * -#(parsers.digit)
+
+ local inline_math_dollars = between(C( dollar_math_content),
+ inline_math_opening_dollars,
+ inline_math_closing_dollars)
+
+ local display_math_opening_dollars = parsers.dollar
+ * parsers.dollar
+
+ local display_math_closing_dollars = parsers.dollar
+ * parsers.dollar
+
+ local display_math_dollars = between(C( dollar_math_content),
+ display_math_opening_dollars,
+ display_math_closing_dollars)
+ local backslash_math_content = parsers.any
+ - parsers.blankline^2
+ local inline_math_opening_double = parsers.backslash
+ * parsers.backslash
+ * parsers.lparent
+ * #(parsers.nonspacechar)
+
+ local inline_math_closing_double = allowed_before_closing
+ * parsers.backslash
+ * parsers.backslash
+ * parsers.rparent
+
+ local inline_math_double = between(C( backslash_math_content),
+ inline_math_opening_double,
+ inline_math_closing_double)
+
+ local display_math_opening_double = parsers.backslash
+ * parsers.backslash
+ * parsers.lbracket
+
+ local display_math_closing_double = allowed_before_closing
+ * parsers.backslash
+ * parsers.backslash
+ * parsers.rbracket
+
+ local display_math_double = between(C( backslash_math_content),
+ display_math_opening_double,
+ display_math_closing_double)
+ local inline_math_opening_single = parsers.backslash
+ * parsers.lparent
+ * #(parsers.nonspacechar)
+
+ local inline_math_closing_single = allowed_before_closing
+ * parsers.backslash
+ * parsers.rparent
+
+ local inline_math_single = between(C( backslash_math_content),
+ inline_math_opening_single,
+ inline_math_closing_single)
+
+ local display_math_opening_single = parsers.backslash
+ * parsers.lbracket
+
+ local display_math_closing_single = allowed_before_closing
+ * parsers.backslash
+ * parsers.rbracket
+
+ local display_math_single = between(C( backslash_math_content),
+ display_math_opening_single,
+ display_math_closing_single)
+
+ local display_math = parsers.fail
+
+ local inline_math = parsers.fail
+
+ if tex_math_dollars then
+ display_math = display_math + display_math_dollars
+ inline_math = inline_math + inline_math_dollars
+ end
- local displaymathdelim = parsers.dollar
- * parsers.dollar
+ if tex_math_double_backslash then
+ display_math = display_math + display_math_double
+ inline_math = inline_math + inline_math_double
+ end
- local displaymath = between(C( parsers.backslash^-1
- * parsers.any
- - parsers.blankline^2
- - parsers.dollar),
- displaymathdelim,
- displaymathdelim)
+ if tex_math_single_backslash then
+ display_math = display_math + display_math_single
+ inline_math = inline_math + inline_math_single
+ end
- local TexMathDollars = displaymath / writer.display_math
- + inlinemath / writer.inline_math
+ local TexMath = display_math / writer.display_math
+ + inline_math / writer.inline_math
self.insert_pattern("Inline after Emph",
- TexMathDollars, "TexMathDollars")
+ TexMath, "TexMath")
+
+ if tex_math_dollars then
+ self.add_special_character("$")
+ end
- self.add_special_character("$")
+ if tex_math_single_backslash or tex_math_double_backslash then
+ self.add_special_character("\\")
+ self.add_special_character("[")
+ self.add_special_character("]")
+ self.add_special_character(")")
+ self.add_special_character("(")
+ end
end
}
end
@@ -5352,7 +5683,7 @@ M.extensions.jekyll_data = function(expect_jekyll_data)
self.insert_pattern("Block before Blockquote",
UnexpectedJekyllData, "UnexpectedJekyllData")
if expect_jekyll_data then
- self.update_rule("ExpectedJekyllData", function() return ExpectedJekyllData end)
+ self.update_rule("ExpectedJekyllData", ExpectedJekyllData)
end
end
}
@@ -5399,12 +5730,24 @@ function M.new(options)
table.insert(extensions, header_attributes_extension)
end
+ if options.inlineCodeAttributes then
+ local inline_code_attributes_extension =
+ M.extensions.inline_code_attributes()
+ table.insert(extensions, inline_code_attributes_extension)
+ end
+
if options.jekyllData then
local jekyll_data_extension = M.extensions.jekyll_data(
options.expectJekyllData)
table.insert(extensions, jekyll_data_extension)
end
+ if options.linkAttributes then
+ local link_attributes_extension =
+ M.extensions.link_attributes()
+ table.insert(extensions, link_attributes_extension)
+ end
+
if options.lineBlocks then
local line_block_extension = M.extensions.line_blocks()
table.insert(extensions, line_block_extension)
@@ -5436,9 +5779,14 @@ function M.new(options)
table.insert(extensions, superscript_extension)
end
- if options.texMathDollars then
- local tex_math_dollars_extension = M.extensions.tex_math_dollars()
- table.insert(extensions, tex_math_dollars_extension)
+ if options.texMathDollars or
+ options.texMathSingleBackslash or
+ options.texMathDoubleBackslash then
+ local tex_math_extension = M.extensions.tex_math(
+ options.texMathDollars,
+ options.texMathSingleBackslash,
+ options.texMathDoubleBackslash)
+ table.insert(extensions, tex_math_extension)
end
if options.footnotes or options.inlineFootnotes or