Skip to content

Commit

Permalink
Implement \setupmarkdown and \inputmarkdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Witiko committed Aug 26, 2022
1 parent 0fc7501 commit 4ddada4
Showing 1 changed file with 171 additions and 27 deletions.
198 changes: 171 additions & 27 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -15435,11 +15435,11 @@ pdflatex --shell-escape document.tex
% \begin{markdown}
%
% The \LaTeX{} interface provides \LaTeX{} environments for the typesetting of
% markdown input from within \LaTeX{}, facilities for setting Lua interface
% options (see Section <#sec:luaoptions>) used during the conversion from
% markdown to plain \TeX{}, and facilities for changing the way markdown tokens
% are rendered. The rest of the interface is inherited from the plain \TeX{}
% interface (see Section <#sec:texinterface>).
% markdown input from within \LaTeX{}, facilities for setting Lua, plain \TeX,
% and \LaTeX{} options used during the conversion from markdown to plain
% \TeX{}, and facilities for changing the way markdown tokens are rendered. The
% rest of the interface is inherited from the plain \TeX{} interface (see
% Section <#sec:texinterface>).
%
% The \LaTeX{} implementation redefines the plain \TeX{} logging macros (see
% Section <#sec:texinterfacelogging>) to use the \LaTeX{} \mref{PackageInfo},
Expand Down Expand Up @@ -16216,7 +16216,7 @@ The following ordered list will be preceded by roman numerals:
% \begin{markdown}
%
% Furthermore, we also define the \meta{key}`=`\meta{value} interface
% for all option macros recognized by the Lua plain \TeX{} interfaces.
% for all option macros recognized by the Lua and plain \TeX{} interfaces.
%
% \end{markdown}
% \begin{macrocode}
Expand Down Expand Up @@ -16464,7 +16464,7 @@ The following ordered list will be preceded by roman numerals:
The \Hologo{ConTeXt} interface provides the same level of functionality as the
plain \TeX{} interface by using the plain \TeX{} interface behind the scenes.
Unlike the plain \TeX{} interface, the \Hologo{ConTeXt} interface uses familiar
\Hologo{ConTeXt} idioms, such as environments.
\Hologo{ConTeXt} idioms as syntactic sugar.

The \Hologo{ConTeXt} interface accepts the same options as the plain \TeX{}
interface.
Expand All @@ -16479,7 +16479,7 @@ following content:
$\sqrt{-1}$ *equals* $i$.
\stopmarkdown

\def\markdownOptionHybrid{true}
\setupmarkdown[hybrid = yes]
\startmarkdown
$\sqrt{-1}$ *equals* $i$.
\stopmarkdown
Expand Down Expand Up @@ -16507,9 +16507,10 @@ texexec --passon=--shell-escape document.tex
% \fi
%
% The \Hologo{ConTeXt} interface provides a start-stop macro pair for the
% typesetting of markdown input from within \Hologo{ConTeXt}. The rest of the
% interface is inherited from the plain \TeX{} interface (see Section
% <#sec:texinterface>).
% typesetting of markdown input from within \Hologo{ConTeXt} and facilities for
% setting Lua, plain \TeX, and \Hologo{ConTeXt} options used during the
% conversion from markdown to plain \TeX{}. The rest of the interface is
% inherited from the plain \TeX{} interface (see Section <#sec:texinterface>).
%
% \end{markdown}
% \begin{macrocode}
Expand All @@ -16520,6 +16521,21 @@ texexec --passon=--shell-escape document.tex
% \par
% \begin{markdown}
%
% The \Hologo{ConTeXt} implementation redefines the plain \TeX{} logging macros
% (see Section <#sec:texinterfacelogging>) to use the \Hologo{ConTeXt}
% \mref{writestatus} macro.
%
% \end{markdown}
% \begin{macrocode}
\def\markdownInfo#1{\writestatus{markdown}{#1.}}%
\def\markdownWarning#1{\writestatus{markdown\space warn}{#1.}}%
\def\dospecials{\do\ \do\\\do\{\do\}\do\$\do\&%
\do\#\do\^\do\_\do\%\do\~}%
\input markdown/markdown
% \end{macrocode}
% \par
% \begin{markdown}
%
% The \Hologo{ConTeXt} interface is implemented by the
% `t-markdown.tex` \Hologo{ConTeXt} module file that can be loaded as follows:
% ``` tex
Expand All @@ -16530,12 +16546,14 @@ texexec --passon=--shell-escape document.tex
%
%### Typesetting Markdown
% The interface exposes the \mdef{startmarkdown} and \mdef{stopmarkdown} macro
% pair for the typesetting of a markdown document fragment.
% pair for the typesetting of a markdown document fragment, and defines the
% \mdef{inputmarkdown} command.
%
% \end{markdown}
% \begin{macrocode}
\let\startmarkdown\relax
\let\stopmarkdown\relax
\let\inputmarkdown\relax
% \end{macrocode}
% \par
% \begin{markdown}
Expand All @@ -16559,6 +16577,127 @@ texexec --passon=--shell-escape document.tex
% \stoptext
% ```````
%
% The \mref{inputmarkdown} macro accepts a single mandatory parameter
% containing the filename of a markdown document and expands to the result of
% the conversion of the input markdown document to plain \TeX{}. Unlike the
% \mref{markdownInput} macro provided by the plain \TeX{} interface, this macro
% also accepts \Hologo{ConTeXt} interface options (see Section
% <#sec:contextoptions>) as its optional argument. These options will only
% influnce this markdown document.
%
% The following example \LaTeX{} code showcases the usage of the
% \mref{markdownInput} macro:
% ``` tex
% \usemodule[t][markdown]
% \starttext
% % ...
% \inputmarkdown[smartEllipses]{hello.md}
% % ...
% \stoptext
% ```````
%
%### Options {#contextoptions}
%
% The \Hologo{ConTeXt} options are represented by a comma-delimited list of
% \meta{key}`=`\meta{value} pairs. For boolean options, the `=`\meta{value}
% part is optional, and \meta{key} will be interpreted as \meta{key}`=true`
% (or, equivalently, \meta{key}`=yes`) if the `=`\meta{value} part has been
% omitted.
%
% \Hologo{ConTeXt} options map directly to the options recognized by the plain
% \TeX{} interface (see Section <#sec:texoptions>).
%
% The \Hologo{ConTeXt} options may be specified when using the
% \mref{inputmarkdown} macro (see Section <#sec:contextinterface>), or via the
% \mdef{setupmarkdown} macro. The \mref{setupmarkdown} macro receives the
% options to set up as its only argument:
%
% \end{markdown}
% \begin{macrocode}
\ExplSyntaxOn
\cs_new:Nn
\@@_setup:n
{
\keys_set:nn
{ markdown/context-options }
{ #1 }
}
\long\def\setupmarkdown[#1]
{
\@@_setup:n
{ #1 }
}
\ExplSyntaxOff
% \end{macrocode}
% \begin{markdown}
%
%#### \Hologo{ConTeXt} Interface Options
% We define the \meta{key}`=`\meta{value} interface for all option macros
% recognized by the Lua and plain \TeX{} interfaces.
%
% \end{markdown}
% \begin{macrocode}
\ExplSyntaxOn
\cs_new:Nn \@@_context_define_option_commands_and_keyvals:
{
\seq_map_inline:Nn
\g_@@_option_layers_seq
{
\seq_map_inline:cn
{ g_@@_ ##1 _options_seq }
{
\@@_context_define_option_keyval:nn
{ ##1 }
{ ####1 }
}
}
}
\cs_new:Nn \@@_context_define_option_keyval:nn
{
\prop_get:cnN
{ g_@@_ #1 _option_types_prop }
{ #2 }
\l_tmpa_tl
\keys_define:nn
{ markdown/context-options }
{
#2 .code:n = {
\tl_set:Nx
\l_tmpa_tl
{
\str_case:nnF
{ ##1 }
{
{ yes } { true }
{ no } { false }
}
{ ##1 }
}
\@@_set_option_value:nV
{ #2 }
\l_tmpa_tl
},
}
\str_if_eq:VVT
\l_tmpa_tl
\c_@@_option_type_boolean_tl
{
\keys_define:nn
{ markdown/context-options }
{
#2 .default:n = { true },
}
}
}
\cs_generate_variant:Nn
\@@_set_option_value:nn
{ nV }
\@@_context_define_option_commands_and_keyvals:
\ExplSyntaxOff
% \end{macrocode}
% \par
% \begin{markdown}
%
% Implementation {#implementation}
%================
%
Expand Down Expand Up @@ -25303,21 +25442,6 @@ end
% consequence, we can directly reuse the existing plain \TeX{} implementation
% after supplying the missing plain \TeX{} macros.
%
% The \Hologo{ConTeXt} implementation redefines the plain \TeX{} logging macros
% (see Section <#sec:texinterfacelogging>) to use the \Hologo{ConTeXt}
% \mref{writestatus} macro.
%
% \end{markdown}
% \begin{macrocode}
\def\markdownInfo#1{\writestatus{markdown}{#1.}}%
\def\markdownWarning#1{\writestatus{markdown\space warn}{#1.}}%
\def\dospecials{\do\ \do\\\do\{\do\}\do\$\do\&%
\do\#\do\^\do\_\do\%\do\~}%
\input markdown/markdown
% \end{macrocode}
% \par
% \begin{markdown}
%
% When buffering user input, we should disable the bytes with the high bit set,
% since these are made active by the \mref{enableregime} macro. We will do this
% by redefining the \mref{markdownMakeOther} macro accordingly. The code is
Expand Down Expand Up @@ -25347,6 +25471,26 @@ end
% \begin{markdown}
%
%### Typesetting Markdown
% The \mref{inputmarkdown} is defined to accept an optional argument with
% options recognized by the \Hologo{ConTeXt} interface (see Section
% <#sec:contextoptions>).
%
% \end{markdown}
% \begin{macrocode}
\long\def\inputmarkdown{%
\dosingleempty
\doinputmarkdown}%
\long\def\doinputmarkdown[#1]#2{%
\begingroup
\iffirstargument
\setupmarkdown{#1}%
\fi
\markdownInput{#2}%
\endgroup}%
% \end{macrocode}
% \par
% \begin{markdown}
%
% The \mref{startmarkdown} and \mref{stopmarkdown} macros are implemented using the
% \mref{markdownReadAndConvert} macro.
%
Expand Down

0 comments on commit 4ddada4

Please sign in to comment.