Skip to content

Commit

Permalink
Merge pull request #194 from Witiko/feature/accept-snake-case
Browse files Browse the repository at this point in the history
Accept snake_case and snakecase variants of options in `\markdownSetup` and `\setupmarkdown`
  • Loading branch information
github-actions[bot] authored Oct 7, 2022
2 parents 8ca83f5 + 79a8144 commit ea9040c
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 46 deletions.
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changes

## 2.18.0

Development:

- Accept snake_case and snakecase variants of options in `\markdownSetup` and
`\setupmarkdown`. (#193, #194)

## 2.17.1 (2022-10-03)

Fixes:
Expand Down
4 changes: 2 additions & 2 deletions examples/context-mkii.tex
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
pipeTables = yes,
tableCaptions = yes,
taskLists = yes,
strikeThrough = yes,
strikethrough = yes,
superscripts = yes,
subscripts = yes,
fancyLists = yes,
fancy_lists = yes,
]

% Set renderers of the Markdown module.
Expand Down
4 changes: 2 additions & 2 deletions examples/context-mkiv.tex
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
pipeTables = yes,
tableCaptions = yes,
taskLists = yes,
strikeThrough = yes,
strikethrough = yes,
superscripts = yes,
subscripts = yes,
fancyLists = yes,
fancy_lists = yes,
]

% Set renderers of the Markdown module.
Expand Down
4 changes: 2 additions & 2 deletions examples/latex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
pipeTables,
tableCaptions,
taskLists,
strikeThrough,
strikethrough,
superscripts,
subscripts,
fancyLists,
fancy_lists,
]{markdown}
\begin{markdown*}{hybrid}
---
Expand Down
197 changes: 157 additions & 40 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,13 @@ abbr {
version = {v2.5},
url = {https://mirrors.ctan.org/macros/latex/contrib/minted/minted.pdf},
urldate = {2020-09-01}}
@online{macfarlane22,
title = {Pandoc},
subtitle = {a universal document converter},
author = {John MacFarlane},
year = {2022},
url = {https://pandoc.org/},
urldate = {2022-10-05}}
@online{novotny15,
author = {Novotný, Vít},
year = {2015},
Expand Down Expand Up @@ -2110,6 +2117,60 @@ interfaces and all the way up to the \LaTeX{} and \Hologo{ConTeXt} interfaces.
\tl_tail:n { #1 }
}
}
\cs_new:Nn \@@_with_various_cases:nn
{
\seq_clear:N
\l_tmpa_seq
\clist_map_inline:nn
{
@@_camel_case:N,
@@_snake_case:N,
@@_snake_case_without_underscores:N,
}
{
\tl_set:Nn
\l_tmpa_tl
{ #1 }
\use:c { ##1 }
\l_tmpa_tl
\seq_put_right:NV
\l_tmpa_seq
\l_tmpa_tl
}
\seq_map_inline:Nn
\l_tmpa_seq
{ #2 }
}
\cs_new:Nn \@@_camel_case:N
{
\regex_replace_all:nnN
{ _ ([a-z]) }
{ \c { str_uppercase:n } \cB\{ \1 \cE\} }
#1
\tl_set:Nx
#1
{ #1 }
}
\cs_new:Nn \@@_snake_case:N
{
\regex_replace_all:nnN
{ ([a-z])([A-Z]) }
{ \1 _ \c { str_lowercase:n } \cB\{ \2 \cE\} }
#1
\tl_set:Nx
#1
{ #1 }
}
\cs_new:Nn \@@_snake_case_without_underscores:N
{
\regex_replace_all:nnN
{ ([a-z])([A-Z]) }
{ \1 \c { str_lowercase:n } \cB\{ \2 \cE\} }
#1
\tl_set:Nx
#1
{ #1 }
}
% \end{macrocode}
% \iffalse
%</tex>
Expand Down Expand Up @@ -16661,13 +16722,27 @@ The following ordered list will be preceded by roman numerals:
\seq_map_inline:cn
{ g_@@_ ##1 _options_seq }
{
\@@_latex_define_option_keyval:nn
{ ##1 }
% \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 both
% snake\\\_case and camelCase variants of options.
%
% \end{markdown}
% \begin{macrocode}
\@@_with_various_cases:nn
{ ####1 }
{
\@@_latex_define_option_keyval:nnn
{ ##1 }
{ ####1 }
{ ########1 }
}
}
}
}
\cs_new:Nn \@@_latex_define_option_keyval:nn
\cs_new:Nn \@@_latex_define_option_keyval:nnn
{
\prop_get:cnN
{ g_@@_ #1 _option_types_prop }
Expand All @@ -16676,7 +16751,7 @@ The following ordered list will be preceded by roman numerals:
\keys_define:nn
{ markdown/latex-options }
{
#2 .code:n = {
#3 .code:n = {
\@@_set_option_value:nn
{ #2 }
{ ##1 }
Expand All @@ -16689,7 +16764,7 @@ The following ordered list will be preceded by roman numerals:
\keys_define:nn
{ markdown/latex-options }
{
#2 .default:n = { true },
#3 .default:n = { true },
}
}
% \end{macrocode}
Expand All @@ -16710,7 +16785,7 @@ The following ordered list will be preceded by roman numerals:
{
\tl_set:Nn
\l_tmpa_tl
{ #2 }
{ #3 }
\tl_reverse:N
\l_tmpa_tl
\str_if_eq:enF
Expand All @@ -16723,7 +16798,7 @@ The following ordered list will be preceded by roman numerals:
\msg_error:nnn
{ @@ }
{ malformed-name-for-clist-option }
{ #2 }
{ #3 }
}
\tl_set:Nx
\l_tmpa_tl
Expand Down Expand Up @@ -16865,16 +16940,20 @@ The following ordered list will be preceded by roman numerals:
}
\cs_new:Nn \@@_latex_define_renderer:nNn
{
\keys_define:nn
{ markdown/latex-options/renderers }
\@@_with_various_cases:nn
{ #1 }
{
#1 .code:n = {
\cs_generate_from_arg_count:NNnn
#2
\cs_set:Npn
{ #3 }
{ ##1 }
},
\keys_define:nn
{ markdown/latex-options/renderers }
{
##1 .code:n = {
\cs_generate_from_arg_count:NNnn
#2
\cs_set:Npn
{ #3 }
{ ####1 }
},
}
}
}
\cs_generate_variant:Nn
Expand Down Expand Up @@ -16929,16 +17008,20 @@ The following ordered list will be preceded by roman numerals:
}
\cs_new:Nn \@@_latex_define_renderer_prototype:nNn
{
\keys_define:nn
{ markdown/latex-options/renderer-prototypes }
\@@_with_various_cases:nn
{ #1 }
{
#1 .code:n = {
\cs_generate_from_arg_count:NNnn
#2
\cs_set:Npn
{ #3 }
{ ##1 }
},
\keys_define:nn
{ markdown/latex-options/renderer-prototypes }
{
##1 .code:n = {
\cs_generate_from_arg_count:NNnn
#2
\cs_set:Npn
{ #3 }
{ ####1 }
},
}
}
}
\cs_generate_variant:Nn
Expand Down Expand Up @@ -17160,13 +17243,27 @@ texexec --passon=--shell-escape document.tex
\seq_map_inline:cn
{ g_@@_ ##1 _options_seq }
{
\@@_context_define_option_keyval:nn
{ ##1 }
% \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 both
% snake\\\_case and camelCase variants of options.
%
% \end{markdown}
% \begin{macrocode}
\@@_with_various_cases:nn
{ ####1 }
{
\@@_context_define_option_keyval:nnn
{ ##1 }
{ ####1 }
{ ########1 }
}
}
}
}
\cs_new:Nn \@@_context_define_option_keyval:nn
\cs_new:Nn \@@_context_define_option_keyval:nnn
{
\prop_get:cnN
{ g_@@_ #1 _option_types_prop }
Expand All @@ -17175,7 +17272,7 @@ texexec --passon=--shell-escape document.tex
\keys_define:nn
{ markdown/context-options }
{
#2 .code:n = {
#3 .code:n = {
\tl_set:Nx
\l_tmpa_tl
{
Expand All @@ -17199,7 +17296,7 @@ texexec --passon=--shell-escape document.tex
\keys_define:nn
{ markdown/context-options }
{
#2 .default:n = { true },
#3 .default:n = { true },
}
}
}
Expand Down Expand Up @@ -25266,11 +25363,20 @@ end
{ markdown/latex-options/renderers }
{ #1 }
},
rendererPrototypes .code:n = {
\keys_set:nn
{ markdown/latex-options/renderer-prototypes }
{ #1 }
},
}
\@@_with_various_cases:nn
{ rendererPrototypes }
{
\keys_define:nn
{ markdown/latex-options }
{
#1 .code:n = {
\keys_set:nn
{ markdown/latex-options/renderer-prototypes }
{ ##1 }
},
}
}
% \end{macrocode}
% \begin{markdown}
%
Expand All @@ -25279,7 +25385,11 @@ end
%
% \end{markdown}
% \begin{macrocode}
\keys_define:nn
{ markdown/latex-options }
{
code .code:n = { #1 },
}
% \end{macrocode}
% \begin{markdown}
%
Expand All @@ -25289,11 +25399,18 @@ end
%
% \end{markdown}
% \begin{macrocode}
jekyllDataRenderers .code:n = {
\keys_set:nn
{ markdown/latex-options/jekyll-data-renderers }
{ #1 }
},
\@@_with_various_cases:nn
{ jekyllDataRenderers }
{
\keys_define:nn
{ markdown/latex-options }
{
#1 .code:n = {
\keys_set:nn
{ markdown/latex-options/jekyll-data-renderers }
{ ##1 }
},
}
}
\keys_define:nn
{ markdown/latex-options/jekyll-data-renderers }
Expand Down

0 comments on commit ea9040c

Please sign in to comment.