Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contentType Lua option #400

Merged
merged 6 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Development:
`witiko/markdown/defaults`. (#391, #392)
- Add format-independent options `noDefaults` and `plain`, which control the
loading of theme `witiko/markdown/defaults`. (#393, #394)
- Add `contentLevel` Lua option.
(#300, #375, #400, contributed by @lostenderman)

Default Renderer Prototypes:

Expand Down
146 changes: 146 additions & 0 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -5209,6 +5209,143 @@ defaultOptions.contentBlocks = false
%</lua,lua-cli>
%<*manual-options>

#### Option `contentType`

`contentType` (default value: `block`)

% \fi
% \begin{markdown}
%
% \Optitem[block]{contentType}{\opt{block}, \opt{inline}}
%
: block

: Treat content as a sequence of blocks.
``` md
- this is a list
- it contains two items
``````

: inline

: Treat all content as inline content.
``` md
- this is a text
- not a list
``````

% \end{markdown}
% \iffalse

##### Plain \TeX{} Example {.unnumbered}

Using a text editor, create a text document named `document.tex` with the
following content:
``` tex
\input markdown
\def\markdownOptionContentType{inline}
\markdownBegin
- this is
- a text
\markdownEnd
\bye
```````
Next, invoke LuaTeX from the terminal:
``` sh
luatex document.tex
``````
A PDF document named `document.pdf` should be produced and contain the
following text:

> \- this is - a text

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

Using a text editor, create a text document named `document.tex` with the
following content:
``` tex
\documentclass{article}
\usepackage{markdown}
\begin{document}

\begin{markdown}
- this is
- a list
\end{markdown}

\begin{markdown}[contentType=inline]
- this is
- a text
\end{markdown}

\end{document}
```````
Next, invoke LuaTeX from the terminal:
``` sh
lualatex document.tex
``````
A PDF document named `document.pdf` should be produced and contain the
following text:

> - this is
> - a list
>
> \- this is - a text

##### \Hologo{ConTeXt} Example {.unnumbered}

Using a text editor, create a text document named `document.tex` with the
following content:
``` tex
\usemodule[t][markdown]
\starttext

\startmarkdown
- this is
- a list
\stopmarkdown

\setupmarkdown[contentType = inline]
\startmarkdown
- this is
- a text
\stopmarkdown

\stoptext
````````
Next, invoke LuaTeX from the terminal:
``` sh
context --luatex document.tex
`````
A PDF document named `document.pdf` should be produced and contain the
following text:

> - this is
> - a list
>
> \- this is - a text

%</manual-options>
%<*tex>
% \fi
% \begin{macrocode}
\@@_add_lua_option:nnn
{ contentType }
{ string }
{ block }
% \end{macrocode}
% \iffalse
%</tex>
%<*lua,lua-cli>
% \fi
% \begin{macrocode}
defaultOptions.contentType = "block"
% \end{macrocode}
% \par
% \iffalse
%</lua,lua-cli>
%<*manual-options>

#### Option `debugExtensions`

`debugExtensions` (default value: `false`)
Expand Down Expand Up @@ -29299,6 +29436,15 @@ end
syntax.AutoLinkRelativeReference = parsers.fail
end

if options.contentType == "inline" then
syntax[1] = "Inlines"
syntax.Inlines = V("InitializeState")
* parsers.Inline^0
* ( parsers.spacing^0
* parsers.eof / "")
syntax.Space = parsers.Space + parsers.blankline / writer.space
end

local blocks_nested_t = util.table_copy(syntax)
blocks_nested_t.ExpectedJekyllData = parsers.fail
parsers.blocks_nested = Ct(blocks_nested_t)
Expand Down
86 changes: 86 additions & 0 deletions tests/testfiles/lunamark-markdown/content-type-block.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
\markdownSetup{contentType=block}
<<<
This test ensures that the Lua `contentType` option correctly propagates
through the plain TeX interface. Setting the `contentType` option to the
default value `block` should have no effect.

Here are some inline elements:

- *emphasis* and __strong emphasis__
- [link](https://example/url "Example title")
- ![image](https://example/url "Example title")
- `code`

Here are some block elements:

- > blockquote
- code

block
-
* bullet
* list
-
1. ordered
2. list
>>>
BEGIN document
codeSpan: contentType
softLineBreak
codeSpan: contentType
softLineBreak
codeSpan: block
paragraphSeparator
interblockSeparator
ulBeginTight
ulItem
emphasis: emphasis
strongEmphasis: strong emphasis
ulItemEnd
ulItem
BEGIN link
- label: link
- URI: https://example/url
- title: Example title
END link
ulItemEnd
ulItem
BEGIN image
- label: image
- URI: https://example/url
- title: Example title
END image
ulItemEnd
ulItem
codeSpan: code
ulItemEnd
ulEndTight
interblockSeparator
interblockSeparator
ulBegin
ulItem
blockQuoteBegin
blockQuoteEnd
ulItemEnd
ulItem
interblockSeparator
inputVerbatim: ./_markdown_test/14511f2f5564650d129ca7cabc333278.verbatim
ulItemEnd
ulItem
ulBeginTight
ulItem
ulItemEnd
ulItem
ulItemEnd
ulEndTight
ulItemEnd
ulItem
olBeginTight
olItemWithNumber: 1
olItemEnd
olItemWithNumber: 2
olItemEnd
olEndTight
ulItemEnd
ulEnd
END document
47 changes: 47 additions & 0 deletions tests/testfiles/lunamark-markdown/content-type-inline.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
\markdownSetup{contentType=inline}
<<<
This test ensures that the Lua `contentType` option correctly propagates
through the plain TeX interface. Setting the `contentType` option to the
`inline` value should disable the part of the markdown grammar that deals
with block elements. Instead of separating blocks and paragraphs, blank
lines should translate to spaces, lists and blockquotes should just be
understood as plain text.

Here are some inline elements:

- *emphasis* and __strong emphasis__
- [link](https://example/url "Example title")
- ![image](https://example/url "Example title")
- `code`

Here are some block elements:

- > blockquote
- code

block
-
* bullet
* list
-
1. ordered
2. list
>>>
BEGIN document
codeSpan: contentType
codeSpan: contentType
codeSpan: inline
emphasis: emphasis
strongEmphasis: strong emphasis
BEGIN link
- label: link
- URI: https://example/url
- title: Example title
END link
BEGIN image
- label: image
- URI: https://example/url
- title: Example title
END image
codeSpan: code
END document
Loading