Skip to content

Commit

Permalink
Merge pull request #198 from Witiko/feature/accept-snake-case-in-lua-cli
Browse files Browse the repository at this point in the history
Accept snake_case variants of options in Lua CLI
  • Loading branch information
Witiko authored Oct 8, 2022
2 parents 1f74a40 + 0bd73cf commit 2075a94
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 33 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Development:

- Accept snake\_case variants of options in addition to camelCase variants in
`\markdownSetup`. Accept snake\_case and caseless variants of options in
`\setupmarkdown`. (#193, #194, #195, #197)
`\markdownSetup` and Lua CLI. Accept snake\_case and caseless variants of
options in `\setupmarkdown`. (#193, #194, #195, #196, #197, #198)

## 2.17.1 (2022-10-03)

Expand Down
22 changes: 17 additions & 5 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@ AUXFILES=*.tmp *.tui *.tuo *.mp *.tuc *.markdown.in *.markdown.out \
latex-pdftex.tex latex-xetex.tex latex-luatex.tex latex-tex4ht.tex \
example.tex *.debug-extensions.json debug-extensions.json
AUXDIRS=_markdown_*/
LUACLI_OPTIONS=cacheDir=_markdown_example hashEnumerators=true \
definitionLists=true footnotes=true inlineFootnotes=true \
smartEllipses=true fencedCode=true contentBlocks=true pipeTables=true \
tableCaptions=true taskLists=true strikeThrough=true superscripts=true \
subscripts=true fancyLists=true debugExtensions=true
LUACLI_OPTIONS=\
cacheDir=_markdown_example \
contentBlocks=true \
debugExtensions=true \
definitionLists=true \
fancy_lists=true \
fencedCode=true \
footnotes=true \
hashEnumerators=true \
inlineFootnotes=true \
pipeTables=true \
smartEllipses=true \
strikeThrough=true \
subscripts=true \
superscripts=true \
tableCaptions=true \
taskLists=true
OUTPUT=context-mkii.pdf context-mkiv.pdf latex-pdftex.pdf \
latex-luatex.pdf latex-xetex.pdf latex-tex4ht.html latex-tex4ht.css

Expand Down
16 changes: 8 additions & 8 deletions examples/context-mkii.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
% Set options of the Markdown module.
\setupmarkdown
[
hashEnumerators = yes,
contentBlocks = yes,
debugExtensions = yes,
definitionLists = yes,
smartEllipses = yes,
fancy_lists = yes,
fencedCode = yes,
footnotes = yes,
hashEnumerators = yes,
inlineFootnotes = yes,
fencedCode = yes,
contentBlocks = yes,
pipeTables = yes,
tableCaptions = yes,
taskLists = yes,
smartEllipses = yes,
strikethrough = yes,
superscripts = yes,
subscripts = yes,
fancy_lists = yes,
superscripts = yes,
tableCaptions = yes,
taskLists = yes,
]

% Set renderers of the Markdown module.
Expand Down
16 changes: 8 additions & 8 deletions examples/context-mkiv.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
% Set options of the Markdown module.
\setupmarkdown
[
hashEnumerators = yes,
contentBlocks = yes,
debugExtensions = yes,
definitionLists = yes,
smartEllipses = yes,
fancy_lists = yes,
fencedCode = yes,
footnotes = yes,
hashEnumerators = yes,
inlineFootnotes = yes,
fencedCode = yes,
contentBlocks = yes,
pipeTables = yes,
tableCaptions = yes,
taskLists = yes,
smartEllipses = yes,
strikethrough = yes,
superscripts = yes,
subscripts = yes,
fancy_lists = yes,
superscripts = yes,
tableCaptions = yes,
taskLists = yes,
]

% Set renderers of the Markdown module.
Expand Down
16 changes: 8 additions & 8 deletions examples/latex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
\fi\fi
\usepackage{booktabs}
\usepackage[
hashEnumerators,
contentBlocks,
debugExtensions,
definitionLists,
fancy_lists,
fencedCode,
footnotes,
hashEnumerators,
inlineFootnotes,
jekyllData,
smartEllipses,
fencedCode,
contentBlocks,
pipeTables,
tableCaptions,
taskLists,
smartEllipses,
strikeThrough,
superscripts,
subscripts,
fancy_lists,
superscripts,
tableCaptions,
taskLists,
]{markdown}
\begin{markdown*}{hybrid}
---
Expand Down
40 changes: 38 additions & 2 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -8690,7 +8690,40 @@ local function warn(s)

local function error(s)
io.stderr:write("Error: " .. s .. "\n")
os.exit(1) end
os.exit(1)
end
% \end{macrocode}
% \begin{markdown}
%
% To make it easier to copy-and-paste options from Pandoc [@macfarlane22] such
% as `fancy_lists`, `header_attributes`, and `pipe_tables`, we accept
% snake\\\_case in addition to camelCase variants of options. As a bonus,
% studies [@sharif10] also show that snake\\\_case is faster to read than
% camelCase.
%
% \end{markdown}
% \begin{macrocode}
local function camel_case(option_name)
local cased_option_name = option_name:gsub("_(%l)", function(match)
return match:sub(2, 2):upper()
end)
return cased_option_name
end

local function snake_case(option_name)
local cased_option_name = option_name:gsub("%l%u", function(match)
return match:sub(1, 1) .. "_" .. match:sub(2, 2):lower()
end)
return cased_option_name
end

local cases = {camel_case, snake_case}
local various_case_options = {}
for option_name, _ in pairs(defaultOptions) do
for _, case in ipairs(cases) do
various_case_options[case(option_name)] = option_name
end
end

local process_options = true
local options = {}
Expand Down Expand Up @@ -8719,10 +8752,13 @@ for i = 1, #arg do
% \begin{macrocode}
elseif arg[i]:match("=") then
local key, value = arg[i]:match("(.-)=(.*)")
if defaultOptions[key] == nil then
key = various_case_options[key]
end
% \end{macrocode}
% \begin{markdown}
% The \luamref{defaultOptions} table is consulted to identify whether \meta{value}
% should be parsed as a string or as a boolean.
% should be parsed as a string, number, table, or boolean.
% \end{markdown}
% \begin{macrocode}
local default_type = type(defaultOptions[key])
Expand Down

0 comments on commit 2075a94

Please sign in to comment.