diff options
-rw-r--r-- | tex/context/base/core-con.lua | 2 | ||||
-rw-r--r-- | tex/context/base/m-markdown.lua | 29 | ||||
-rw-r--r-- | tex/context/base/m-markdown.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/mtx-context-arrange.tex | 8 | ||||
-rw-r--r-- | tex/context/base/mtx-context-markdown.tex | 92 | ||||
-rw-r--r-- | tex/context/base/ppchtex.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/status-files.pdf | bin | 23783 -> 23755 bytes | |||
-rw-r--r-- | tex/context/base/status-lua.pdf | bin | 162201 -> 162227 bytes | |||
-rw-r--r-- | tex/context/base/strc-lst.lua | 13 | ||||
-rw-r--r-- | tex/context/base/strc-not.mkiv | 63 | ||||
-rw-r--r-- | tex/context/base/syst-aux.lua | 17 | ||||
-rw-r--r-- | tex/context/base/syst-aux.mkiv | 87 |
12 files changed, 214 insertions, 101 deletions
diff --git a/tex/context/base/core-con.lua b/tex/context/base/core-con.lua index 8679b6b8e..46fc69eaa 100644 --- a/tex/context/base/core-con.lua +++ b/tex/context/base/core-con.lua @@ -298,7 +298,7 @@ local function toroman(n) if n >= 4000 then return toroman(floor(n/1000)) .. " " .. toroman(n%1000) else - return rep("M",floor(n/1000)) .. roman[3][floor((n%1000)/100)] .. roman[2][floor((n%100)/10)] .. roman[1][floor((n% 10)/1)] + return rep("M",floor(n/1000)) .. roman[3][floor((n%1000)/100)] .. roman[2][floor((n%100)/10)] .. roman[1][floor((n%10)/1)] end end diff --git a/tex/context/base/m-markdown.lua b/tex/context/base/m-markdown.lua index 552e046ef..bddc38280 100644 --- a/tex/context/base/m-markdown.lua +++ b/tex/context/base/m-markdown.lua @@ -53,10 +53,14 @@ local markdown = moduledata.markdown local nofruns, nofbytes, nofhtmlblobs = 0, 0, 0 local function process(func,t) - for i=1,#t do - t[i] = func(t[i]) + if func then + for i=1,#t do + t[i] = func(t[i]) + end + return t + else + return "ERROR: NO FUNCTION" end - return t end local function traverse_tree(t,buffer,n) @@ -183,6 +187,8 @@ local selfclosingblocktag = less * spnl * slash^-1 * blocktag * spnl * htmlat interblockspace = Cmt(blanklines, function(s,i) if i == 1 then return i, "" else return i, "\n" end end) +local nestedparser -- forward reference + -- helper stuff local escaped = { @@ -198,7 +204,7 @@ local escaped = { } for k, v in next, escaped do - escaped[k] = "\\char" .. utfbyte(k) .. " " + escaped[k] = "\\char" .. utfbyte(k) .. "{}" end local itemsignal = "\001" @@ -228,8 +234,8 @@ end local function listitem(c) return { "\\startitem\n", - process(parser, lpegmatch(itemsplitter,c)), - "\n\stopitem\n" + process(nestedparser, lpegmatch(itemsplitter,c) or c), + "\n\\stopitem\n" } end @@ -320,7 +326,7 @@ end local function c_blockquote(c) return { "\\startmarkdownblockquote\n", - parser(concat(c,"\n")), + nestedparser(concat(c,"\n")), "\\stopmarkdownblockquote\n" } end @@ -360,9 +366,9 @@ local function c_heading(level,c) if level > #levels then level = #levels end - local finish = concat(levels,"\n",level+1) or "" + local finish = concat(levels,"\n",level) or "" for i=level+1,#levels do - levels[level] = "" + levels[i] = "" end levels[level] = "\\stopstructurelevel" return { @@ -469,7 +475,8 @@ local function f_link(a) end local syntax -local nestedparser = function(inp) return to_string(lpegmatch(syntax,inp)) end + +nestedparser = function(inp) return to_string(lpegmatch(syntax,inp)) end syntax = { "Document", -- still rather close to the original but reformatted etc etc @@ -684,7 +691,7 @@ function markdown.typesetbuffer(name) end function markdown.typesetfile(name) - local fullname = findctxfile(name) + local fullname = resolvers.findctxfile(name) if fullname and fullname ~= "" then markdown.typesetstring(io.loaddata(fullname)) end diff --git a/tex/context/base/m-markdown.mkiv b/tex/context/base/m-markdown.mkiv index 71bc3442f..016e18ea2 100644 --- a/tex/context/base/m-markdown.mkiv +++ b/tex/context/base/m-markdown.mkiv @@ -2,7 +2,7 @@ %D [ file=x-markdown, %D version=2011.07.19, %D title=\CONTEXT\ Modules, -%D subtitle=processign MarkDown, +%D subtitle=Processing MarkDown, %D author=Hans Hagen, %D date=\currentdate, %D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] diff --git a/tex/context/base/mtx-context-arrange.tex b/tex/context/base/mtx-context-arrange.tex index 9ee0391b6..d1a01c699 100644 --- a/tex/context/base/mtx-context-arrange.tex +++ b/tex/context/base/mtx-context-arrange.tex @@ -33,7 +33,7 @@ [offset=\getdocumentargument{paperoffset}] } -\doifdocumentargumentelse {noduplex} {yes} { +\doifdocumentargumentelse {noduplex} { \setuppagenumbering [alternative=doublesided] \setdocumentargument{sided}{doublesided} @@ -41,9 +41,9 @@ \setdocumentargument{sided}{singlesided} } -\setdefaultdocumentargument {textwidth} {0cm} -\setdefaultdocumentargument {backspace} {0cm} -\setdefaultdocumentargument {topspace} {0cm} +\setdocumentargumentdefault {textwidth} {0cm} +\setdocumentargumentdefault {backspace} {0cm} +\setdocumentargumentdefault {topspace} {0cm} \setuplayout [backspace=\getdocumentargument{backspace}, diff --git a/tex/context/base/mtx-context-markdown.tex b/tex/context/base/mtx-context-markdown.tex new file mode 100644 index 000000000..1bd57945f --- /dev/null +++ b/tex/context/base/mtx-context-markdown.tex @@ -0,0 +1,92 @@ +%D \module +%D [ file=mtx-context-markdown, +%D version=2011.07.24, +%D title=\CONTEXT\ Extra Trickry, +%D subtitle=Rendering Markdown Files, +%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. + +% begin help +% +% usage: context --extra=markdown [options] list-of-files +% +% --sort : sort filenames first +% --paperoffset=dimension : left-top-offset +% --duplex : doublesided (singlesided is default) +% --backspace=dimension : extra left offset +% --topspace=dimension : extra top offset +% --bodyfont=specification : additional bodyfont specification +% --contents : add table of contents +% +% end help + +\usemodule[markdown] + +\doifdocumentargument {paperoffset} { + \definepapersize + [offset=\getdocumentargument{paperoffset}] +} + +\doifdocumentargument{duplex} { + \setuppagenumbering + [alternative=doublesided] +} { + \setuppagenumbering + [alternative=singlesided] +} + +\setdocumentargumentdefault {textwidth} {middle} +\setdocumentargumentdefault {backspace} {2cm} +\setdocumentargumentdefault {topspace} {2cm} +\setdocumentargumentdefault {bodyfont} {} + +\setuptolerance + [verytolerant,stretch] + +\setuplayout + [width=middle, + height=middle, + backspace=\getdocumentargument{backspace}, + topspace=\getdocumentargument{topspace}, + footer=0pt] + +\setupbodyfont + [dejavu,10pt,\getdocumentargument{bodyfont}] + +\setupwhitespace + [big] + +% \enabletrackers[context.trace] + +\setuplist + [chapter,section,subsection] + [aligntitle=yes, + width=4em] + +\starttext + +\doifdocumentargument{contents} { + \starttitle[title={Table of contents}] + \placelist[chapter,section,subsection] % todo: levels + \stoptitle +} + + +\startluacode + if #document.files > 0 then + if document.arguments.sort then + table.sort(document.files) + end + for i=1,#document.files do + context.processmarkdownfile(document.files[i]) + context.page() + end + end +\stopluacode + +\stoptext diff --git a/tex/context/base/ppchtex.mkiv b/tex/context/base/ppchtex.mkiv index 6fbba7666..c14e8edb1 100644 --- a/tex/context/base/ppchtex.mkiv +++ b/tex/context/base/ppchtex.mkiv @@ -1721,7 +1721,7 @@ \let\chemicaltwintiparrow = \chemicaltwintipouterarrow \fi \disablechemicalspecials - \unexpandedprocessallactionsinset + \processallactionsinset [#1] [ HIGH=>\sethighsubscripts, LOW=>\setlowsubscripts, diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex cb85368d5..5e3950fce 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex 01099d394..24525ddd3 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/strc-lst.lua b/tex/context/base/strc-lst.lua index edb036a5c..1e54eddec 100644 --- a/tex/context/base/strc-lst.lua +++ b/tex/context/base/strc-lst.lua @@ -475,12 +475,13 @@ function lists.userdata(name,r,tag) -- to tex (todo: xml) local userdata, metadata = result.userdata, result.metadata local str = userdata and userdata[tag] if str then - local catcodes = metadata and metadata.catcodes - if catcodes then - context.sprint(catcodes,str) - else - context(str) - end +--~ local catcodes = metadata and metadata.catcodes +--~ if catcodes then +--~ context.sprint(catcodes,str) +--~ else +--~ context(str) +--~ end + helpers.title(str,metadata) end end end diff --git a/tex/context/base/strc-not.mkiv b/tex/context/base/strc-not.mkiv index a9fbd670b..f309fdc29 100644 --- a/tex/context/base/strc-not.mkiv +++ b/tex/context/base/strc-not.mkiv @@ -338,33 +338,46 @@ \fi \dochecknote} -\appendtoks - \setvalue{\??vn\c!rule:c:\currentnote}{\normalnoterule}% hm - \letvalue{\??vn\c!rule:a:\currentnote}\v!left -\to \everysetupnote +\def\currentnoterulecommand{\csname\??vn\c!rule:c:\currentnote\endcsname} +\def\currentnoterulealign {\csname\??vn\c!rule:a:\currentnote\endcsname} + +\def\currentnoterulecommandnormal {\normalnoterule} % no let as it can be changed afterwards +\def\currentnoterulecommandunknown{\noteparameter\c!rule} + +\def\letcurrentnoterulecommand{\expandafter\let\csname\??vn\c!rule:c:\currentnote\endcsname} \appendtoks - \expanded{\processallactionsinset - [\noteparameter\c!rule]} - [ \v!on=>\setvalue{\??vn\c!rule:c:\currentnote}{\normalnoterule}, % no let as it can be changed afterwards - \v!normal=>\setvalue{\??vn\c!rule:c:\currentnote}{\normalnoterule}, - \v!left=>\setvalue{\??vn\c!rule:a:\currentnote}{l2r}, - \v!right=>\setvalue{\??vn\c!rule:a:\currentnote}{r2l}, - \v!off=>\letvalue{\??vn\c!rule:c:\currentnote}\relax, - \s!default=>\letvalue{\??vn\c!rule:c:\currentnote}\relax, - \s!unknown=>\setvalue{\??vn\c!rule:c:\currentnote}{\noteparameter\c!rule}]% + \letvalue{\??vn\c!rule:c:\currentnote}\currentnoterulecommandnormal + \letvalue{\??vn\c!rule:a:\currentnote}\lefttoright \to \everysetupnote \appendtoks - \processaction % todo (why doesnt it work for a global setting) - [\noteparameter\c!split] - [ \v!tolerant=>\notepenalty\zeropoint, - \v!strict=>\notepenalty9999, - \v!verystrict=>\notepenalty\maxdimen, - \s!default=>\notepenalty\zeropoint, - \s!unknown=>\notepenalty\commalistelement]% + \processallactionsinset[\noteparameter\c!rule] + [ \v!on=>\letcurrentnoterulecommand\currentnoterulecommandnormal, + \v!normal=>\letcurrentnoterulecommand\currentnoterulecommandnormal, + \v!left=>\letcurrentnoterulecommand\lefttoright, + \v!right=>\letcurrentnoterulecommand\righttoleft, + \v!off=>\letcurrentnoterulecommand\relax, + \s!default=>\letcurrentnoterulecommand\relax, + \s!unknown=>\letcurrentnoterulecommand\currentnoterulecommandunknown]% \to \everysetupnote +\def\currentnotepenalty + {\ifcsname\??vn\c!split:p:\noteparameter\c!split\endcsname + \csname\??vn\c!split:p:\noteparameter\c!split\endcsname + \else + \numexpr\noteparameter\c!split\relax + \fi} + +\setnewconstant\notepenaltytolerant \zerocount +\setnewconstant\notepenaltystrict 9999 +\setnewconstant\notepenaltyverystrict\maxdimen + +\letvalue{\??vn\c!split:p:\v!tolerant }\notepenaltytolerant +\letvalue{\??vn\c!split:p:\v!strict }\notepenaltystrict +\letvalue{\??vn\c!split:p:\v!verystrict}\notepenaltyverystrict +\letvalue{\??vn\c!split:p:\empty }\notepenaltytolerant + \appendtoks \edef\currentnotewidth{\noteparameter\c!width}% \ifx\currentnotewidth\empty @@ -531,9 +544,8 @@ \unexpanded\def\placenoterule {\bgroup - \setupalign[\getvalue{\??vn\c!rule:a:\currentnote}]% - \righttoleft - \getvalue{\??vn\c!rule:c:\currentnote}% + \currentnoterulealign + \currentnoterulecommand \par \egroup} @@ -855,9 +867,6 @@ \let\stoppushnote \relax \newsignal\notesignal -\newcount \notepenalty - -\notepenalty=0 % needed in order to split in otrset \newconditional\processingnote \newconditional\postponednote @@ -875,7 +884,7 @@ \appendtoks \doif{\noteparameter\c!scope}\v!page{\floatingpenalty\maxdimen}% experiment - \penalty\notepenalty + \penalty\currentnotepenalty \forgetall \setnotebodyfont \redoconvertfont % to undo \undo calls in in headings etc diff --git a/tex/context/base/syst-aux.lua b/tex/context/base/syst-aux.lua new file mode 100644 index 000000000..a585ed8b2 --- /dev/null +++ b/tex/context/base/syst-aux.lua @@ -0,0 +1,17 @@ +if not modules then modules = { } end modules ['syst-aux'] = { + version = 1.001, + comment = "companion to syst-aux.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +function commands.getfirstcharacter(str) + local first, rest = utf.match(str,"(.?)(.*)$") + context.setvalue("firstcharacter",first) + context.setvalue("remainingcharacters",rest) +end + +function commands.doiffirstcharelse(chr,str) + commands.doifelse(utf.sub(str,1,1) == chr) +end diff --git a/tex/context/base/syst-aux.mkiv b/tex/context/base/syst-aux.mkiv index 7016228c9..f9f604d14 100644 --- a/tex/context/base/syst-aux.mkiv +++ b/tex/context/base/syst-aux.mkiv @@ -15,6 +15,8 @@ %D obsolete once we've redone the bibliography module. Of course %D the handy helpers will stay. +\registerctxluafile{syst-aux}{1.001} + %D This is a stripped down combination of: %D %D \startitemize @@ -1070,6 +1072,10 @@ \newcount\processlevel +%D By default we expand actions: + +\def\expandactions{\let\expandedaction\edef} \expandactions % this command will go away + \def\p!compareprocessactionA[#1=>#2][#3]% {\edef\!!stringb{#1}% \ifx\!!stringb\s!default @@ -1185,35 +1191,35 @@ \global\advance\commalevel \minusone #2} -%D \macros -%D {unexpandedprocessaction, -%D unexpandedprocessfirstactioninset, -%D unexpandedprocessallactionsinset} -%D -%D Now what are those expansion commands doing there. Well, -%D sometimes we want to compare actions that may consist off -%D commands (i.e. are no constants). In such occasions we can -%D use the a bit slower alternatives: - -\def\unexpandedprocessfirstactioninset{\dontexpandactions\processfirstactioninset} -\def\unexpandedprocessaction {\dontexpandactions\processaction} -\def\unexpandedprocessallactionsinset {\dontexpandactions\processallactionsinset} - -%D By default we expand actions: - -\def\expandactions{\let\expandedaction\edef} \expandactions - -%D But when needed we convert the strings to meaningful -%D sequences of characters. - -\def\unexpandedaction#1>{} - -\def\noexpandedaction#1#2% - {\def\@@convertedargument{#2}% - \@EA\edef\@EA#1\@EA{\@EA\unexpandedaction\meaning\@@convertedargument}} - -\def\dontexpandactions - {\let\expandedaction\noexpandedaction} +% % THIS IS OBSOLETE (as is \expandedaction) +% +% %D \macros +% %D {unexpandedprocessaction, +% %D unexpandedprocessfirstactioninset, +% %D unexpandedprocessallactionsinset} +% %D +% %D Now what are those expansion commands doing there. Well, +% %D sometimes we want to compare actions that may consist off +% %D commands (i.e. are no constants). In such occasions we can +% %D use the a bit slower alternatives: +% +% \def\unexpandedprocessfirstactioninset{\dontexpandactions\processfirstactioninset} +% \def\unexpandedprocessaction {\dontexpandactions\processaction} +% \def\unexpandedprocessallactionsinset {\dontexpandactions\processallactionsinset} +% +% %D But when needed we convert the strings to meaningful +% %D sequences of characters. [THIS CAN GO] +% +% \def\unexpandedaction#1>{} +% +% \def\noexpandedaction#1#2% +% {\def\@@convertedargument{#2}% +% \@EA\edef\@EA#1\@EA{\@EA\unexpandedaction\meaning\@@convertedargument}} +% +% \def\dontexpandactions +% {\let\expandedaction\noexpandedaction} +% +% % TILL HERE %D \macros %D {getfirstcharacter, firstcharacter, remainingcharacters, doiffirstcharacter} @@ -1230,27 +1236,8 @@ %D complicated arguments, for instance arguments that %D consist of two or more expandable tokens. -\def\dogetfirstcharacter#1#2\relax - {\def\firstcharacter{#1}% - \def\remainingcharacters{#2}} - -\def\getfirstcharacter#1% - {\edef\!!stringa{#1}% - \expandafter\dogetfirstcharacter\!!stringa\relax} - -\def\doiffirstcharelse#1#2% char string -% kort (maar onleesbaar) -% {\expanded{\dogetfirstcharacter#2}\\\doifelse{#1}\firstcharacter} -% korter (en begrijpelijk)) - {\getfirstcharacter{#2}\doifelse{#1}\firstcharacter} -% snel (maar zelden gebruikt, dus niet zo belangrijk) -% {\getfirstcharacter{#2}% -% \edef\!!stringa{#1}% -% \ifx\!!stringa\firstcharacter -% \expandafter\firstoftwoarguments -% \else -% \expandafter\secondoftwoarguments -% \fi} +\def\getfirstcharacter #1{\ctxcommand{getfirstcharacter(\!!bs#1\e!!es)}} +\def\doiffirstcharelse#1#2{\ctxcommand{doiffirstcharelse(\!!bs#1\e!!es,\!!bs#2\e!!es)}} % chr str %D \macros %D {doifinstringelse, doifincsnameelse} |