Skip to content

Commit

Permalink
Merge pull request #532 from Witiko/feat/luaxml
Browse files Browse the repository at this point in the history
Use package `luaxml` for default LaTeX renderer prototypes
  • Loading branch information
Witiko authored Nov 21, 2024
2 parents 88a06a2 + a1d9f12 commit bf72f36
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 6 deletions.
34 changes: 32 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Fixes:

Defaults:

- Define LaTeX renderers for table identifiers.
- Define default LaTeX renderer prototypes for table identifiers.
(#525, suggested by @machitgarha, #528)

This establishes a reliable method for authors to reference tables within
Expand Down Expand Up @@ -77,7 +77,7 @@ Defaults:
\end{document}
```

- Define LaTeX renderers for bracketed spans.
- Define default LaTeX renderer prototypes for bracketed spans.
(discussed with @MacLotsen at TUG 2024 and with @TeXhackse at matrix.org, #528)

This establishes a reliable method for authors to reference the last LaTeX
Expand Down Expand Up @@ -105,6 +105,36 @@ Defaults:
\end{document}
```

- Use package LuaXML in default LaTeX renderer prototypes for content blocks,
raw blocks, and inline raw spans. (#469, #532, co-authored by @michal.h21)

This allows authors to render HTML fragments in their LaTeX documents:

``` tex
\documentclass{article}
\usepackage[content_blocks, raw_attribute]{markdown}
\begin{filecontents}[overwrite, nosearch, noheader]{example_input.html}
<b>foo</b> <i>bar</i>
\end{filecontents}
\begin{document}
\begin{markdown}
Raw text span: `<b>foo</b> <i>bar</i>`{=html}
Raw code block:
``` {=html}
<b>foo</b> <i>bar</i>
```

Content block:

/example_input.html

\end{markdown}
\end{document}
```
Deprecation:
- Remove support for TeX Live 2022. (da85e015, 8f2d25c7)
Expand Down
140 changes: 136 additions & 4 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,17 @@ soft ltxcmds
% \end{macrocode}
% \begin{markdown}
%
% \pkg{luaxml}
%
%: A package that is used to convert \acro{HTML} to \LaTeX{} in the default
% renderer prototypes for content blocks, raw blocks, and inline raw spans.
%
% \end{markdown}
% \begin{macrocode}
soft luaxml
% \end{macrocode}
% \begin{markdown}
%
% \pkg{verse}
%
%: A package that is used in the default renderer prototypes for
Expand Down Expand Up @@ -37812,6 +37823,19 @@ end
\texttt{#1}%
\fi
}}}
% \end{macrocode}
% \begin{markdown}
%
%#### Content Blocks
%
% In content block renderer prototypes, display the content as a table using
% the package \pkg{csvsimple} when the raw attribute is `csv`, display the
% content using the default templates of the package \pkg{luaxml} when the
% raw attribute is `html`, execute the content with TeX when the raw attribute
% is `tex`, and display the content as markdown otherwise.
%
% \end{markdown}
% \begin{macrocode}
\ExplSyntaxOn
\markdownSetup{
rendererPrototypes = {
Expand All @@ -37830,9 +37854,45 @@ end
{ \caption{#4} }
\end{table}
}
{ tex } { \markdownEscape{#3} }
{ html }
{
% \end{macrocode}
% \begin{markdown}
%
% If we are using [\TeX{}4ht][1], we will pass HTML elements to the
% output HTML document unchanged.
%
% [1]: https://tug.org/tex4ht/
%
% \end{markdown}
% \begin{macrocode}
\cs_if_exist:NTF
\HCode
{
\if_mode_vertical:
\IgnorePar
\fi:
\EndP
\special
{ t4ht* < #3 }
\par
\ShowPar
}
{
\@@_luaxml_print_html:n
{ #3 }
}
}
{ tex }
{
\markdownEscape
{ #3 }
}
}
{
\markdownInput
{ #3 }
}
{ \markdownInput{#3} }
},
},
}
Expand Down Expand Up @@ -38825,12 +38885,28 @@ end
%
%#### Raw Attributes
%
% In the raw block and inline raw span renderer prototypes, default to the
% plain TeX renderer prototypes, translating raw attribute `latex` to `tex`.
% In the raw block and inline raw span renderer prototypes, display the content
% using the default templates of the package \pkg{luaxml} when the raw
% attribute is `html` and default to the plain TeX renderer prototypes
% otherwise, translating raw attribute `latex` to `tex`.
%
% \end{markdown}
% \begin{macrocode}
\ExplSyntaxOn
\cs_new:Nn
\@@_luaxml_print_html:n
{
\luabridge_now:n
{
local~input_file = assert(io.open(" #1 ", "r"))
local~input = assert(input_file:read("*a"))
assert(input_file:close())
input = "<body>" .. input .. "</body>"
local~dom = require("luaxml-domobject").html_parse(input)
local~output = require("luaxml-htmltemplates"):process_dom(dom)
print(output)
}
}
\cs_gset_protected:Npn
\markdownRendererInputRawInlinePrototype#1#2
{
Expand All @@ -38843,6 +38919,33 @@ end
{ #1 }
{ tex }
}
{ html }
{
% \end{macrocode}
% \begin{markdown}
%
% If we are using [\TeX{}4ht][1], we will pass HTML elements to the
% output HTML document unchanged.
%
% [1]: https://tug.org/tex4ht/
%
% \end{markdown}
% \begin{macrocode}
\cs_if_exist:NTF
\HCode
{
\if_mode_vertical:
\IgnorePar
\EndP
\fi:
\special
{ t4ht* < #1 }
}
{
\@@_luaxml_print_html:n
{ #1 }
}
}
}
{
\@@_plain_tex_default_input_raw_inline:nn
Expand All @@ -38862,6 +38965,35 @@ end
{ #1 }
{ tex }
}
{ html }
{
% \end{macrocode}
% \begin{markdown}
%
% If we are using [\TeX{}4ht][1], we will pass HTML elements to the
% output HTML document unchanged.
%
% [1]: https://tug.org/tex4ht/
%
% \end{markdown}
% \begin{macrocode}
\cs_if_exist:NTF
\HCode
{
\if_mode_vertical:
\IgnorePar
\fi:
\EndP
\special
{ t4ht* < #1 }
\par
\ShowPar
}
{
\@@_luaxml_print_html:n
{ #1 }
}
}
}
{
\@@_plain_tex_default_input_raw_block:nn
Expand Down

0 comments on commit bf72f36

Please sign in to comment.