diff options
author | Karl Berry <karl@freefriends.org> | 2017-03-27 21:41:13 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-03-27 21:41:13 +0000 |
commit | 58d83afa8885de91f792004e03eb2678b087b46f (patch) | |
tree | a2308b039b6a75aa7bf3427476829d50e1746f12 /Master/texmf-dist/tex/luatex | |
parent | f6e2e4efbdd44ba2ce51fc1555361c23ec6c8beb (diff) |
markdown (27mar17)
git-svn-id: svn://tug.org/texlive/trunk@43618 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r-- | Master/texmf-dist/tex/luatex/markdown/markdown.lua | 155 |
1 files changed, 144 insertions, 11 deletions
diff --git a/Master/texmf-dist/tex/luatex/markdown/markdown.lua b/Master/texmf-dist/tex/luatex/markdown/markdown.lua index 63e4effda43..de9895c8c27 100644 --- a/Master/texmf-dist/tex/luatex/markdown/markdown.lua +++ b/Master/texmf-dist/tex/luatex/markdown/markdown.lua @@ -1,5 +1,5 @@ -- --- Copyright (C) 2009-2016 John MacFarlane, Hans Hagen +-- Copyright (C) 2009-2017 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 @@ -58,7 +58,7 @@ -- those in the standard .ins files. -- local metadata = { - version = "2.3.0", + version = "2.4.0", comment = "A module for the conversion from markdown to plain TeX", author = "John MacFarlane, Hans Hagen, Vít Novotný", copyright = "2009-2017 John MacFarlane, Hans Hagen; " .. @@ -79,6 +79,8 @@ defaultOptions.breakableBlockquotes = false defaultOptions.cacheDir = "." defaultOptions.citationNbsps = true defaultOptions.citations = false +defaultOptions.contentBlocks = false +defaultOptions.contentBlocksLanguageMap = "markdown-languages.json" defaultOptions.definitionLists = false defaultOptions.hashEnumerators = false defaultOptions.html = false @@ -554,6 +556,50 @@ function M.writer.new(options) "{",self.uri(src),"}", "{",self.string(tit or ""),"}"} end +local languages_json = (function() + local kpse = require('kpse') + kpse.set_program_name('luatex') + local base, prev, curr + for _, file in ipairs{kpse.lookup(options.contentBlocksLanguageMap, + { all=true })} do + json = assert(io.open(file, "r")):read("*all") + :gsub('("[^\n]-"):','[%1]=') + curr = (function() + local _ENV={ json=json, load=load } -- run in sandbox + return load("return "..json)() + end)() + if type(curr) == "table" then + if base == nil then + base = curr + else + setmetatable(prev, { __index = curr }) + end + prev = curr + end + end + return base or {} +end)() + function self.contentblock(src,suf,type,tit) + src = src.."."..suf + suf = suf:lower() + if type == "onlineimage" then + return {"\\markdownRendererContentBlockOnlineImage{",suf,"}", + "{",self.string(src),"}", + "{",self.uri(src),"}", + "{",self.string(tit or ""),"}"} + elseif languages_json[suf] then + return {"\\markdownRendererContentBlockCode{",suf,"}", + "{",self.string(languages_json[suf]),"}", + "{",self.string(src),"}", + "{",self.uri(src),"}", + "{",self.string(tit or ""),"}"} + else + return {"\\markdownRendererContentBlock{",suf,"}", + "{",self.string(src),"}", + "{",self.uri(src),"}", + "{",self.string(tit or ""),"}"} + end + end local function ulitem(s) return {"\\markdownRendererUlItem ",s, "\\markdownRendererUlItemEnd "} @@ -829,7 +875,7 @@ parsers.fencedline = function(char) end parsers.leader = parsers.space^-3 --- in balanced brackets, parentheses, quotes: +-- content in balanced brackets, parentheses, or quotes: parsers.bracketed = P{ parsers.lbracket * ((parsers.anyescaped - (parsers.lbracket + parsers.rbracket @@ -856,22 +902,24 @@ parsers.dquoted = P{ parsers.dquote * parsers.alphanumeric ) + V(1))^0 * parsers.dquote } --- bracketed 'tag' for markdown links, allowing nested brackets: +-- bracketed tag for markdown links, allowing nested brackets: parsers.tag = parsers.lbracket * Cs((parsers.alphanumeric^1 + parsers.bracketed + parsers.inticks - + (parsers.anyescaped - (parsers.rbracket - + parsers.blankline^2)))^0) + + (parsers.anyescaped + - (parsers.rbracket + parsers.blankline^2)))^0) * parsers.rbracket --- url for markdown links, allowing balanced parentheses: -parsers.url = parsers.less * Cs((parsers.anyescaped-parsers.more)^0) +-- url for markdown links, allowing nested brackets: +parsers.url = parsers.less * Cs((parsers.anyescaped + - parsers.more)^0) * parsers.more + Cs((parsers.inparens + (parsers.anyescaped - -parsers.spacing-parsers.rparent))^1) + - parsers.spacing + - parsers.rparent))^1) --- quoted text possibly with nested quotes: +-- quoted text, possibly with nested quotes: parsers.title_s = parsers.squote * Cs(((parsers.anyescaped-parsers.squote) + parsers.squoted)^0) * parsers.squote @@ -889,6 +937,70 @@ parsers.title = parsers.title_d + parsers.title_s + parsers.title_p parsers.optionaltitle = parsers.spnl * parsers.title * parsers.spacechar^0 + Cc("") +parsers.contentblock_tail + = parsers.optionaltitle + * (parsers.newline + parsers.eof) + +-- case insensitive online image suffix: +parsers.onlineimagesuffix + = (function(...) + local parser = nil + for _,suffix in ipairs({...}) do + local pattern=nil + for i=1,#suffix do + local char=suffix:sub(i,i) + char = S(char:lower()..char:upper()) + if pattern == nil then + pattern = char + else + pattern = pattern * char + end + end + if parser == nil then + parser = pattern + else + parser = parser + pattern + end + end + return parser + end)("png", "jpg", "jpeg", "gif", "tif", "tiff") + +-- online image url for iA Writer content blocks with mandatory suffix, +-- allowing nested brackets: +parsers.onlineimageurl + = (parsers.less + * Cs((parsers.anyescaped + - parsers.more + - #(parsers.period + * parsers.onlineimagesuffix + * parsers.more + * parsers.contentblock_tail))^0) + * parsers.period + * Cs(parsers.onlineimagesuffix) + * parsers.more + + (Cs((parsers.inparens + + (parsers.anyescaped + - parsers.spacing + - parsers.rparent + - #(parsers.period + * parsers.onlineimagesuffix + * parsers.contentblock_tail)))^0) + * parsers.period + * Cs(parsers.onlineimagesuffix)) + ) * Cc("onlineimage") + +-- filename for iA Writer content blocks with mandatory suffix: +parsers.localfilepath + = parsers.slash + * Cs((parsers.anyescaped + - parsers.tab + - parsers.newline + - #(parsers.period + * parsers.alphanumeric^1 + * parsers.contentblock_tail))^1) + * parsers.period + * Cs(parsers.alphanumeric^1) + * Cc("localfile") parsers.citation_name = Cs(parsers.dash^-1) * parsers.at * Cs(parsers.alphanumeric * (parsers.alphanumeric + parsers.internal_punctuation @@ -1067,6 +1179,16 @@ end parsers.urlchar = parsers.anyescaped - parsers.newline - parsers.more parsers.Block = V("Block") +parsers.OnlineImageURL + = parsers.leader + * parsers.onlineimageurl + * parsers.optionaltitle + +parsers.LocalFilePath + = parsers.leader + * parsers.localfilepath + * parsers.optionaltitle + parsers.TildeFencedCode = parsers.fencehead(parsers.tilde) * Cs(parsers.fencedline(parsers.tilde)^0) @@ -1460,6 +1582,11 @@ function M.reader.new(writer, options) larsers.HtmlEntity = parsers.hexentity / entities.hex_entity / writer.string + parsers.decentity / entities.dec_entity / writer.string + parsers.tagentity / entities.char_entity / writer.string + larsers.ContentBlock = parsers.leader + * (parsers.localfilepath + parsers.onlineimageurl) + * parsers.contentblock_tail + / writer.contentblock + larsers.DisplayHtml = C(parsers.displayhtml) / expandtabs / writer.display_html @@ -1612,7 +1739,8 @@ function M.reader.new(writer, options) Blank = larsers.Blank, - Block = V("Blockquote") + Block = V("ContentBlock") + + V("Blockquote") + V("Verbatim") + V("FencedCode") + V("HorizontalRule") @@ -1624,6 +1752,7 @@ function M.reader.new(writer, options) + V("Paragraph") + V("Plain"), + ContentBlock = larsers.ContentBlock, Blockquote = larsers.Blockquote, Verbatim = larsers.Verbatim, FencedCode = larsers.FencedCode, @@ -1689,6 +1818,10 @@ function M.reader.new(writer, options) syntax.Citations = parsers.fail end + if not options.contentBlocks then + syntax.ContentBlock = parsers.fail + end + if not options.footnotes then syntax.NoteRef = parsers.fail end |