Skip to main content
more idiomatic expl3
Source Link
mbert
  • 12k
  • 1
  • 23
  • 134

All your requirements except the indentation guide are possible out of the box with minted. If you need the indentation guide, you can manually add the vertical lines with escapeinside and tikzmark.

\documentclass{article} \usepackage{tikz} \usetikzlibrary{tikzmark} \usepackage{minted} \newminted{JSON}{linenos,frame=single,framesep=10pt,style=autumn,escapeinside=??} \newcounter{JSONcode}\ExplSyntaxOn \int_new:N \g_kyu_JSONcode_int \AddToHook{env/JSONcode/before}{\stepcounter{JSONcode}\int_incr:N \g_kyu_JSONcode_int} \ExplSyntaxOn \clist_new:N \g_kyu_JSONmarks_clist \newcommand\NewDocumentCommand { \JSONmark }[1] { m } { \tikzmark{JSON-\theJSONcode\int_use:N \g_kyu_JSONcode_int-#1-begin} \clist_gput_right:Nn \g_kyu_JSONmarks_clist { #1 } } \newcommand\NewDocumentCommand { \finishJSONmark }[1] { m } { \tikzmark{JSON-\theJSONcode\int_use:N \g_kyu_JSONcode_int-#1-end} } \AddToHook{env/JSONcode/after} { \begin{tikzpicture}[remember~picture] \clist_map_function:NN \g_kyu_JSONmarks_clist \drawJSONmark\kyu_drawJSONmark:n \end{tikzpicture} \clist_gclear:N \g_kyu_JSONmarks_clist } \ExplSyntaxOff \cs_new_protected:Nn \kyu_drawJSONmark:n \newcommand{\drawJSONmark}[1] {%   \draw[overlay,-,line width=0line~width=0.5pt,gray!50,shorten >=1emshorten~>=1em,shorten <=0shorten~<=0.3em] (picpic~cs\c_colon_str cs:JSON-\theJSONcode\int_use:N \g_kyu_JSONcode_int-#1-begin)  --  (picpic~cs\c_colon_str cs:JSON-\theJSONcode\int_use:N \g_kyu_JSONcode_int-#1-end); } \ExplSyntaxOff \begin{document} \begin{JSONcode} ?\JSONmark{1}?"builders": [ ?\JSONmark{2}?{ "type": "test", "image": "ubuntu:latest", ?\JSONmark{3}?"changes": [ "EXPOSE 123 456", "CMD [\"/tmp/entrypoint.sh\"]" ?\finishJSONmark{3}?], "commit": true ?\finishJSONmark{2}?} ?\finishJSONmark{1}?] \end{JSONcode} \end{document} 

JSON code

All your requirements except the indentation guide are possible out of the box with minted. If you need the indentation guide, you can manually add the vertical lines with escapeinside and tikzmark.

\documentclass{article} \usepackage{tikz} \usetikzlibrary{tikzmark} \usepackage{minted} \newminted{JSON}{linenos,frame=single,framesep=10pt,style=autumn,escapeinside=??} \newcounter{JSONcode} \AddToHook{env/JSONcode/before}{\stepcounter{JSONcode}} \ExplSyntaxOn \clist_new:N \g_kyu_JSONmarks_clist \newcommand{\JSONmark}[1] { \tikzmark{JSON-\theJSONcode-#1-begin} \clist_gput_right:Nn \g_kyu_JSONmarks_clist { #1 } } \newcommand{\finishJSONmark}[1]{\tikzmark{JSON-\theJSONcode-#1-end}} \AddToHook{env/JSONcode/after} { \begin{tikzpicture}[remember~picture] \clist_map_function:NN \g_kyu_JSONmarks_clist \drawJSONmark \end{tikzpicture} \clist_gclear:N \g_kyu_JSONmarks_clist } \ExplSyntaxOff  \newcommand{\drawJSONmark}[1]{% \draw[overlay,-,line width=0.5pt,gray!50,shorten >=1em,shorten <=0.3em](pic cs:JSON-\theJSONcode-#1-begin) -- (pic cs:JSON-\theJSONcode-#1-end); } \begin{document} \begin{JSONcode} ?\JSONmark{1}?"builders": [ ?\JSONmark{2}?{ "type": "test", "image": "ubuntu:latest", ?\JSONmark{3}?"changes": [ "EXPOSE 123 456", "CMD [\"/tmp/entrypoint.sh\"]" ?\finishJSONmark{3}?], "commit": true ?\finishJSONmark{2}?} ?\finishJSONmark{1}?] \end{JSONcode} \end{document} 

JSON code

All your requirements except the indentation guide are possible out of the box with minted. If you need the indentation guide, you can manually add the vertical lines with escapeinside and tikzmark.

\documentclass{article} \usepackage{tikz} \usetikzlibrary{tikzmark} \usepackage{minted} \newminted{JSON}{linenos,frame=single,framesep=10pt,style=autumn,escapeinside=??} \ExplSyntaxOn \int_new:N \g_kyu_JSONcode_int \AddToHook{env/JSONcode/before}{\int_incr:N \g_kyu_JSONcode_int} \clist_new:N \g_kyu_JSONmarks_clist \NewDocumentCommand { \JSONmark } { m } { \tikzmark{JSON-\int_use:N \g_kyu_JSONcode_int-#1-begin} \clist_gput_right:Nn \g_kyu_JSONmarks_clist { #1 } } \NewDocumentCommand { \finishJSONmark } { m } { \tikzmark{JSON-\int_use:N \g_kyu_JSONcode_int-#1-end} } \AddToHook{env/JSONcode/after} { \begin{tikzpicture}[remember~picture] \clist_map_function:NN \g_kyu_JSONmarks_clist \kyu_drawJSONmark:n \end{tikzpicture} \clist_gclear:N \g_kyu_JSONmarks_clist } \cs_new_protected:Nn \kyu_drawJSONmark:n  {   \draw[overlay,-,line~width=0.5pt,gray!50,shorten~>=1em,shorten~<=0.3em] (pic~cs\c_colon_str JSON-\int_use:N \g_kyu_JSONcode_int-#1-begin)  --  (pic~cs\c_colon_str JSON-\int_use:N \g_kyu_JSONcode_int-#1-end); } \ExplSyntaxOff \begin{document} \begin{JSONcode} ?\JSONmark{1}?"builders": [ ?\JSONmark{2}?{ "type": "test", "image": "ubuntu:latest", ?\JSONmark{3}?"changes": [ "EXPOSE 123 456", "CMD [\"/tmp/entrypoint.sh\"]" ?\finishJSONmark{3}?], "commit": true ?\finishJSONmark{2}?} ?\finishJSONmark{1}?] \end{JSONcode} \end{document} 

JSON code

Source Link
mbert
  • 12k
  • 1
  • 23
  • 134

All your requirements except the indentation guide are possible out of the box with minted. If you need the indentation guide, you can manually add the vertical lines with escapeinside and tikzmark.

\documentclass{article} \usepackage{tikz} \usetikzlibrary{tikzmark} \usepackage{minted} \newminted{JSON}{linenos,frame=single,framesep=10pt,style=autumn,escapeinside=??} \newcounter{JSONcode} \AddToHook{env/JSONcode/before}{\stepcounter{JSONcode}} \ExplSyntaxOn \clist_new:N \g_kyu_JSONmarks_clist \newcommand{\JSONmark}[1] { \tikzmark{JSON-\theJSONcode-#1-begin} \clist_gput_right:Nn \g_kyu_JSONmarks_clist { #1 } } \newcommand{\finishJSONmark}[1]{\tikzmark{JSON-\theJSONcode-#1-end}} \AddToHook{env/JSONcode/after} { \begin{tikzpicture}[remember~picture] \clist_map_function:NN \g_kyu_JSONmarks_clist \drawJSONmark \end{tikzpicture} \clist_gclear:N \g_kyu_JSONmarks_clist } \ExplSyntaxOff \newcommand{\drawJSONmark}[1]{% \draw[overlay,-,line width=0.5pt,gray!50,shorten >=1em,shorten <=0.3em](pic cs:JSON-\theJSONcode-#1-begin) -- (pic cs:JSON-\theJSONcode-#1-end); } \begin{document} \begin{JSONcode} ?\JSONmark{1}?"builders": [ ?\JSONmark{2}?{ "type": "test", "image": "ubuntu:latest", ?\JSONmark{3}?"changes": [ "EXPOSE 123 456", "CMD [\"/tmp/entrypoint.sh\"]" ?\finishJSONmark{3}?], "commit": true ?\finishJSONmark{2}?} ?\finishJSONmark{1}?] \end{JSONcode} \end{document} 

JSON code