Skip to content

Commit

Permalink
Rewrite snippets to expl3
Browse files Browse the repository at this point in the history
  • Loading branch information
Witiko committed Dec 15, 2023
1 parent 64fbe34 commit 3838560
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 33 deletions.
90 changes: 59 additions & 31 deletions markdown.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -11985,20 +11985,20 @@ a specific look and other high-level goals without low-level programming.
% To keep track of the current theme when themes are nested, we will
% maintain the \mdef{g_\@\@_themes_seq} stack of theme names.
% For convenience, the name of the current theme is also available in the
% \mdef{markdownThemeName} macro.
% \mdef{g_@@_current_theme_tl} macro.
%
% \end{markdown}
% \begin{macrocode}
\seq_new:N
\g_@@_themes_seq
\tl_new:N
\markdownThemeName
\g_@@_current_theme_tl
\tl_gset:Nn
\markdownThemeName
\g_@@_current_theme_tl
{ }
\seq_gput_right:NV
\g_@@_themes_seq
\markdownThemeName
\g_@@_current_theme_tl
\cs_new:Nn
\@@_set_theme:n
{
Expand Down Expand Up @@ -12047,11 +12047,11 @@ a specific look and other high-level goals without low-level programming.
% \end{markdown}
% \begin{macrocode}
\tl_gset:Nn
\markdownThemeName
\g_@@_current_theme_tl
{ #1 / }
\seq_gput_right:NV
\g_@@_themes_seq
\markdownThemeName
\g_@@_current_theme_tl
\@@_load_theme:nV
{ #1 }
\l_tmpa_str
Expand All @@ -12062,7 +12062,7 @@ a specific look and other high-level goals without low-level programming.
\g_@@_themes_seq
\l_tmpa_tl
\tl_gset:NV
\markdownThemeName
\g_@@_current_theme_tl
\l_tmpa_tl
}
\cs_generate_variant:Nn
Expand Down Expand Up @@ -12149,6 +12149,8 @@ options locally.
% \end{markdown}
% \begin{macrocode}
\ExplSyntaxOn
\prop_new:N
\g_@@_snippets_prop
\cs_new:Nn
\@@_setup_snippet:nn
{
Expand All @@ -12159,22 +12161,26 @@ options locally.
{ Empty~snippet~name }
{ Pick~a~non-empty~name~for~your~snippet }
}
\markdownIfSnippetExists
\@@_if_snippet_exists:nT
{ #1 }
{
\markdownWarning
{ Redefined~snippet~\markdownThemeName#1 }
\csname markdownSetupSnippet%
\markdownThemeName#1\endcsname={#2}
}
{
\newtoks\next
\next={#2}
\expandafter\let\csname markdownSetupSnippet%
\markdownThemeName#1\endcsname=\next
{ Redefined~snippet~\g_@@_current_theme_tl #1 }
}
\tl_set:NV
\l_tmpa_tl
\g_@@_current_theme_tl
\tl_put_right:Nn
\l_tmpa_tl
{ #1 }
\prop_gput:NVn
\g_@@_snippets_prop
\l_tmpa_tl
{ #2 }
}
\let\markdownSetupSnippet=\@@_setup_snippet:nn
\cs_gset_eq:NN
\markdownSetupSnippet
\@@_setup_snippet:nn
% \end{macrocode}
% \begin{markdown}
%
Expand All @@ -12183,15 +12189,26 @@ options locally.
%
% \end{markdown}
% \begin{macrocode}
\cs_new:Npn
\markdownIfSnippetExists
#1 #2 #3
\prg_new_conditional:Nnn
\@@_if_snippet_exists:n
{ TF, T, F }
{
\@ifundefined
{ markdownSetupSnippet\markdownThemeName#1 }%
{ #3 }
{ #2 }
\tl_set:NV
\l_tmpa_tl
\g_@@_current_theme_tl
\tl_put_right:Nn
\l_tmpa_tl
{ #1 }
\prop_get:NVNTF
\g_@@_snippets_prop
\l_tmpa_tl
\l_tmpb_tl
{ \prg_return_true: }
{ \prg_return_false: }
}
\cs_gset_eq:NN
\markdownSetupSnippet
\@@_if_snippet_exists:nTF
% \end{macrocode}
% \begin{markdown}
%
Expand All @@ -12203,14 +12220,25 @@ options locally.
{ markdown/options }
{
snippet .code:n = {
\markdownIfSnippetExists{#1}
\@@_if_snippet_exists:nT
{ #1 }
{
\tl_set:NV
\l_tmpa_tl
\g_@@_current_theme_tl
\tl_put_right:Nn
\l_tmpa_tl
{ #1 }
\prop_get:NVN
\g_@@_snippets_prop
\l_tmpa_tl
\l_tmpb_tl
\tl_use:N
\l_tmpb_tl
}
{
\expandafter\markdownSetup\expandafter{
\the\csname markdownSetupSnippet
\markdownThemeName#1\endcsname}
}{
\markdownError
{ Can't~invoke~setup~snippet~#1 }
{ Can't~invoke~setup~snippet~\g_@@_current_theme_tl #1 }
{ The~setup~snippet~is~undefined }
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/support/markdownthemewitiko_markdown_test.sty
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

% Expand `\markdownSetupSnippet{snippet}{<content of keyval-setup.tex>}`.
\cs_generate_variant:Nn
\__markdown_latex_setup_snippet:nn
\__markdown_setup_snippet:nn
{ nV }
\__markdown_latex_setup_snippet:nV
\__markdown_setup_snippet:nV
{ snippet }
\l_tmpa_tl
}
Expand Down

0 comments on commit 3838560

Please sign in to comment.