diff options
Diffstat (limited to 'tex/context/modules/mkiv')
-rw-r--r-- | tex/context/modules/mkiv/m-markdown.lua | 824 | ||||
-rw-r--r-- | tex/context/modules/mkiv/m-markdown.mkiv | 88 | ||||
-rw-r--r-- | tex/context/modules/mkiv/m-punk.mkiv | 4 | ||||
-rw-r--r-- | tex/context/modules/mkiv/s-maps.mkiv | 822 | ||||
-rw-r--r-- | tex/context/modules/mkiv/x-pandoc.mkiv | 152 |
5 files changed, 710 insertions, 1180 deletions
diff --git a/tex/context/modules/mkiv/m-markdown.lua b/tex/context/modules/mkiv/m-markdown.lua deleted file mode 100644 index 1f9402f60..000000000 --- a/tex/context/modules/mkiv/m-markdown.lua +++ /dev/null @@ -1,824 +0,0 @@ -if not modules then modules = { } end modules ['m-markdown'] = { - version = 1.002, - comment = "companion to m-markdown.mkiv", - author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", - copyright = "see below", - license = "see context related readme files" -} - ---[[ -Copyright (C) 2009 John MacFarlane / Khaled Hosny / Hans Hagen - -The main parser is derived from the lunamark parser written by John MacFarlane. You -can download lunamark from: - - http://github.com/jgm/lunamark.git - -Khaled Hosny provided the context writer for lunamark and that was used as starting -point for the mapping. The original code can be fetched from the above location. - -While playing with the original code I got the feeling that lpeg could perform better. -The slowdown was due to the fact that the parser's lpeg was reconstructed each time a -nested parse was needed. After changing that code a bit I could bring down parsing of -some test code from 2 seconds to less than 0.1 second so I decided to stick to this -parser instead of writing my own. After all, the peg code looks pretty impressive and -visiting Johns pandoc pages is worth the effort: - - http://johnmacfarlane.net/pandoc/ - -The code here is mostly meant for processing snippets embedded in a context -documents and is no replacement for pandoc at all. Therefore an alternative is to use -pandoc in combination with Aditya's filter module. - -As I changed (and optimized) the original code, it will be clear that all errors -are mine. Eventually I might also adapt the parser code a bit more. When I ran into of -closure stack limitations I decided to flatten the code. The following implementation -seems to be a couple of hundred times faster than what I started with which is not that -bad. - -This is a second rewrite. The mentioned speed gain largely depended on the kind of -content: blocks, references and items can be rather demanding. Also, There were -some limitations with respect to the captures. So, table storage has been removed in -favor of strings, and nesting has been simplified. The first example at the end of this -file now takes .33 seconds for 567KB code (resulting in over 1MB) so we're getting there. - -There will be a third rewrite eventually. -]]-- - --- todo: we have better quote and tag scanners in ctx --- todo: provide an xhtml mapping --- todo: add a couple of extensions --- todo: check patches to the real peg - -local type, next, tonumber = type, next, tonumber -local lower, upper, gsub, rep, gmatch, format, length = string.lower, string.upper, string.gsub, string.rep, string.gmatch, string.format, string.len -local concat = table.concat -local P, R, S, V, C, Ct, Cg, Cb, Cmt, Cc, Cf, Cs = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.C, lpeg.Ct, lpeg.Cg, lpeg.Cb, lpeg.Cmt, lpeg.Cc, lpeg.Cf, lpeg.Cs -local lpegmatch = lpeg.match -local utfbyte, utfchar = utf.byte, utf.char - -moduledata = moduledata or { } -moduledata.markdown = moduledata.markdown or { } -local markdown = moduledata.markdown - -local nofruns, nofbytes, nofhtmlblobs = 0, 0, 0 - ---------------------------------------------------------------------------------------------- - -local nestedparser -local syntax - -nestedparser = function(str) return lpegmatch(syntax,str) end - ---------------------------------------------------------------------------------------------- - -local asterisk = P("*") -local dash = P("-") -local plus = P("+") -local underscore = P("_") -local period = P(".") -local hash = P("#") -local ampersand = P("&") -local backtick = P("`") -local less = P("<") -local more = P(">") -local space = P(" ") -local squote = P("'") -local dquote = P('"') -local lparent = P("(") -local rparent = P(")") -local lbracket = P("[") -local rbracket = P("]") -local slash = P("/") -local equal = P("=") -local colon = P(":") -local semicolon = P(";") -local exclamation = P("!") - -local digit = R("09") -local hexdigit = R("09","af","AF") -local alphanumeric = R("AZ","az","09") - -local doubleasterisks = P("**") -local doubleunderscores = P("__") -local fourspaces = P(" ") - -local any = P(1) -local always = P("") - -local tab = P("\t") -local spacechar = S("\t ") -local spacing = S(" \n\r\t") -local newline = P("\r")^-1 * P("\n") -local spaceornewline = spacechar + newline -local nonspacechar = any - spaceornewline -local optionalspace = spacechar^0 -local spaces = spacechar^1 -local eof = - any -local nonindentspace = space^-3 -local blankline = optionalspace * C(newline) -local blanklines = blankline^0 -local skipblanklines = (optionalspace * newline)^0 -local linechar = P(1 - newline) -local indent = fourspaces + (nonindentspace * tab) / "" -local indentedline = indent /"" * C(linechar^1 * (newline + eof)) -local optionallyindentedline = indent^-1 /"" * C(linechar^1 * (newline + eof)) -local spnl = optionalspace * (newline * optionalspace)^-1 -local specialchar = S("*_`*&[]<!\\") -local normalchar = any - (specialchar + spaceornewline) -local line = C((any - newline)^0 * newline) - + C(any^1 * eof) -local nonemptyline = (any - newline)^1 * newline - ---------------------------------------------------------------------------------------------- - -local function lineof(c) - return (nonindentspace * (P(c) * optionalspace)^3 * newline * blankline^1) -end - -local lineof_asterisks = lineof(asterisk) -local lineof_dashes = lineof(dash) -local lineof_underscores = lineof(underscore) - -local bullet = nonindentspace * (plus + (asterisk - lineof_asterisks) + (dash - lineof_dashes)) * spaces -local enumerator = nonindentspace * digit^1 * period * spaces - ---------------------------------------------------------------------------------------------- - -local openticks = Cg(backtick^1, "ticks") -local closeticks = space^-1 * Cmt(C(backtick^1) * Cb("ticks"), function(s,i,a,b) return #a == #b and i end) -local intickschar = (any - S(" \n\r`")) - + (newline * -blankline) - + (space - closeticks) - + (backtick^1 - closeticks) -local inticks = openticks * space^-1 * C(intickschar^1) * closeticks - ---------------------------------------------------------------------------------------------- - -local leader = space^-3 -local nestedbrackets = P { lbracket * ((1 - lbracket - rbracket) + V(1))^0 * rbracket } -local tag = lbracket * C((nestedbrackets + 1 - rbracket)^0) * rbracket -local url = less * C((1-more)^0) * more - + C((1-spacing- rparent)^1) -- sneaky: ) for resolver -local title_s = squote * lpeg.C((1-squote )^0) * squote -local title_d = dquote * lpeg.C((1-dquote )^0) * dquote -local title_p = lparent * lpeg.C((1-rparent)^0) * rparent -local title = title_s + title_d + title_p -local optionaltitle = ((spacing^0 * title * spacechar^0) + lpeg.Cc("")) - -local references = { } - -local function register_link(tag,url,title) - tag = lower(gsub(tag, "[ \n\r\t]+", " ")) - references[tag] = { url, title } -end - -local function direct_link(label,url,title) -- title is typical html thing - return label, url, title -end - -local function indirect_link(label,tag) - if tag == "" then - tag = label - end - tag = lower(gsub(tag, "[ \n\r\t]+", " ")) - local r = references[tag] - if r then - return label, r[1], r[2] - else - return label, tag, "" - end -end - -local define_reference_parser = (leader * tag * colon * spacechar^0 * url * optionaltitle) / register_link -local direct_link_parser = tag * spacechar^0 * lparent * (url + Cc("")) * optionaltitle * rparent / direct_link -local indirect_link_parser = tag * spacechar^0 * tag / indirect_link - -local rparser = (define_reference_parser+1)^0 - -local function referenceparser(str) - references = { } - lpegmatch(rparser,str) -end - --- local reftest = [[ --- [1]: <http://example.com/> --- [3]:http://example.com/ (Optional Title Here) --- [2]: http://example.com/ 'Optional Title Here' --- [a]: http://example.com/ "Optional *oeps* Title Here" --- ]] --- --- local linktest = [[ --- [This link] (http://example.net/) --- [an example] (http://example.com/ "Title") --- [an example][1] --- [an example] [2] --- ]] --- --- lpeg.match((define_reference_parser+1)^0,reftest) --- --- inspect(references) --- --- lpeg.match((direct_link_parser/print + indirect_link_parser/print + 1)^0,linktest) - ---------------------------------------------------------------------------------------------- - -local blocktags = table.tohash { - "address", "blockquote" , "center", "dir", "div", "p", "pre", - "li", "ol", "ul", "dl", "dd", - "form", "fieldset", "isindex", "menu", "noframes", "frameset", - "h1", "h2", "h3", "h4", "h5", "h6", - "hr", "ht", "script", "noscript", - "table", "tbody", "tfoot", "thead", "th", "td", "tr", -} - ------ htmlattributevalue = squote * C((any - (blankline + squote))^0) * squote ------ + dquote * C((any - (blankline + dquote))^0) * dquote ------ + (any - S("\t >"))^1 -- any - tab - space - more ------ htmlattribute = (alphanumeric + S("_-"))^1 * spnl * (equal * spnl * htmlattributevalue)^-1 * spnl ------ htmlcomment = P("<!--") * (any - P("-->"))^0 * P("-->") - ------ htmltag = less * spnl * slash^-1 * alphanumeric^1 * spnl * htmlattribute^0 * slash^-1 * spnl * more ------ ------ blocktag = Cmt(C(alphanumeric^1), function(s,i,a) return blocktags[lower(a)] and i, a end) ------ ------ openblocktag = less * Cg(blocktag, "opentag") * spnl * htmlattribute^0 * more ------ closeblocktag = less * slash * Cmt(C(alphanumeric^1) * Cb("opentag"), function(s,i,a,b) return lower(a) == lower(b) and i end) * spnl * more ------ selfclosingblocktag = less * blocktag * spnl * htmlattribute^0 * slash * more ------ ------ displayhtml = Cs { "HtmlBlock", ------ InBlockTags = openblocktag * (V("HtmlBlock") + (any - closeblocktag))^0 * closeblocktag, ------ HtmlBlock = C(V("InBlockTags") + selfclosingblocktag + htmlcomment), ------ } ------ ------ inlinehtml = Cs(htmlcomment + htmltag) - --- There is no reason to support crappy html, so we expect proper attributes. - -local htmlattributevalue = squote * C((any - (blankline + squote))^0) * squote - + dquote * C((any - (blankline + dquote))^0) * dquote -local htmlattribute = (alphanumeric + S("_-"))^1 * spnl * equal * spnl * htmlattributevalue * spnl - -local htmlcomment = P("<!--") * (any - P("-->"))^0 * P("-->") -local htmlinstruction = P("<?") * (any - P("?>" ))^0 * P("?>" ) - --- We don't care too much about matching elements and there is no reason why display elements could not --- have inline elements so the above should be patched then. Well, markdown mixed with html is not meant --- for anything else than webpages anyway. - -local blocktag = Cmt(C(alphanumeric^1), function(s,i,a) return blocktags[lower(a)] and i, a end) - -local openelement = less * alphanumeric^1 * spnl * htmlattribute^0 * more -local closeelement = less * slash * alphanumeric^1 * spnl * more -local emptyelement = less * alphanumeric^1 * spnl * htmlattribute^0 * slash * more - -local displaytext = (any - less)^1 -local inlinetext = displaytext / nestedparser - -local displayhtml = #(less * blocktag * spnl * htmlattribute^0 * more) - * Cs { "HtmlBlock", - InBlockTags = openelement * (V("HtmlBlock") + displaytext)^0 * closeelement, - HtmlBlock = (V("InBlockTags") + emptyelement + htmlcomment + htmlinstruction), - } - -local inlinehtml = Cs { "HtmlBlock", - InBlockTags = openelement * (V("HtmlBlock") + inlinetext)^0 * closeelement, - HtmlBlock = (V("InBlockTags") + emptyelement + htmlcomment + htmlinstruction), - } - ---------------------------------------------------------------------------------------------- - -local hexentity = ampersand * hash * S("Xx") * C(hexdigit ^1) * semicolon -local decentity = ampersand * hash * C(digit ^1) * semicolon -local tagentity = ampersand * C(alphanumeric^1) * semicolon - ---------------------------------------------------------------------------------------------- - --- --[[ - -local escaped = { - ["{" ] = "", - ["}" ] = "", - ["$" ] = "", - ["&" ] = "", - ["#" ] = "", - ["~" ] = "", - ["|" ] = "", - ["%%"] = "", - ["\\"] = "", -} - -for k, v in next, escaped do - escaped[k] = "\\char" .. utfbyte(k) .. "{}" -end - -local function c_string(s) -- has to be done more often - return (gsub(s,".",escaped)) -end - -local c_linebreak = "\\crlf\n" -- is this ok? -local c_space = " " - -local function c_paragraph(c) - return c .. "\n\n" -- { "\\startparagraph ", c, " \\stopparagraph\n" } -end - -local function listitem(c) - return format("\n\\startitem\n%s\n\\stopitem\n",nestedparser(c)) -end - -local function c_tightbulletlist(c) - return format("\n\\startmarkdownitemize[packed]\n%s\\stopmarkdownitemize\n",c) -end - -local function c_loosebulletlist(c) - return format("\n\\startmarkdownitemize\n\\stopmarkdownitemize\n",c) -end - -local function c_tightorderedlist(c) - return format("\n\\startmarkdownitemize[n,packed]\n%s\\stopmarkdownitemize\n",c) -end - -local function c_looseorderedlist(c) - return format("\n\\startmarkdownitemize[n]\n%s\\stopmarkdownitemize\n",c) -end - -local function c_inline_html(content) - nofhtmlblobs = nofhtmlblobs + 1 - return format("\\markdowninlinehtml{%s}",content) -end - -local function c_display_html(content) - nofhtmlblobs = nofhtmlblobs + 1 - return format("\\startmarkdowndisplayhtml\n%s\n\\stopmarkdowndisplayhtml",content) -end - -local function c_emphasis(c) - return format("\\markdownemphasis{%s}",c) -end - -local function c_strong(c) - return format("\\markdownstrong{%s}",c) -end - -local function c_blockquote(c) - return format("\\startmarkdownblockquote\n%s\\stopmarkdownblockquote\n",nestedparser(c)) -end - -local function c_verbatim(c) - return format("\\startmarkdowntyping\n%s\\stopmarkdowntyping\n",c) -end - -local function c_code(c) - return format("\\markdowntype{%s}",c) -end - -local levels = { "", "", "", "", "", "" } - -local function c_start_document() - levels = { "", "", "", "", "", "" } - return "" -end - -local function c_stop_document() - return concat(levels,"\n") or "" -end - -local function c_heading(level,c) - if level > #levels then - level = #levels - end - local finish = concat(levels,"\n",level) or "" - for i=level+1,#levels do - levels[i] = "" - end - levels[level] = "\\stopstructurelevel" - return format("%s\\startstructurelevel[markdown][title={%s}]\n",finish,c) -end - -local function c_hrule() - return "\\markdownrule\n" -end - -local function c_link(lab,src,tit) - return format("\\goto{%s}[url(%s)]",nestedparser(lab),src) -end - -local function c_image(lab,src,tit) - return format("\\externalfigure[%s]",src) -end - -local function c_email_link(address) - return format("\\goto{%s}[url(mailto:%s)]",c_string(address),address) -end - -local function c_url_link(url) - return format("\\goto{%s}[url(%s)]",c_string(url),url) -end - -local function f_heading(c,n) - return c_heading(n,c) -end - -local function c_hex_entity(s) - return utfchar(tonumber(s,16)) -end - -local function c_dec_entity(s) - return utfchar(tonumber(s)) -end - -local function c_tag_entity(s) - return s -- we can use the default resolver -end - ---]] - ---------------------------------------------------------------------------------------------- - ---[[ - -local escaped = { - ["<"] = "<", - [">"] = ">", - ["&"] = "&", - ['"'] = """, -} - -local function c_string(s) -- has to be done more often - return (gsub(s,".",escaped)) -end - -local c_linebreak = "<br/>" -local c_space = " " - -local function c_paragraph(c) - return format("<p>%s</p>\n", c) -end - -local function listitem(c) - return format("<li>%s</li>",nestedparser(c)) -end - -local function c_tightbulletlist(c) - return format("<ul>\n%s\n</ul>\n",c) -end - -local function c_loosebulletlist(c) - return format("<ul>\n%s\n</ul>\n",c) -end - -local function c_tightorderedlist(c) - return format("<ol>\n%s\n</ol>\n",c) -end - -local function c_looseorderedlist(c) - return format("<ol>\n%s\n</ol>\n",c) -end - -local function c_inline_html(content) - nofhtmlblobs = nofhtmlblobs + 1 - return content -end - -local function c_display_html(content) - nofhtmlblobs = nofhtmlblobs + 1 - return format("\n%s\n",content) -end - -local function c_emphasis(c) - return format("<em>%s</em>",c) -end - -local function c_strong(c) - return format("<strong>%s</strong>",c) -end - -local function c_blockquote(c) - return format("<blockquote>\n%s\n</blockquote>",nestedparser(c)) -end - -local function c_verbatim(c) - return format("<pre><code>%s</code></pre>",c) -end - -local function c_code(c) - return format("<code>%s</code>",c) -end - -local c_start_document = "" -local c_stop_document = "" - -local function c_heading(level,c) - return format("<h%d>%s</h%d>\n",level,c,level) -end - -local function c_hrule() - return "<hr/>\n" -end - -local function c_link(lab,src,tit) - local titattr = #tit > 0 and format(" title=%q",tit) or "" - return format("<a href=%q%s>%s</a>",src,titattr,nestedparser(lab)) -end - -local function c_image(lab,src,tit) - return format("<img href=%q title=%q>%s</a>",src,tit,nestedparser(lab)) -end - -local function c_email_link(address) - return format("<a href=%q>%s</a>","mailto:",address,c_escape(address)) -end - -local function c_url_link(url) - return format("<a href=%q>%s</a>",url,c_string(url)) -end - -local function f_heading(c,n) - return c_heading(n,c) -end - -local function c_hex_entity(s) - return utfchar(tonumber(s,16)) -end - -local function c_dec_entity(s) - return utfchar(tonumber(s)) -end - -local function c_tag_entity(s) - return format("&%s;",s) -end - ---]] - ---------------------------------------------------------------------------------------------- - -local Str = normalchar^1 / c_string -local Space = spacechar^1 / c_space -local Symbol = specialchar / c_string -local Code = inticks / c_code - -local HeadingStart = C(hash * hash^-5) / length -local HeadingStop = optionalspace * hash^0 * optionalspace * newline * blanklines -local HeadingLevel = equal^3 * Cc(1) - + dash ^3 * Cc(2) - -local NormalEndline = optionalspace * newline * -( - blankline - + more - + HeadingStart - + ( line * (P("===")^3 + P("---")^3) * newline ) - ) / c_space - -local LineBreak = P(" ") * NormalEndline / c_linebreak - -local TerminalEndline = optionalspace * newline * eof / "" - -local Endline = LineBreak - + TerminalEndline - + NormalEndline - -local AutoLinkUrl = less * C(alphanumeric^1 * P("://") * (any - (newline + more))^1) * more / c_url_link -local AutoLinkEmail = less * C((alphanumeric + S("-_+"))^1 * P("@") * (any - (newline + more))^1) * more / c_email_link - -local DirectLink = direct_link_parser / c_link -local IndirectLink = indirect_link_parser / c_link - -local ImageLink = exclamation * (direct_link_parser + indirect_link_parser) / c_image -- we can combine this with image ... smaller lpeg - -local UlOrStarLine = asterisk^4 - + underscore^4 - + (spaces * S("*_")^1 * #spaces) / c_string - -local EscapedChar = P("\\") * C(P(1 - newline)) / c_string - -local InlineHtml = inlinehtml / c_inline_html -local DisplayHtml = displayhtml / c_display_html -local HtmlEntity = hexentity / c_hex_entity - + decentity / c_dec_entity - + tagentity / c_tag_entity - -local NestedList = Cs(optionallyindentedline - (bullet + enumerator))^1 / nestedparser - -local ListBlockLine = -blankline * -(indent^-1 * (bullet + enumerator)) * optionallyindentedline - -local Verbatim = Cs(blanklines * (indentedline - blankline)^1) / c_verbatim - * (blankline^1 + eof) -- not really needed, probably capture trailing? we can do that beforehand - -local Blockquote = Cs(( - ((nonindentspace * more * space^-1)/"" * linechar^0 * newline)^1 - * ((linechar - blankline)^1 * newline)^0 - * blankline^0 - )^1) / c_blockquote - -local HorizontalRule = (lineof_asterisks + lineof_dashes + lineof_underscores) / c_hrule - -local Reference = define_reference_parser / "" - --- could be a mini grammar - -local ListBlock = line * ListBlockLine^0 -local ListContinuationBlock = blanklines * indent * ListBlock -local ListItem = Cs(ListBlock * (NestedList + ListContinuationBlock^0)) / listitem - ----- LeadingLines = blankline^0 / "" ----- TrailingLines = blankline^1 * #(any) / "\n" - -syntax = Cs { "Document", - - Document = V("Display")^0, - - Display = blankline -- ^1/"\n" - + Blockquote - + Verbatim - + Reference - + HorizontalRule - + HeadingStart * optionalspace * Cs((V("Inline") - HeadingStop)^1) * HeadingStop / c_heading - + Cs((V("Inline") - Endline)^1) * newline * HeadingLevel * newline * blanklines / f_heading - + Cs((bullet /"" * ListItem)^1) * blanklines * -bullet / c_tightbulletlist - + Cs((bullet /"" * ListItem * C(blanklines))^1) / c_loosebulletlist - + Cs((enumerator /"" * ListItem)^1) * blanklines * -enumerator / c_tightorderedlist - + Cs((enumerator /"" * ListItem * C(blanklines))^1) / c_looseorderedlist - + DisplayHtml - + nonindentspace * Cs(V("Inline")^1)* newline * blankline^1 / c_paragraph - + V("Inline")^1, - - Inline = Str - + Space - + Endline - + UlOrStarLine -- still needed ? - + doubleasterisks * -spaceornewline * Cs((V("Inline") - doubleasterisks )^1) * doubleasterisks / c_strong - + doubleunderscores * -spaceornewline * Cs((V("Inline") - doubleunderscores)^1) * doubleunderscores / c_strong - + asterisk * -spaceornewline * Cs((V("Inline") - asterisk )^1) * asterisk / c_emphasis - + underscore * -spaceornewline * Cs((V("Inline") - underscore )^1) * underscore / c_emphasis - + ImageLink - + DirectLink - + IndirectLink - + AutoLinkUrl - + AutoLinkEmail - + Code - + InlineHtml - + HtmlEntity - + EscapedChar - + Symbol, - -} - ---------------------------------------------------------------------------------------------- - -local function convert(str) - nofruns = nofruns + 1 - nofbytes = nofbytes + #str - statistics.starttiming(markdown) - referenceparser(str) - local result = c_start_document() .. nestedparser(str) .. c_stop_document() - statistics.stoptiming(markdown) - return result -end - -markdown.convert = convert - -function markdown.typesetstring(data) - if data and data ~= "" then - local result = convert(data) - context.viafile(result) - end -end - -function markdown.typesetbuffer(name) - markdown.typesetstring(buffers.getcontent(name)) -end - -function markdown.typesetfile(name) - local fullname = resolvers.findctxfile(name) - if fullname and fullname ~= "" then - markdown.typesetstring(io.loaddata(fullname)) - end -end - -statistics.register("markdown",function() - if nofruns > 0 then - return format("%s bytes converted, %s runs, %s html blobs, %s seconds used", - nofbytes, nofruns, nofhtmlblobs, statistics.elapsedtime(markdown)) - end -end) - ---------------------------------------------------------------------------------------------- - ---~ context.starttext() ---~ moduledata.markdown.convert(str) ---~ context.stoptext() - -if not tex.jobname then - - local one = [[ -Test *123* -========== - -<b>BOLD *BOLD* BOLD</b> - -<pre>PRE <b>PRE</b> PRE</pre> - - -* Test -** Test -* Test1 - * Test2 -* Test - -Test -==== - -> test -> test **123** *123* -> test `code` - -test - -Test -==== - -> test -> test -> test - -test -oeps - -more - - code - code - -oeps - -[an example][a] - -[an example] [2] - -[a]: http://example.com/ "Optional *oeps* Title Here" -[2]: http://example.com/ 'Optional Title Here' -[3]: http://example.com/ (Optional Title Here) - -[an example][a] - -[an example] [2] - -[an [tricky] example](http://example.com/ "Title") - -[This **xx** link](http://example.net/) - ]] - --- This snippet takes some 4 seconds in the original parser (the one that is --- a bit clearer from the perspective of grammars but somewhat messy with --- respect to the captures. In the above parser it takes .1 second. Also, --- in the later case only memory is the limit. - - local two = [[ -Test -==== -* Test -** Test -* Test -** Test -* Test - -Test -==== - -> test -> test -> test - -test - -Test -==== - -> test -> test -> test - -test - ]] - - local function test(str) - local n = 1 -- 000 - local t = os.clock() - local one = convert(str) - -- print("runtime",1,#str,#one,os.clock()-t) - str = string.rep(str,n) - local t = os.clock() - local two = convert(str) - print(two) - -- print("runtime",n,#str,#two,os.clock()-t) - -- print(format("==============\n%s\n==============",one)) - end - - -- test(one) - -- test(two) - -- test(io.read("*all")) - - -end diff --git a/tex/context/modules/mkiv/m-markdown.mkiv b/tex/context/modules/mkiv/m-markdown.mkiv deleted file mode 100644 index 29d41341e..000000000 --- a/tex/context/modules/mkiv/m-markdown.mkiv +++ /dev/null @@ -1,88 +0,0 @@ -%D \module -%D [ file=x-markdown, -%D version=2011.07.19, -%D title=\CONTEXT\ Modules, -%D subtitle=Processing MarkDown, -%D author=Hans Hagen, -%D date=\currentdate, -%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] -%C -%C This module is part of the \CONTEXT\ macro||package and is -%C therefore copyrighted by \PRAGMA. See mreadme.pdf for -%C details. - -\writestatus{loading}{ConTeXt Modules / MarkDown Renderer} - -%D This module deals with markdown which is a document encoding that -%D some \CONTEXT\ like much. It reminds me of the kind of minimal coding -%D we used before we ran into \TEX\ and were using a somewhat simple -%D rendering (pagination, etc) of documents. As I'm no user myself, it -%D is up to others to provide documentation and examples. - -\registerctxluafile{m-markdown}{} - -\unprotect - -% basic interface - -\definebuffer[markdown] - -\unexpanded\def\stopmarkdown - {\ctxlua{moduledata.markdown.typesetbuffer("\thedefinedbuffer{markdown}")}} - -\unexpanded\def\processmarkdownfile#1% maybe [] or both - {\ctxlua{moduledata.markdown.typesetfile("#1")}} - -\unexpanded\def\markdown#1% maybe [] or both - {\ctxlua{moduledata.markdown.typesetstring(\!!bs#1\!!es)}} - -% commands - -\defineitemgroup - [markdownitemize] - -\definetyping - [markdowntyping] - -\definetype - [markdowntype] - -\definetype - [markdowninlinehtml] - -\definetyping - [markdowndisplayhtml] - -\definedelimitedtext - [markdownblockquote] - [quotation] - -\definehighlight - [markdownemphasis] - [style=\em] - -\definehighlight - [markdownstrong] - [style=\bf] - -\definestructurelevels - [markdown] - [\v!chapter, - \v!section, - \v!subsection, - \v!subsubsection, - \v!subsubsubsection, - \v!subsubsubsubsection] - -\unexpanded\def\markdownrule - {\hairline\par} - -\protect - -\continueifinputfile{m-markdown.mkiv} - -\starttext - \startmarkdown - % some examples needed - \stopmarkdown -\stoptext diff --git a/tex/context/modules/mkiv/m-punk.mkiv b/tex/context/modules/mkiv/m-punk.mkiv index 29a6d8cca..47f1a0177 100644 --- a/tex/context/modules/mkiv/m-punk.mkiv +++ b/tex/context/modules/mkiv/m-punk.mkiv @@ -63,8 +63,8 @@ local flusher = { boundingbox = { 0, -d, w, h }, } characters[n] = { - commands = { -- todo: xforms, should happen in backend - { "special", "pdf: " .. concat(l," ") }, + commands = { -- todo: type 3 in lmtx + { "pdf", concat(l," ") }, } } else diff --git a/tex/context/modules/mkiv/s-maps.mkiv b/tex/context/modules/mkiv/s-maps.mkiv index 28e88af98..bc0bcbaa0 100644 --- a/tex/context/modules/mkiv/s-maps.mkiv +++ b/tex/context/modules/mkiv/s-maps.mkiv @@ -7,30 +7,38 @@ %D date=\currentdate, %D copyright=NTG/MAPS] -% This module implements the MAPS style for use with the Context -% macro package. The original MAPS layout was designed and -% implemented in LaTeX by Taco Hoekwater and Siep Kroonenberg. - -% - three layouts: -% 1. two columns -% 2. one column, with wide outer margins (option onecolumn) -% 3. one column, with wide left margin (option asym) -% - font sizes deviate from TeX's usual geometric progression -% - use of sans-serif for headers and various details -% - option realfonts uses Linux Libertine, Euler Math and Inconsolata. -% This is used for final typesetting. -% The default font setup, intended for authors, uses Computer -% Modern Math instead of Euler Math (which is still in beta), -% and LM Mono instead of Inconsolata. - -% A mode nosubsub defines only two levels of sectioning. If you -% don't need more and use the two-column layout, then this option -% will probably improve the looks of your paper. +%D This module implements the MAPS style for use with the Context macro package. The +%D original MAPS layout was designed and implemented in LaTeX by Taco Hoekwater and +%D Siep Kroonenberg. +%D +%D \startitemize +%D \startitem +%D four layouts: +%D \startitemize +%D \startitem two columns \stopitem +%D \startitem one column, with wide outer margins (option onecolumn) \stopitem +%D \startitem one column, with wide left margin (option asym) \stopitem +%D \startitem one column, with wide right margin (option single) \stopitem +%D \stopitemize +%D \stopitem +%D \startitem +%D font sizes deviate from TeX's usual geometric progression +%D \stopitem +%D \startitem +%D use of sans-serif for headers and various details +%D \stopitem +%D \stopitemize +%D +%D A mode nosubsub defines only two levels of sectioning. If you don't need more and +%D use the two-column layout, then this option will probably improve the looks of +%D your paper. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newif\ifMapsInColumns -\doifmode{asym}{\enablemode[onecolumn]} % implies onecolumn + +\doifmode {asym} {\enablemode[onecolumn]} % implies onecolumn +\doifmode {single} {\enablemode[asym,onecolumn]} % implies onecolumn \doifnotmode{onecolumn}{\MapsInColumnstrue} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -98,31 +106,31 @@ %%% font families -\starttypescript [maps] -\definetypeface [maps] [rm] [serif] [modern] [default] [rscale=0.95] -\definetypeface [maps] [mm] [math] [modern] [latin-modern] -\definetypeface [maps] [tt] [mono] [modern] [default] [rscale=0.90] -\definetypeface [maps] [ss] [sans] [modern] [default] [rscale=0.95] +\definefontfeature[mapsdef][default][mode=node,onum=yes,lnum=no] + +\starttypescript [serif] [libertine] [name] + \setups[font:fallback:serif] + \definefontsynonym [Serif] [file:LinLibertine_R.otf] [features=mapsdef] + \definefontsynonym [SerifItalic] [file:LinLibertine_RI.otf] [features=mapsdef] + \definefontsynonym [SerifSlanted] [file:LinLibertine_RI.otf] [features=mapsdef] + \definefontsynonym [SerifBold] [file:LinLibertine_RB.otf] [features=mapsdef] + \definefontsynonym [SerifBoldItalic] [file:LinLibertine_RBI.otf] [features=mapsdef] + \definefontsynonym [SerifBoldSlanted] [file:LinLibertine_RBI.otf] [features=mapsdef] + \definefontsynonym [SerifCaps] [file:LinLibertine_R.otf] [features=smallcaps] \stoptypescript -\startmode[realfonts] -\usetypescriptfile[type-libertine] - -\usetypescriptfile[type-inconsolata] - \starttypescript [maps] -\definetypeface [maps] [rm] [serif] [libertine] [default] -\definetypeface [maps] [mm] [math] [euler] [default] [rscale=0.9] -\definetypeface [maps] [tt] [mono] [inconsolata] [default] [rscale=0.92] -\definetypeface [maps] [ss] [sans] [modern] [default] [rscale=0.95] + \definetypeface [maps] [rm] [serif] [libertine] [default] + \definetypeface [maps] [mm] [math] [euler] [default] [rscale=0.9] + \definetypeface [maps] [tt] [mono] [modern] [default] + \definetypeface [maps] [ss] [sans] [modern] [default] [rscale=0.95] \stoptypescript -\stopmode \setupbodyfont[maps,10pt,rm] -% activate protruding \setupinterlinespace[line=11pt] +% activate protruding \setupfontsynonym[handling=pure] \setupalign[hanging] @@ -142,7 +150,7 @@ \setuppapersize [maps][maps] -\setuplayout[ +\setuplayout [topspace=40pt, height=688pt, header=33pt, @@ -166,154 +174,137 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% sectioning -\setupheads[sectionnumber=no, align=right] - -\def\hfonti{\ssbfa} -\def\hfontii{\ssbf} -\def\hfontiii{\rm\it} +\setupheads + [number=no, + align=flushleft] + +\unexpanded\def\hfonti {\ssbfa} +\unexpanded\def\hfontii {\ssbf} +\unexpanded\def\hfontiii {\rm\bi} +\unexpanded\def\runin #1{#1} + +\setuphead [section,subject] + [style=\hfonti, + before={\blank[line]}, + after={\blank[halfline]}] +\setuphead [subsection,subsubject] + [style=\hfontii, + before={\blank[halfline]}, + after={}] +\setuphead [subsubsection,subsubsubject] + [style=\hfontiii, + deeptextcommand=\runin, + distance=6pt, + alternative=text, + before={\blank[halfline]}] + +\startmode[nosubsub] +\setuphead [section,subject] + [style=\hfontii, + before={\blank[line]}, + after={}] +\setuphead [subsection,subsubject] + [style=\hfontiii, + deeptextcommand=\runin, + alternative=text, + distance=6pt, + before={\blank[halfline]}] +\stopmode -\doifelsemode{nosubsub}{% -\setuphead [section][% - style=\hfontii, - before={\blank[line]}, - after={}% -] -\setuphead [subsection][% - style=\hfontiii, - alternative=text, - distance=6pt, - before={\blank[halfline]}% -]}{% -\setuphead [section][% - style=\hfonti, - before={\blank[line]}, - after={\blank[halfline]}% -] -\setuphead [subsection][% - style=\hfontii, - before={\blank[halfline]}, - after={}% -] -\setuphead [subsubsection][% - style=\hfontiii, - distance=6pt, - alternative=text, - before={\blank[halfline]}% -]} - -\doifelsemode{nosubsub}{% -\setuphead [subject][% - style=\hfontii, - before={\blank[halfline]}, - after={}% -] -\setuphead [subsubject][% - style=\hfontiii, - alternative=text, - before={\blank[halfline]}% -]}{% -\setuphead [subject][% - style=\hfonti, - before={\blank}, - after={\blank[halfline]}% -] -\setuphead [subsubject][% - style=\hfontii, - before={\blank[halfline]}, - after={}% -] -\setuphead [subsubsubject][% - style=\hfontiii, - alternative=text, - before={\blank[halfline]}% -]} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% floats -\setupfloats [location=center, before={\ss}] -\setupcaptions [headstyle={\ssbf},style={\ssx}, - suffix=.,distance=6pt, +\setupfloats + [location=left, + before={\ss}] + +\setupcaptions + [align=flushleft, + headstyle={\ssbf}, + style={\ssx}, + suffix=., + distance=6pt, inbetween={\blank[halfline]}] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% various document elements -\definesymbol [1][\getnamedglyphdirect{file:stmary10}{boxempty}] +\setupitemize + [1] + [symbol=8] -\setupitemize[1][packed] - -\setupitemize [each][% - indentnext=no, - align=right, - width=1em, - distance=0pt% -] +\setupitemize + [each] + [before={\blank[line]}, + after={\blank[line]}, + inbetween=, + indentnext=no, + width=12pt, + distance=0pt] % an outer form of itemize that does not indent % the paragraph. \definecomplexorsimpleempty\startouteritemize -\def\complexstartouteritemize[#1]{\begingroup - \startitemize[width=1sp,#1] - \let\doitem\item - \def\item{\doitem[]\hbox{}\kern12pt\rightskip=0pt}% -} - -\def\stopouteritemize{\stopitemize\endgroup} - -\setupenumerations [indentnext=no] +\def\complexstartouteritemize[#1]% + {\begingroup + \setupitemize[width=0pt,inbetween={\blank},before={\blank},after={\blank}] + \startitemize[#1] + \let\doitem\item + \def\item{\doitem[]\hbox{}\kern12pt\rightskip=0pt}} -\setupdescriptions [indentnext=no] +\def\stopouteritemize + {\stopitemize\endgroup} -\unexpanded\def\smalltyping{% - \switchtobodyfont[tt]% - \parindent=0pt -} +\definedescription + [description] + [alternative=hanging,width=fit] % typing: % - prettyverbatim is NOT the default -% - smaller size -\unexpanded\def - \XeTeX{X\lower.5ex\hbox{\kern-.1em\mirror{E}}\kern-.1667em\TeX} +\setuptyping + [style={\switchtobodyfont[small,tt]}, + option=none, + indentnext=no] -\setuptyping [% - style={\smalltyping}, - option=none, - indentnext=no% -] - -\def\footnum#1{#1.} +% normally we have endnotes, but in the title there +% could be a \thanks command. Since the new column mode +% does not deal with footnotes all that well, we more +% or less have to roll our own. \setupnotation - [footnote] - [alternative=serried, - before=, - after=, - location=none, - width=\textwidth, - before={\blank}, - numbercommand=, - command=\footnum, - distance=0.5em] + [footnote] + [margin=0cm, + before={}, + after={}, + way=bypage, + number=no] + +\setupnote + [footnote] + [location=page, + spacebefore=, + before=, + after=] + +\unexpanded\def\thanks#1{\xdef\MapsThanks{#1}*} \setuptabulate - [before=\blank, - inner=\ss, - after=\blank] + [before=\blank, + inner=\ss, + after=\blank] \def\startIntroEntry#1% - {\startlinecorrection - \bgroup + {\bgroup \setupalign[right] \setuptolerance[verytolerant] \setupindenting[no] \noindent \switchtobodyfont[9pt]% \setuplocalinterlinespace[line=10pt]% - %\hyphenpenalty10000 \parfillskip 0pt plus 1fill \rightskip6pt plus 1fill \ss @@ -321,15 +312,15 @@ \ignorespaces } \def\stopIntroEntry - {\par\egroup \stoplinecorrection + {\par\egroup \blank[line] } -\def\defineIntroEntry[#1][#2][#3]% +\def\defineIntroEntry[#1][#2] {\setvalue{start#1}{\startIntroEntry{#2}}% - \setvalue {stop#1}{\stopIntroEntry#3}} + \setvalue {stop#1}{\stopIntroEntry}} -\defineIntroEntry[Keywords][Keywords][] -\defineIntroEntry[Abstract][Abstract][] +\defineIntroEntry[Keywords][Keywords] +\defineIntroEntry[Abstract][Abstract] % article parameters (other fields and defaults) \def\MapsBibData[#1]% @@ -345,82 +336,141 @@ Period=, Number=, Year=, + SkipHeader=, + SkipFooter=, + Abstract=, + Keywords=, + Thanks=, #1]% - \doifnothing{\MapsPeriod}{% - \ifnum \normalmonth<6 \gdef\MapsPeriod{VOORJAAR}\else \gdef\MapsPeriod{NAJAAR}\fi} - \doifelseinstring{oorjaar}{\MapsPeriod}{\gdef\MapsPeriod{VOORJAAR}}{}% - \doifelseinstring{pring}{\MapsPeriod}{\gdef\MapsPeriod{VOORJAAR}}{}% - \doifelseinstring{ajaar}{\MapsPeriod}{\gdef\MapsPeriod{NAJAAR}}{}% - \doifelseinstring{utumn}{\MapsPeriod}{\gdef\MapsPeriod{NAJAAR}}{}% + \doifnothing{\MapsPeriod}% + {\ifnum \normalmonth<6 \gdef\MapsPeriod{VOORJAAR}\else \gdef\MapsPeriod{NAJAAR}\fi} + \doifinstringelse{oorjaar}{\MapsPeriod}{\gdef\MapsPeriod{VOORJAAR}}{}% + \doifinstringelse{pring}{\MapsPeriod}{\gdef\MapsPeriod{VOORJAAR}}{}% + \doifinstringelse{ajaar}{\MapsPeriod}{\gdef\MapsPeriod{NAJAAR}}{}% + \doifinstringelse{utumn}{\MapsPeriod}{\gdef\MapsPeriod{NAJAAR}}{}% \doifnothing{\MapsYear}{\gdef\MapsYear{\the\year}}% - \doifnothing{\MapsNumber}{% - \ifnum \normalmonth<6 + \doifnothing{\MapsNumber}% + {\ifnum \normalmonth<6 \xdef\MapsNumber{\the\numexpr (\the\year-1990)*2\relax}% - \else + \else \xdef\MapsNumber{\the\numexpr (\the\year-1990)*2+1\relax}% - \fi }% + \fi }% \doifnothing\MapsRunningAuthor - {\glet\MapsRunningAuthor\MapsAuthor}% + {\global\let\MapsRunningAuthor\MapsAuthor}% \doifnothing\MapsRunningTitle - {\glet\MapsRunningTitle\MapsTitle}}% - -\def\dostartArticle[#1]{% - \MapsBibData[#1] - \pageno=\MapsPage - \setupuserpagenumber[start=\MapsPage] - \startbaselinecorrection - \bgroup - \hsize = 457pt - \let\\\crlf - \blank[35pt,force] - \switchtobodyfont[24pt] - \setupalign[right] - {\noindent\bf\MapsTitle\par} - \ifx\MapsSubTitle\empty - \blank[30pt] - \else - \bgroup - \blank[12pt] - \switchtobodyfont[18pt]\noindent \it - \advance \rightskip 0pt plus 2em - \MapsSubTitle\par - \egroup - \blank[30pt] - \fi - \egroup - \setupalign[width] - \switchtobodyfont[rm,10pt] - \stopbaselinecorrection - \ifMapsInColumns - \startcolumns\hyphenpenalty1000 - \else - \clubpenalty10000 - \widowpenalty10000 - \fi -} - -\def\startArticle{\dosingleempty\dostartArticle} - -\def\signArticle{% - \blank\let\\\crlf - \noindent\switchtobodyfont[ss,9pt]% - \MapsAuthor - \doifsomething{\MapsAddress}{\\\MapsAddress}% - \doifsomething{\MapsEmail}{\\\MapsEmail}% - \switchtobodyfont[10pt]% - \def\signArticle{}% -} - -\def\stopArticle{% - \par\signArticle - \ifMapsInColumns \stopcolumns \fi - \page -} + {\global\let\MapsRunningTitle\MapsTitle}}% + +\def\doarticleheader + {\startbaselinecorrection + \bgroup + \hsize = 457pt + \let\\\crlf + \blank[35pt,force] + \switchtobodyfont[24pt] + \startalign[flushleft,verytolerant,extremestretch] + {\noindent\bf\language=-1\MapsTitle\par} + \ifx\MapsSubTitle\empty + \blank[line] + \else + \bgroup + \blank[12pt] + \switchtobodyfont[14pt]\noindent \it + \advance \rightskip 0pt plus 2em + \MapsSubTitle\par + \egroup + \blank[line] + \fi + \stopalign + \egroup + \setupalign[width] + \switchtobodyfont[rm,10pt] + \stopbaselinecorrection } + +\newif\ifintroentries + +\def\dostartArticle[#1]% + {\MapsBibData[#1] + \pageno=\MapsPage + \setnumber[realpage][\MapsPage] + \setnumber[userpage][\MapsPage] + \doifnothing{\MapsSkipHeader}{\doarticleheader}% + \ifMapsInColumns + \startcolumns\hyphenpenalty1000 + \else + \clubpenalty10000 + \widowpenalty10000 + \fi + \introentriesfalse + \startbaselinecorrection + \doifsomething{\MapsAbstract}{\startAbstract \MapsAbstract \stopAbstract \introentriestrue } + \doifsomething{\MapsKeywords}{\startKeywords \MapsKeywords \stopKeywords \introentriestrue } + \stopbaselinecorrection + \ifintroentries + \blank[2*line] + \fi + \doifsomething\MapsThanks + {\expanded{\footnote[thanks]{*\quad\strut\MapsThanks}}% + \kern -22pt }% need to unskip because of the silent \footnote + \let\footnote\endnote } + +\def\startArticle + {\dosingleempty\dostartArticle} + +\def\signArticle + {\doifnothing + {\MapsSkipFooter} + {\blank[line]\let\\\crlf + \noindent\switchtobodyfont[ss,9pt]% + \MapsAuthor + \doifsomething{\MapsAddress}{\\\MapsAddress}% + \doifsomething{\MapsEmail}{\\\MapsEmail}}% + \switchtobodyfont[10pt]% + \def\signArticle{}} + +% endnotes aka footnotes + +\def\footnum#1{#1.} + +\setupnotation + [endnote] + [alternative=serried, + style={\switchtobodyfont[9pt]}, + margin=0cm, + width=12pt, + before=, + after=, + margin=0cm, + numbercommand=\footnum] + +\setupnote + [endnote] + [location=none] + +\def\endnotessubjectname{Footnotes} +\def\endnotesubjectname{Footnote} + +\def\stopArticle + {\ifcase\rawcountervalue[endnote]\relax + \or + \startsubject[title=\endnotesubjectname] % single + \placenotes[endnote] + \stopsubject + \else + \startsubject[title=\endnotessubjectname] + \placenotes[endnote] + \stopsubject + \fi + \par\signArticle + \ifMapsInColumns \stopcolumns \fi + \page } \installpagebreakmethod{last}{} %%% `logos' %%%%%%%%%%%%%%%%%%%%%%%%%% +\unexpanded\def\XeTeX + {X\lower.5ex\hbox{\kern-.1em\mirror{E}}\kern-.1667em\TeX} + \unexpanded\def\LaTeX % requested by erik frambach {{\setbox\scratchbox\hbox{L}% \scratchdimen\ht\scratchbox @@ -429,66 +479,306 @@ \raise\scratchdimen\hbox{\lower\ht\scratchbox\copy\scratchbox}% \kern-.2\wd\scratchbox\TeX}} +\unexpanded\def\CONTEXT {Con{\TeX}t} +\unexpanded\def\ConTeXt {Con{\TeX}t} +\unexpanded\def\METAFONT {Metafont} +\unexpanded\def\METAPOST {MetaPost} +\unexpanded\def\POSTSCRIPT{PostScript} -\def\CONTEXT{Con{\TeX}t} -\def\ConTeXt{Con{\TeX}t} -\def\METAFONT{Metafont} -\def\METAPOST{MetaPost} -\def\POSTSCRIPT{PostScript} +\unexpanded\def\acro#1{{\switchtobodyfont[9pt]#1}} -\def\acro#1{{\switchtobodyfont[9pt]#1}} +\definefontfeature[smallcapitals] [smcp=yes] +\def\sc{\addff{smallcapitals}} +\def\NTG{{\sc ntg}} +\def\TUG{{\sc tug}} %%%%%%%%%%% +% headers and footers and other mode-related things +\setuplayout + [width=457pt] -\doifelsemode{onecolumn}{% - \setuplayout[width=340pt] - \doifelsemode{asym}{% one col, asymmetric - \setuplayout[backspace=187.3pt]% - \setuptyping [widetyping][oddmargin=-117pt] - \setuppagenumbering [alternative={singlesided,doublesided}] - \setupheadertexts - [{\hbox{}\hskip-117pt\TiHead}] - [{\cap{\MapsPeriod\ \MapsYear}\quad\bf \pagenumber\hskip-30pt\hbox{}}] - [{\hbox{}\hskip-147pt{\bf \pagenumber}\quad \cap {maps\ \MapsNumber}}] - [\AuHead] - \setupfootertexts - }{% one col, symmetric - \setuplayout[backspace=70.3pt] - \setuppagenumbering [alternative=doublesided] - \setuptyping[blank=halfline] - \setupheadertexts +\setupcolumns + [n=2,tolerance=verytolerant,distance=11pt] + +\setuplayout + [backspace=70.3pt,grid=yes] + +\setuppagenumbering + [alternative=doublesided] + +\setuptyping + [blank=halfline] + +\setupheadertexts + [\TiHead] + [{\cap{\MapsPeriod\ \MapsYear}\quad\bf \pagenumber\hskip-30pt\hbox{}}] + [{\hbox{}\hskip-30pt{\bf \pagenumber}\quad \cap {maps\ \MapsNumber}}] + [\AuHead] + +\setupfootertexts % empty + +\startmode[onecolumn] + +\setuplayout[width=340pt] + +\startmode[asym]% one col, asymmetric + \setuppagenumbering + [alternative={singlesided,doublesided}] + \doifmodeelse + {single} + {\setupheadertexts [\TiHead] [{\cap{\MapsPeriod\ \MapsYear}\quad\bf \pagenumber\hskip-147pt\hbox{}}] + [{\hbox{}\hskip-30pt{\bf \pagenumber}\quad \cap {maps\ \MapsNumber}}] + [\AuHead\hskip-110pt]} + {\setuptyping + [widetyping] + [oddmargin=-117pt] + \setuplayout[backspace=187.3pt] + \setupheadertexts + [{\hbox{}\hskip-117pt\TiHead}] + [{\cap{\MapsPeriod\ \MapsYear}\quad\bf \pagenumber\hskip-30pt\hbox{}}] [{\hbox{}\hskip-147pt{\bf \pagenumber}\quad \cap {maps\ \MapsNumber}}] - [\AuHead] - \setupfootertexts -}}{% two col - \setuplayout[width=457pt] - \setupcolumns[n=2,tolerance=verytolerant,distance=11pt] - \setuplayout[backspace=70.3pt,grid=yes] - \setuppagenumbering [alternative=doublesided] - \setuptyping[blank=halfline] - \setupheadertexts + [\AuHead]} +\stopmode + +\startnotmode[asym] + \setupheadertexts [\TiHead] - [{\cap{\MapsPeriod\ \MapsYear}\quad\bf \pagenumber\hskip-30pt\hbox{}}] - [{\hbox{}\hskip-30pt{\bf \pagenumber}\quad \cap {maps\ \MapsNumber}}] + [{\cap{\MapsPeriod\ \MapsYear}\quad\bf \pagenumber\hskip-147pt\hbox{}}] + [{\hbox{}\hskip-147pt{\bf \pagenumber}\quad \cap {maps\ \MapsNumber}}] [\AuHead] - \setupfootertexts -} +\stopnotmode + +\stopmode % onecolumn + \def\fulltextwidth{457pt} -\def\startdescription - {\blank - \bgroup - \def\sym##1{\par\noindent\hbox{\bf\kern -16pt ##1}\hskip 12pt} - \startnarrower[left] - } -\def\stopdescription - {\par \stopnarrower \egroup \blank \noindentation } +\def\startfullwidth + {\par\begingroup + \doifmode + {onecolumn} + {\hsize=\fulltextwidth + \doifmodeelse + {asym} + {\doifmodeelse{single}{\textwidth=\fulltextwidth }{\leftskip-117pt }} + {\ifodd\pageno \else \leftskip-117pt \hsize=340pt \fi }}} + +\def\stopfullwidth + {\par\endgroup} + +% Taco: \setupalign[tolerant,fixed} where fixed is french spacing + +\setupalign + [tolerant,fixed] + +\continueifinputfile{s-maps.mkiv} + +% \enabletrackers[mixedcolumns.*] + +% \enablemode[nosubsub] % if you need at most two levels of sectioning +% \enablemode[onecolumn] % for symmetric single-column layout +% \enablemode[asym] % for asymmetric single-column layout, left aligned +% \enablemode[single] % for asymmetric single-column layout, right aligned + +% \usemodule[map-20] + +\usebtxdataset[samplmaps.bib] +\usebtxdefinitions[apa] + +\starttext +\startArticle[% Use {} if argument contains comma's! +% titel + Title={An example document for the Maps module, demonstrating its + various features\thanks{Thanks should be short} + }, + RunningTitle=An example document, + SubTitle=with an optional subtitle, +% auteur + Author=Anton Ulrich Thor, + Email=a.u.thor@uu.am.dw, + Address=Institute of Indefinite Studies\\ + Unseen University\\ + Ankh Morpork, +% tijdstip + Period=voorjaar, + Number=36, + Year=2008, + Page=1, +% Taal + Language=english, +% Intro + Abstract={% +This is a sample input file for the Maps module version 2.0, +which mimics the associated \LaTeX\ class file. +It demonstrates various standard and non-standard features. +\crlf +Use of the abstract- and keywords environments is highly appreciated.}, + Keywords={Maps, \ConTeXt\ module, sample}] + +\startsection[title=Ordinary Text] + +The ends of words and sentences are marked + by spaces. It doesn't matter how many +spaces you type; one is as good as 100. The +end of a line counts as a space. + +One or more blank lines denote the end +of a paragraph. + +Footnotes\footnote{This is an example of an endnote.} are converted to +endnotes\endnote{This is another one, with more text to it, to see how +it will wrap to the next line.}. These will automatically be typeset at +the end of the article. The title of the notes section is defined by the +command \type{\endnotessubjectname} (for multiple notes) or +\type{\endnotesubjectname} (in case of a single note). + +\stopsection + +\startsection[title=Fonts] +The Maps uses Linux Libertine for main text, +with Latin Modern Sans and Mono, and Euler for math. The Linux Libertine +OpenType fonts are part of \TeX\ Live. If they are not found, +Latin Modern Serif fallbacks will be used. + +\stopsection + +\startsection[title=Sectioning] + +The maps module defaults to unnumbered sections. If you really must, +you can restore section numbering with \emph{e.g.} +\type{\setupheads[number=yes]} + +\startsubsection[title=Subsection] +This is a second-level section header. You can go down one more +level: + +% \penalty0 + +\startsubsubsection[title=A subsubsection] +This is supposed to be a run-in header, so make sure you start the +text right after \type{\startsubsubsection}. + +\stopsubsubsection + +\startsubsubsection[title=Tip] +If you only need one or two levels of header, then you can get a +better layout with the \type{nosubsub} document option. +The Maps editors may decide to turn on this option for you. +\stopsubsubsection + +\stopsubsection + +\stopsection + +\startsection[title=Lists] + +Another frequently-displayed structure is a list. +The following is an example of an \emph{itemized} +list. +\startitemize + \item This is the first item of an itemized list. + Each item in the list is marked with a \quote{tick}. + \item This is the second item of the list. It + contains another list nested inside it. The inner + list is an \emph{enumerated} list. + + \startitemize[n] + \startitem This is the first item of an enumerated + list that is nested within the itemized list. + \stopitem + \item This is the second item of the inner list. + \ConTeXt\ allows you to nest lists deeper than + you really should. + \stopitem + \stopitemize + + \noindent + This is the rest of the second item of the outer + list. It is no more interesting than any other + part of the item. + \startitem This is the third item of the list. \stopitem +\stopitemize + +In a two-column layout, protracted indenting doesn't look very +good. Therefore, the Maps module provides an \type{outeritemize} +environment: + +\startouteritemize +\item This is the first item of a non-indented itemized list, + produced with the \mono{outeritemize} environment. +\item This is the second item. +\stopouteritemize + +Now an enumerated version: + +\startouteritemize[n] +\item This is the first item of a non-indented enumerated list, + produced with the \mono{outeritemize} environment. +\item This is the second item. +\stopouteritemize + +There is also a definition for description lists: + +\startdescription{cow} +A milk-producing animal that grazes grass and has multiple stomachs +\stopdescription +\startdescription{kangoroo} +An Australian hopping animal +\stopdescription + +\stopsection + +\startsection[title=Wide typesetting in single-column layout] + +For both single-column layouts, there are environments \type{fullwidth} and +\type{widetyping} which typeset their content across the full page, +including most of the wide margin. + +\startfullwidth +x x x x x x x x x x x x x x x x x x x x x +x x x x x x x x x x x x x x x x x x x x x +x x x x x x x x x x x x x x x x x x x x x +x x x x x x x x x x x x x x x x x x x x x +\stopfullwidth -\frenchspacing -\setuptolerance[tolerant] +\startwidetyping +{}\/$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +\stopwidetyping +The implementation of \type{fullwidth} is rather simplistic and +may easily break, in which case more sophisticated hackery will be +needed. + +\stopsection + +\startsection[title=Assembling your submission] + +Please check whether all non-standard modules and all +non-standard fonts are included. We do have a current \TeX{} Live but, +although we do have access to CTAN, finding the right stuff by +name can occasionally be a challenge. + +Avoid jpeg compression for screenshots. Conversion to pdf may +sometimes result in jpeg compression as well. Use \emph{e.g.} png +format instead. + +Finally, a pdf of your article is appreciated. This way, we can +check more reliably whether your article compiles +correctly on our own systems. + +\stopsection +\startsection[title=References] + +If you have references, use whatever suits you. A few sample references: +see \cite[knuth], or \cite[lamport]. + +\stopsection + +\startsection[title=References] + \placelistofpublications +\stopsection +\stopArticle +\stoptext -\endinput diff --git a/tex/context/modules/mkiv/x-pandoc.mkiv b/tex/context/modules/mkiv/x-pandoc.mkiv new file mode 100644 index 000000000..18bea9e7c --- /dev/null +++ b/tex/context/modules/mkiv/x-pandoc.mkiv @@ -0,0 +1,152 @@ +%D \module +%D [ file=m-pandoc, +%D version=2019.05.30, +%D title=\CONTEXT\ Extra Modules, +%D subtitle=Pandoc Docbook Rendering, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +% just a test + +\startxmlsetups xml:docbook:article + \xmlflush{#1} +\stopxmlsetups + +\startxmlsetups xml:docbook:section + \startsectionlevel[title={\xmltext{#1}{/title}},reference={\xmlatt{#1}{xml:id}}] + \xmlall{#1}{./!title} + \stopsectionlevel +\stopxmlsetups + +\startxmlsetups xml:docbook:para + \dontleavehmode\ignorespaces + \xmlflush{#1} + \removeunwantedspaces\par +\stopxmlsetups + +\startxmlsetups xml:docbook:emphasis + \dontleavehmode\begingroup + \em \xmlflush{#1} + \endgroup +\stopxmlsetups + +\startxmlsetups xml:docbook:literal + \doifelse {\xmlatt{#1}{class}} {math} { + % what kind of math? inline or display? + \starttexcode + \startimath + \xmlflush{#1} + \stopimath + \stoptexcode + } { + \dontleavehmode\begingroup + \tttf \xmlflush{#1} + % \xmlinlineverbatim{#1} + \endgroup + } +\stopxmlsetups + +\startxmlsetups xml:docbook:programlisting + \xmldisplayverbatim{#1} +\stopxmlsetups + +\startxmlsetups xml:docbook:link + \doifsomethingelse {\xmlatt{#1}{xlink:href}} { + \goto{\xmlflush{#1}}[url(\xmllastatt)] + } { + \doifsomethingelse {\xmlatt{#1}{linkend}} { + \in{\xmlflush{#1}}[\xmllastatt] + } { + \xmlflush{#1} + } + } +\stopxmlsetups + +\startxmlsetups xml:docbook:anchor + \pagereference[\xmlatt{id}] +\stopxmlsetups + +\startxmlsetups xml:docbook:itemizedlist + \doifelse {\xmlatt{#1}{spacing}} {compact} { + \startitemize[packed] + \xmlflush{#1} + \stopitemize + } { + \startitemize + \xmlflush{#1} + \stopitemize + } +\stopxmlsetups + +\startxmlsetups xml:docbook:orderedlist + \doifelse {\xmlatt{#1}{spacing}} {compact} { + \startitemize[n,packed] + \xmlflush{#1} + \stopitemize + } { + \startitemize[n] + \xmlflush{#1} + \stopitemize + } +\stopxmlsetups + +\startxmlsetups xml:docbook:listitem + \startitem + \xmlflush{#1} + \stopitem +\stopxmlsetups + +\startxmlsetups xml:docbook:variablelist + \startitemize + \xmlflush{#1} + \stopitemize +\stopxmlsetups + +\startxmlsetups xml:docbook:varlistentry + \xmlflush{#1} +\stopxmlsetups + +\startxmlsetups xml:docbook:term + \xmlflush{#1} +\stopxmlsetups + +\usemodule[cals] + +\startxmlsetups cals:table:before + \startlinecorrection +\stopxmlsetups + +\startxmlsetups cals:table:after + \stoplinecorrection +\stopxmlsetups + +\startxmlsetups xml:docbook + \xmlsetsetup {#1} {*} {xml:docbook:*} + \xmlsetfunction {#1} {informaltable} {moduledata.cals.table} +\stopxmlsetups + +\continueifinputfile{x-pandoc.mkiv} + +\usemodule[article-basic] + +\setupinteraction + [state=start] + +\setupalign + [flushleft,tolerant] + +\starttext + + % running: + % + % pandoc -s -t docbook5 pandoc.txt + + \xmlregisterdocumentsetup{main}{xml:docbook} + \xmlprocessfile{main}{d:/pandoc/pandoc.xml}{} + +\stoptext |