summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex/markdown
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2023-04-27 20:37:52 +0000
committerKarl Berry <karl@freefriends.org>2023-04-27 20:37:52 +0000
commitfd9564b21054e27d1e4f4bfcca7683ae3b84e2fb (patch)
treef98ea8c61cbdc8546aabe2957323aca8776c3bca /Master/texmf-dist/tex/luatex/markdown
parenteaf38b0e316452820428aaa331b98c6b2c9d8edf (diff)
markdown (27apr23)
git-svn-id: svn://tug.org/texlive/trunk@66954 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex/markdown')
-rw-r--r--Master/texmf-dist/tex/luatex/markdown/markdown-tinyyaml.lua18
-rw-r--r--Master/texmf-dist/tex/luatex/markdown/markdown.lua61
2 files changed, 61 insertions, 18 deletions
diff --git a/Master/texmf-dist/tex/luatex/markdown/markdown-tinyyaml.lua b/Master/texmf-dist/tex/luatex/markdown/markdown-tinyyaml.lua
index 7a57ef2422d..074ad79446e 100644
--- a/Master/texmf-dist/tex/luatex/markdown/markdown-tinyyaml.lua
+++ b/Master/texmf-dist/tex/luatex/markdown/markdown-tinyyaml.lua
@@ -38,6 +38,8 @@ local tonumber = tonumber
local math = math
local getmetatable = getmetatable
local error = error
+local end_symbol = "..."
+local end_break_symbol = "...\n"
local UNESCAPES = {
['0'] = "\x00", z = "\x00", N = "\x85",
@@ -183,7 +185,14 @@ function Parser:parsestring(line, stopper)
if not i then
return nil, line
end
- return ssub(line, 2, i-1), ssub(line, i+1)
+ -- Unescape repeated single quotes.
+ while i < #line and ssub(line, i+1, i+1) == "'" do
+ i = sfind(line, "'", i + 2, true)
+ if not i then
+ return nil, line
+ end
+ end
+ return ssub(line, 2, i-1):gsub("''", "'"), ssub(line, i+1)
end
if q == '"' then
local i, buf = 2, ''
@@ -702,6 +711,13 @@ function Parser:parsemap(line, lines, indent)
while #lines > 0 do
-- Check for a new document
line = lines[1]
+ if line == end_symbol or line == end_break_symbol then
+ for i, _ in ipairs(lines) do
+ lines[i] = nil
+ end
+ return map
+ end
+
if startswith(line, '---') then
while #lines > 0 and not startswith(lines, '---') do
tremove(lines, 1)
diff --git a/Master/texmf-dist/tex/luatex/markdown/markdown.lua b/Master/texmf-dist/tex/luatex/markdown/markdown.lua
index 1e68b8ae84f..225428abe03 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.22.0-0-g5a3d0fe",
+ version = "2.23.0-0-g0b22f91",
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",
@@ -2503,7 +2503,7 @@ function M.writer.new(options)
{"\\markdownRendererCodeSpan{", self.escape(s), "}"})
if attributes ~= nil then
table.insert(buf,
- "\n\\markdownRendererCodeSpanAttributeContextEnd ")
+ "\\markdownRendererCodeSpanAttributeContextEnd{}")
end
return buf
end
@@ -2520,7 +2520,7 @@ function M.writer.new(options)
"{",self.string(tit or ""),"}"})
if attributes ~= nil then
table.insert(buf,
- "\n\\markdownRendererLinkAttributeContextEnd ")
+ "\\markdownRendererLinkAttributeContextEnd{}")
end
return buf
end
@@ -2537,7 +2537,7 @@ function M.writer.new(options)
"{",self.string(tit or ""),"}"})
if attributes ~= nil then
table.insert(buf,
- "\n\\markdownRendererImageAttributeContextEnd ")
+ "\\markdownRendererImageAttributeContextEnd{}")
end
return buf
end
@@ -2640,26 +2640,49 @@ function M.writer.new(options)
return buf
end
- function self.attributes(attr)
- local buf = {}
+ function self.attributes(attributes)
+ local expanded_attributes = {}
+ local key_value_regex = "([^= ]+)%s*=%s*(.*)"
+ local key, value
+ for _, attribute in ipairs(attributes) do
+ if attribute:sub(1, 1) == "#" or attribute:sub(1, 1) == "." then
+ table.insert(expanded_attributes, attribute)
+ else
+ key, value = attribute:match(key_value_regex)
+ if key:lower() == "id" then
+ table.insert(expanded_attributes, "#" .. value)
+ elseif key:lower() == "class" then
+ local classes = {}
+ for class in value:gmatch("%S+") do
+ table.insert(classes, class)
+ end
+ table.sort(classes)
+ for _, class in ipairs(classes) do
+ table.insert(expanded_attributes, "." .. class)
+ end
+ else
+ table.insert(expanded_attributes, attribute)
+ end
+ end
+ end
+ table.sort(expanded_attributes)
- table.sort(attr)
+ local buf = {}
local seen = {}
- local key, value
- for i = 1, #attr do
- if seen[attr[i]] ~= nil then
+ for _, attribute in ipairs(expanded_attributes) do
+ if seen[attribute] ~= nil then
goto continue -- prevent duplicate attributes
else
- seen[attr[i]] = true
+ seen[attribute] = true
end
- if attr[i]:sub(1, 1) == "#" then
+ if attribute:sub(1, 1) == "#" then
table.insert(buf, {"\\markdownRendererAttributeIdentifier{",
- attr[i]:sub(2), "}"})
- elseif attr[i]:sub(1, 1) == "." then
+ attribute:sub(2), "}"})
+ elseif attribute:sub(1, 1) == "." then
table.insert(buf, {"\\markdownRendererAttributeClassName{",
- attr[i]:sub(2), "}"})
+ attribute:sub(2), "}"})
else
- key, value = attr[i]:match("([^= ]+)%s*=%s*(.*)")
+ key, value = attribute:match(key_value_regex)
table.insert(buf, {"\\markdownRendererAttributeKeyValue{",
key, "}{", value, "}"})
end
@@ -2971,13 +2994,16 @@ parsers.commented_line = Cg(Cc(""), "backslashes")
parsers.chunk = parsers.line * (parsers.optionallyindentedline
- parsers.blankline)^0
-parsers.attribute_key_char = parsers.alphanumeric + S("_-")
+parsers.attribute_key_char = parsers.alphanumeric + S("-_:.")
parsers.attribute_key = (parsers.attribute_key_char
- parsers.dash - parsers.digit)
* parsers.attribute_key_char^0
parsers.attribute_value = ( (parsers.dquote / "")
* (parsers.anyescaped - parsers.dquote)^0
* (parsers.dquote / ""))
+ + ( (parsers.squote / "")
+ * (parsers.anyescaped - parsers.squote)^0
+ * (parsers.squote / ""))
+ ( parsers.anyescaped - parsers.dquote - parsers.rbrace
- parsers.space)^0
@@ -5652,6 +5678,7 @@ M.extensions.jekyll_data = function(expect_jekyll_data)
, function(s, i, text) -- luacheck: ignore s i
local data
local ran_ok, _ = pcall(function()
+ -- TODO: Replace with `require("tinyyaml")` in TeX Live 2023
local tinyyaml = require("markdown-tinyyaml")
data = tinyyaml.parse(text, {timestamps=false})
end)