Skip to content

Commit

Permalink
Merge branch 'feature/inline_html_tag' into main
Browse files Browse the repository at this point in the history
Progresses #90
  • Loading branch information
Witiko committed Feb 10, 2022
2 parents 4ac9640 + e5e28ed commit 94b9c92
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 7 deletions.
81 changes: 78 additions & 3 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -11926,6 +11926,62 @@ The horizontal margins should contain the following text:
%
% \begin{markdown}

#### Inline HTML Tag Renderer
The \mdef{markdownRendererInlineHtmlTag} macro represents the contents of an
opening, closing, or empty inline \acro{HTML} tag. This macro will only be
produced, when the \Opt{html} option is enabled. The macro receives a single
argument that corresponds to the contents of the \acro{HTML} tag.

% \end{markdown}
%
% \iffalse

##### \LaTeX{} Example {.unnumbered}

Using a text editor, create a text document named `document.tex` with the
following content:
``` tex
\documentclass{article}
\usepackage[html]{markdown}
\usepackage{marginnote}
\markdownSetup{
renderers = {
inlineHtmlTag = {\textbf{#1}},
},
}
\begin{document}
\begin{markdown}
<b>Hello, world!</b><br/>
\end{markdown}
\end{document}
```````
Next, invoke LuaTeX from the terminal:
``` sh
lualatex document.tex
lualatex document.tex
``````
A PDF document named `document.pdf` should be produced and contain the
following body text:

> **<b>**Hello, world!**</b><br/>**

%</manual-tokens>
%<*tex>
% \fi
%
% \begin{macrocode}
\def\markdownRendererInlineHtmlTag{%
\markdownRendererInlineHtmlTagPrototype}%
% \end{macrocode}
% \par
%
% \iffalse
%</tex>
%<*manual-tokens>
% \fi
%
% \begin{markdown}

### Token Renderer Prototypes

% \label{sec:texrendererprototypes}
Expand Down Expand Up @@ -12129,6 +12185,7 @@ following text:
\def\markdownRendererTextCitePrototype#1{}%
\def\markdownRendererTablePrototype#1#2#3{}%
\def\markdownRendererInlineHtmlCommentPrototype#1{}%
\def\markdownRendererInlineHtmlTagPrototype#1{}%
\def\markdownRendererTickedBoxPrototype{}%
\def\markdownRendererHalfTickedBoxPrototype{}%
\def\markdownRendererUntickedBoxPrototype{}%
Expand Down Expand Up @@ -13258,6 +13315,8 @@ The following ordered list will be preceded by roman numerals:
\renewcommand\markdownRendererTable[3]{#1}}%
\define@key{markdownRenderers}{inlineHtmlComment}{%
\renewcommand\markdownRendererInlineHtmlComment[1]{#1}}%
\define@key{markdownRenderers}{inlineHtmlTag}{%
\renewcommand\markdownRendererInlineHtmlTag[1]{#1}}%
\define@key{markdownRenderers}{tickedBox}{%
\renewcommand\markdownRendererTickedBox{#1}}%
\define@key{markdownRenderers}{halfTickedBox}{%
Expand Down Expand Up @@ -13433,6 +13492,8 @@ The following ordered list will be preceded by roman numerals:
\renewcommand\markdownRendererTablePrototype[3]{#1}}%
\define@key{markdownRendererPrototypes}{inlineHtmlComment}{%
\renewcommand\markdownRendererInlineHtmlCommentPrototype[1]{#1}}%
\define@key{markdownRendererPrototypes}{inlineHtmlTag}{%
\renewcommand\markdownRendererInlineHtmlCommentTag[1]{#1}}%
\define@key{markdownRendererPrototypes}{tickedBox}{%
\renewcommand\markdownRendererTickedBoxPrototype{#1}}%
\define@key{markdownRendererPrototypes}{halfTickedBox}{%
Expand Down Expand Up @@ -16542,6 +16603,20 @@ function M.writer.new(options)
% \par
% \begin{markdown}
%
% Define \luamdef{writer->inline_html_tag} as a function that will
% transform the contents of an opening, closing, or empty inline \acro{HTML}
% tag to the output format, where `contents` are the contents of the
% \acro{HTML} tag.
%
% \end{markdown}
% \begin{macrocode}
function self.inline_html_tag(contents)
return {"\\markdownRendererInlineHtmlTag{",self.string(contents),"}"}
end
% \end{macrocode}
% \par
% \begin{markdown}
%
% Define \luamdef{writer->definitionlist} as a function that will transform an
% input definition list to the output format, where `items` is an array of
% tables, each of the form `{ term = t, definitions = defs }`, where `t`
Expand Down Expand Up @@ -18413,12 +18488,12 @@ larsers.PipeTable = Ct(larsers.table_row * parsers.newline

larsers.EscapedChar = parsers.backslash * C(parsers.escapable) / writer.string

larsers.InlineHtml = parsers.emptyelt_any
larsers.InlineHtml = parsers.emptyelt_any / writer.inline_html_tag
+ (parsers.htmlcomment / parse_inlines_no_html)
/ writer.inline_html_comment
+ parsers.htmlinstruction
+ parsers.openelt_any
+ parsers.closeelt_any
+ parsers.openelt_any / writer.inline_html_tag
+ parsers.closeelt_any / writer.inline_html_tag

larsers.HtmlEntity = parsers.hexentity / entities.hex_entity / writer.string
+ parsers.decentity / entities.dec_entity / writer.string
Expand Down
2 changes: 2 additions & 0 deletions tests/support/markdownthemewitiko_markdown_test.sty
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@
\TABLE{#1}{#2}{#3}},
inlineHtmlComment = {%
\TYPE{inlineHtmlComment: #1}},
inlineHtmlTag = {%
\TYPE{inlineHtmlTag: #1}},
tickedBox = {%
\TYPE{tickedBox}%
\GOBBLE},
Expand Down
2 changes: 2 additions & 0 deletions tests/support/plain-setup.tex
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@
\TABLE{#1}{#2}{#3}}%
\def\markdownRendererInlineHtmlComment#1{%
\TYPE{inlineHtmlComment: #1}}%
\def\markdownRendererInlineHtmlTag#1{%
\TYPE{inlineHtmlTag: #1}}%
\def\markdownRendererTickedBox#1{%
\TYPE{tickedBox}}%
\def\markdownRendererHalfTickedBox#1{%
Expand Down
4 changes: 2 additions & 2 deletions tests/testfiles/lunamark-markdown/html.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ the plain TeX interface.
<div>
*There is block tag support.*
</div>
*There is <inline tag="value"></inline> support.*
*There is <inline tag="value"></inline> support.<br/>*
_There is <!-- *comment* --> support._
_There is <? *HTML instruction* ?> support._

Expand All @@ -25,7 +25,7 @@ documentBegin
codeSpan: html
interblockSeparator
interblockSeparator
emphasis: There is support.
emphasis: There is (inlineHtmlTag: <inline tag="value">)(inlineHtmlTag: </inline>) support.(inlineHtmlTag: <br/>)
emphasis: There is (inlineHtmlComment: (emphasis: comment)) support.
emphasis: There is support.
interblockSeparator
Expand Down
4 changes: 2 additions & 2 deletions tests/testfiles/lunamark-markdown/no-html.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This test ensures that the Lua `html` option is disabled by default.
<div>
*There is no block tag support.*
</div>
*There is no <inline tag="tag"></inline> support.*
*There is <inline tag="value"></inline> support.<br/>*
_There is no <!-- comment --> support._
_There is no <? HTML instruction ?> support._

Expand All @@ -23,7 +23,7 @@ documentBegin
codeSpan: html
interblockSeparator
emphasis: There is no block tag support.
emphasis: There is no <inline tag="tag"></inline> support.
emphasis: There is <inline tag="value"></inline> support.<br/>
emphasis: There is no <!-- comment --> support.
emphasis: There is no <? HTML instruction ?> support.
interblockSeparator
Expand Down

0 comments on commit 94b9c92

Please sign in to comment.