summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/markdown/markdown.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/luatex/markdown/markdown.lua')
-rw-r--r--Master/texmf-dist/tex/luatex/markdown/markdown.lua119
1 files changed, 96 insertions, 23 deletions
diff --git a/Master/texmf-dist/tex/luatex/markdown/markdown.lua b/Master/texmf-dist/tex/luatex/markdown/markdown.lua
index d3711c4f243..f9154d8103b 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 = "3.6.0-0-g83c781b4",
+ version = "3.6.1-0-g5a45a922",
comment = "A module for the conversion from markdown to plain TeX",
author = "John MacFarlane, Hans Hagen, Vít Starý Novotný",
copyright = {"2009-2016 John MacFarlane, Hans Hagen",
@@ -4448,19 +4448,21 @@ parsers.link_text = parsers.lbracket
- (parsers.newline + parsers.lbracket + parsers.rbracket + parsers.blankline^2))))^0)
* parsers.rbracket
+parsers.link_label_body = -#(parsers.sp * parsers.rbracket)
+ * #((parsers.any - parsers.rbracket)^-999 * parsers.rbracket)
+ * Cs((parsers.alphanumeric^1
+ + parsers.inticks
+ + parsers.autolink
+ + V("InlineHtml")
+ + ( parsers.backslash * parsers.backslash)
+ + ( parsers.backslash * (parsers.lbracket + parsers.rbracket)
+ + V("NoSoftLineBreakSpace")
+ + V("NoSoftLineBreakEndline")
+ + (parsers.any
+ - (parsers.newline + parsers.lbracket + parsers.rbracket + parsers.blankline^2))))^1)
+
parsers.link_label = parsers.lbracket
- * -#(parsers.sp * parsers.rbracket)
- * #((parsers.any - parsers.rbracket)^-999 * parsers.rbracket)
- * Cs((parsers.alphanumeric^1
- + parsers.inticks
- + parsers.autolink
- + V("InlineHtml")
- + ( parsers.backslash * parsers.backslash)
- + ( parsers.backslash * (parsers.lbracket + parsers.rbracket)
- + V("NoSoftLineBreakSpace")
- + V("NoSoftLineBreakEndline")
- + (parsers.any
- - (parsers.newline + parsers.lbracket + parsers.rbracket + parsers.blankline^2))))^1)
+ * parsers.link_label_body
* parsers.rbracket
parsers.inparens_url = P{ parsers.lparent
@@ -5086,6 +5088,9 @@ function M.reader.new(writer, options)
-- List of references defined in the document
local references
+ -- List of note references defined in the document
+ parsers.rawnotes = {}
+
function self.register_link(_, tag, url, title,
attributes)
local normalized_tag = self.normalize_tag(tag)
@@ -5103,6 +5108,10 @@ function M.reader.new(writer, options)
return references[self.normalize_tag(tag)]
end
+ function self.lookup_note_reference(tag)
+ return parsers.rawnotes[self.normalize_tag(tag)]
+ end
+
parsers.title_s_direct_ref = parsers.squote
* Cs((parsers.html_entities
+ (parsers.anyescaped - parsers.squote - parsers.blankline^2))^0)
@@ -5173,15 +5182,49 @@ function M.reader.new(writer, options)
+ #parsers.link_text
* Cg(Cc("link_text"), "link_type")
+ parsers.note_opening = #(parsers.circumflex * parsers.shortcut_link)
+ * Cg(Cc("note_inline"), "link_type")
+
+ parsers.raw_note_opening = #( parsers.lbracket
+ * parsers.circumflex
+ * parsers.link_label_body
+ * parsers.rbracket)
+ * Cg(Cc("raw_note"), "link_type")
+
+ local inline_note_element = Cg(Cc("note"), "element")
+ * parsers.note_opening
+ * Cg(parsers.circumflex * parsers.lbracket, "content")
+
+ local image_element = Cg(Cc("image"), "element")
+ * parsers.image_opening
+ * Cg(parsers.exclamation * parsers.lbracket, "content")
+
+ local note_element = Cg(Cc("note"), "element")
+ * parsers.raw_note_opening
+ * Cg(parsers.lbracket * parsers.circumflex, "content")
+
+ local link_element = Cg(Cc("link"), "element")
+ * parsers.link_opening
+ * Cg(parsers.lbracket, "content")
+
+ local opening_elements = parsers.fail
+
+ if options.inlineNotes then
+ opening_elements = opening_elements + inline_note_element
+ end
+
+ opening_elements = opening_elements + image_element
+
+ if options.notes then
+ opening_elements = opening_elements + note_element
+ end
+
+ opening_elements = opening_elements + link_element
+
parsers.link_image_opening = Ct( Cg(Cc("delimiter"), "type")
* Cg(Cc(true), "is_opening")
* Cg(Cc(false), "is_closing")
- * ( Cg(Cc("image"), "element")
- * parsers.image_opening
- * Cg(parsers.exclamation * parsers.lbracket, "content")
- + Cg(Cc("link"), "element")
- * parsers.link_opening
- * Cg(parsers.lbracket, "content")))
+ * opening_elements)
parsers.link_image_closing = Ct( Cg(Cc("delimiter"), "type")
* Cg(Cc("link"), "element")
@@ -5239,7 +5282,7 @@ function M.reader.new(writer, options)
local value = t[i]
if value.type == "delimiter" and
value.is_opening and
- (value.element == "link" or value.element == "image")
+ (value.element == "link" or value.element == "image" or value.element == "note")
and not value.removed then
if value.is_active then
return i
@@ -5328,6 +5371,15 @@ function M.reader.new(writer, options)
rendered = writer.image(mapped, reference.url, reference.title, reference.attributes)
end
+ if (t[opening_index].element == "note") then
+ if (t[opening_index].link_type == "note_inline") then
+ rendered = writer.note(mapped)
+ end
+ if (t[opening_index].link_type == "raw_note") then
+ rendered = writer.note(reference)
+ end
+ end
+
t[opening_index].rendered = rendered
delete_parsed_content_in_range(t, opening_index + 1, closing_index)
empty_content_in_range(t, opening_index, closing_index)
@@ -5386,6 +5438,11 @@ function M.reader.new(writer, options)
render_link_or_image(t, opening_index, closing_index, closing_index, inline_content)
end
+ local function resolve_note_inline_link(t, opening_index, closing_index)
+ local inline_content = resolve_inline_following_content(t, closing_index, false, false)
+ render_link_or_image(t, opening_index, closing_index, closing_index, inline_content)
+ end
+
local function resolve_shortcut_link(t, opening_index, closing_index)
local content = collect_link_content(t, opening_index + 1, closing_index - 1)
local r = self.lookup_reference(content)
@@ -5397,6 +5454,16 @@ function M.reader.new(writer, options)
end
end
+ local function resolve_raw_note_link(t, opening_index, closing_index)
+ local content = collect_link_content(t, opening_index + 1, closing_index - 1)
+ local r = self.lookup_note_reference(content)
+
+ if r then
+ local parsed_ref = self.parser_functions.parse_blocks_nested(r)
+ render_link_or_image(t, opening_index, closing_index, closing_index, parsed_ref)
+ end
+ end
+
local function resolve_full_link(t, opening_index, closing_index)
local next_link_closing_index = find_next_link_closing_index(t, closing_index + 4)
local next_link_content = collect_link_content(t, closing_index + 3, next_link_closing_index - 1)
@@ -5430,7 +5497,7 @@ function M.reader.new(writer, options)
for i,value in ipairs(t) do
if not value.is_closing or
value.type ~= "delimiter" or
- not (value.element == "link" or value.element == "image") then
+ not (value.element == "link" or value.element == "image" or value.element == "note") then
goto continue
end
@@ -5456,6 +5523,12 @@ function M.reader.new(writer, options)
if (link_type == "collapsed") then
resolve_collapsed_link(t, opener_position, i)
end
+ if (link_type == "note_inline") then
+ resolve_note_inline_link(t, opener_position, i)
+ end
+ if (link_type == "raw_note") then
+ resolve_raw_note_link(t, opener_position, i)
+ end
::continue::
end
@@ -7506,6 +7579,8 @@ M.extensions.notes = function(notes, inline_notes)
local parsers = self.parsers
local writer = self.writer
+ local rawnotes = parsers.rawnotes
+
if inline_notes then
local InlineNote
= parsers.circumflex
@@ -7524,8 +7599,6 @@ M.extensions.notes = function(notes, inline_notes)
= #(parsers.lbracket * parsers.circumflex)
* parsers.link_label / strip_first_char
- local rawnotes = {}
-
-- like indirect_link
local function lookup_note(ref)
return writer.defer_call(function()