From c2d2eba4dbcbb6d9555b487010e3486c5b37dddc Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 29 Jul 2022 21:00:05 +0000 Subject: markdown (28jul22) git-svn-id: svn://tug.org/texlive/trunk@64000 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/luatex/markdown/markdown.lua | 131 ++++++++++++--------- 1 file changed, 76 insertions(+), 55 deletions(-) (limited to 'Master/texmf-dist/tex/luatex/markdown') diff --git a/Master/texmf-dist/tex/luatex/markdown/markdown.lua b/Master/texmf-dist/tex/luatex/markdown/markdown.lua index 2913503f2ce..8e5d29f0133 100644 --- a/Master/texmf-dist/tex/luatex/markdown/markdown.lua +++ b/Master/texmf-dist/tex/luatex/markdown/markdown.lua @@ -1,6 +1,6 @@ --- +-- -- Copyright (C) 2009-2016 John MacFarlane, Hans Hagen --- +-- -- Permission is hereby granted, free of charge, to any person obtaining -- a copy of this software and associated documentation files (the -- "Software"), to deal in the Software without restriction, including @@ -8,10 +8,10 @@ -- distribute, sublicense, and/or sell copies of the Software, and to -- permit persons to whom the Software is furnished to do so, subject to -- the following conditions: --- +-- -- The above copyright notice and this permission notice shall be included -- in all copies or substantial portions of the Software. --- +-- -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. @@ -19,31 +19,31 @@ -- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --- +-- -- Copyright (C) 2016-2022 Vít Novotný --- +-- -- This work may be distributed and/or modified under the -- conditions of the LaTeX Project Public License, either version 1.3 -- of this license or (at your option) any later version. -- The latest version of this license is in --- +-- -- http://www.latex-project.org/lppl.txt --- +-- -- and version 1.3 or later is part of all distributions of LaTeX -- version 2005/12/01 or later. --- +-- -- This work has the LPPL maintenance status `maintained'. -- The Current Maintainer of this work is Vít Novotný. --- +-- -- Send bug reports, requests for additions and questions -- either to the GitHub issue tracker at --- +-- -- https://github.com/witiko/markdown/issues --- +-- -- or to the e-mail address . --- +-- -- MODIFICATION ADVICE: --- +-- -- If you want to customize this file, it is best to make a copy of -- the source file(s) from which it was produced. Use a different -- name for your copy(ies) and modify the copy(ies); this will ensure @@ -51,14 +51,14 @@ -- new release of the standard system. You should also ensure that -- your modified source file does not generate any modified file with -- the same name as a standard file. --- +-- -- You will also need to produce your own, suitably named, .ins file to -- control the generation of files from your source file; this file -- should contain your own preambles for the files it generates, not -- those in the standard .ins files. --- +-- local metadata = { - version = "2.15.3-0-g7c8e03d", + version = "2.15.4-0-g4cbe4e3", 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", @@ -69,10 +69,14 @@ local metadata = { if not modules then modules = { } end modules['markdown'] = metadata local lpeg = require("lpeg") -local ran_ok, unicode = pcall(require, "unicode") -if not ran_ok then - unicode = {["utf8"]={char=utf8.char}} -end +local unicode +(function() + local ran_ok + ran_ok, unicode = pcall(require, "unicode") + if not ran_ok then + unicode = {["utf8"]={char=utf8.char}} + end +end)() local md5 = require("md5") local M = {metadata = metadata} local defaultOptions = {} @@ -116,7 +120,6 @@ defaultOptions.tightLists = true defaultOptions.underscores = true local upper, gsub, format, length = string.upper, string.gsub, string.format, string.len -local concat = table.concat local P, R, S, V, C, Cg, Cb, Cmt, Cc, Ct, B, Cs, any = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.C, lpeg.Cg, lpeg.Cb, lpeg.Cmt, lpeg.Cc, lpeg.Ct, lpeg.B, lpeg.Cs, lpeg.P(1) @@ -130,7 +133,7 @@ function util.cache(dir, string, salt, transform, suffix) local name = util.pathname(dir, digest .. suffix) local file = io.open(name, "r") if file == nil then -- If no cache entry exists, then create a new one. - local file = assert(io.open(name, "w"), + file = assert(io.open(name, "w"), [[could not open file "]] .. name .. [[" for writing]]) local result = string if transform ~= nil then @@ -2713,9 +2716,7 @@ parsers.spacing = S(" \n\r\t") parsers.nonspacechar = parsers.any - parsers.spacing parsers.optionalspace = parsers.spacechar^0 -parsers.specialchar = S("*_`&[]= #b and i end @@ -2869,10 +2870,10 @@ end parsers.fencedline = function(char) return C(parsers.line - parsers.fencetail(char)) / function(s) - i = 1 - remaining = fenceindent + local i = 1 + local remaining = fenceindent while true do - c = s:sub(i, i) + local c = s:sub(i, i) if c == " " and remaining > 0 then remaining = remaining - 1 i = i + 1 @@ -3113,7 +3114,7 @@ function M.reader.new(writer, options, extensions) gsub(util.rope_to_string(tag), "[ \n\r\t]+", " ")) end local function iterlines(s, f) - rope = lpeg.match(Ct((parsers.line / f)^1), s) + local rope = lpeg.match(Ct((parsers.line / f)^1), s) return util.rope_to_string(rope) end if options.preserveTabs then @@ -3137,7 +3138,7 @@ function M.reader.new(writer, options, extensions) return line end line = util.expand_tabs_in_line(line) - prefix = lpeg.match(C(parsers.optionalspace), line) + local prefix = lpeg.match(C(parsers.optionalspace), line) local prefix_length = #prefix local is_shorter = min_prefix_length == nil is_shorter = is_shorter or prefix_length < min_prefix_length @@ -3291,7 +3292,7 @@ function M.reader.new(writer, options, extensions) parsers.Str = (parsers.normalchar * (parsers.normalchar + parsers.at)^0) / writer.string - parsers.Symbol = (parsers.specialchar - parsers.tightblocksep) + parsers.Symbol = (V("SpecialChar") - parsers.tightblocksep) / writer.string parsers.Ellipsis = P("...") / writer.ellipsis @@ -3682,13 +3683,23 @@ function M.reader.new(writer, options, extensions) EscapedChar = parsers.EscapedChar, Smart = parsers.Smart, Symbol = parsers.Symbol, + SpecialChar = parsers.fail, } - + local special_characters = {"*", "`", "[", "]", "<", "!", "\\"} + self.add_special_character = function(c) + table.insert(special_characters, c) + self.syntax.SpecialChar = S(table.concat(special_characters, "")) + end + self.syntax.SpecialChar = S(table.concat(special_characters, "")) for _, extension in ipairs(extensions) do extension.extend_writer(writer) extension.extend_reader(self) end + if options.underscores then + self.add_special_character("_") + end + if not options.codeSpans then self.syntax.Code = parsers.fail end @@ -3697,6 +3708,8 @@ function M.reader.new(writer, options, extensions) self.syntax.DisplayHtml = parsers.fail self.syntax.InlineHtml = parsers.fail self.syntax.HtmlEntity = parsers.fail + else + self.add_special_character("&") end if options.preserveTabs then @@ -3705,6 +3718,8 @@ function M.reader.new(writer, options, extensions) if not options.smartEllipses then self.syntax.Smart = parsers.fail + else + self.add_special_character(".") end if not options.relativeReferences then @@ -3920,6 +3935,9 @@ M.extensions.citations = function(citation_nbsps) local Citations = TextCitations + ParenthesizedCitations syntax.Citations = Citations + + self.add_special_character("@") + self.add_special_character("-") end } end @@ -3929,15 +3947,15 @@ M.extensions.content_blocks = function(language_map) if ran_ok then kpse.set_program_name("luatex") else - kpse = {lookup=function(filename, options) return filename end} + kpse = {lookup=function(filename, _) return filename end} end local base, prev, curr for _, filename in ipairs{kpse.lookup(language_map, { all=true })} do local file = io.open(filename, "r") if not file then goto continue end - json = file:read("*all"):gsub('("[^\n]-"):','[%1]=') + local json = file:read("*all"):gsub('("[^\n]-"):','[%1]=') curr = (function() - local _ENV={ json=json, load=load } -- run in sandbox + local _ENV={ json=json, load=load } -- luacheck: ignore _ENV return load("return "..json)() end)() if type(curr) == "table" then @@ -4104,7 +4122,7 @@ M.extensions.definition_lists = function(tight_lists) local dlchunk = Cs(parsers.line * (parsers.indentedline - parsers.blankline)^0) - local function definition_list_item(term, defs, tight) + local function definition_list_item(term, defs, _) return { term = self.parser_functions.parse_inlines(term), definitions = defs } end @@ -4147,7 +4165,7 @@ M.extensions.fenced_code = function(blank_before_code_fence) local syntax = self.syntax local writer = self.writer - local function captures_geq_length(s,i,a,b) + local function captures_geq_length(_,i,a,b) return #a >= #b and i end @@ -4172,10 +4190,10 @@ M.extensions.fenced_code = function(blank_before_code_fence) local fencedline = function(char) return C(parsers.line - fencetail(char)) / function(s) - i = 1 - remaining = fenceindent + local i = 1 + local remaining = fenceindent while true do - c = s:sub(i, i) + local c = s:sub(i, i) if c == " " and remaining > 0 then remaining = remaining - 1 i = i + 1 @@ -4209,6 +4227,7 @@ M.extensions.fenced_code = function(blank_before_code_fence) syntax.FencedCode = FencedCode + local fencestart if blank_before_code_fence then fencestart = parsers.fail else @@ -4282,12 +4301,14 @@ M.extensions.footnotes = function(footnotes, inline_footnotes) / writer.note syntax.InlineNote = InlineNote end + + self.add_special_character("^") end } end M.extensions.header_attributes = function() return { - extend_writer = function(self) + extend_writer = function() end, extend_reader = function(self) local parsers = self.parsers local syntax = self.syntax @@ -4432,9 +4453,9 @@ M.extensions.jekyll_data = function(expect_jekyll_data) local JekyllData = Cmt( C((parsers.line - P("---") - P("..."))^0) - , function(s, i, text) + , function(s, i, text) -- luacheck: ignore s i local data - local ran_ok, error = pcall(function() + local ran_ok, _ = pcall(function() local tinyyaml = require("markdown-tinyyaml") data = tinyyaml.parse(text, {timestamps=false}) end) @@ -4614,50 +4635,50 @@ function M.new(options) options = options or {} setmetatable(options, { __index = function (_, key) return defaultOptions[key] end }) - extensions = {} + local extensions = {} if options.citations then - citations_extension = M.extensions.citations(options.citationNbsps) + local citations_extension = M.extensions.citations(options.citationNbsps) table.insert(extensions, citations_extension) end if options.contentBlocks then - content_blocks_extension = M.extensions.content_blocks( + local content_blocks_extension = M.extensions.content_blocks( options.contentBlocksLanguageMap) table.insert(extensions, content_blocks_extension) end if options.definitionLists then - definition_lists_extension = M.extensions.definition_lists( + local definition_lists_extension = M.extensions.definition_lists( options.tightLists) table.insert(extensions, definition_lists_extension) end if options.fencedCode then - fenced_code_extension = M.extensions.fenced_code( + local fenced_code_extension = M.extensions.fenced_code( options.blankBeforeCodeFence) table.insert(extensions, fenced_code_extension) end if options.footnotes or options.inlineFootnotes then - footnotes_extension = M.extensions.footnotes( + local footnotes_extension = M.extensions.footnotes( options.footnotes, options.inlineFootnotes) table.insert(extensions, footnotes_extension) end if options.headerAttributes then - header_attributes_extension = M.extensions.header_attributes() + local header_attributes_extension = M.extensions.header_attributes() table.insert(extensions, header_attributes_extension) end if options.jekyllData then - jekyll_data_extension = M.extensions.jekyll_data( + local jekyll_data_extension = M.extensions.jekyll_data( options.expectJekyllData) table.insert(extensions, jekyll_data_extension) end if options.pipeTables then - pipe_tables_extension = M.extensions.pipe_tables( + local pipe_tables_extension = M.extensions.pipe_tables( options.tableCaptions) table.insert(extensions, pipe_tables_extension) end -- cgit v1.2.3