Markdown、Pandoc、LaTeX 和警告

Markdown、Pandoc、LaTeX 和警告

Markdown我正在为使用和服务的程序编写手册MKDocs,但我还想以可下载的 PDF 形式提供这些手册。Pandoc 和冰鸟模板大有帮助,但据我所知,缺少一件事;警告

这个答案的代码看起来是最好的解决方案但我如何使用它

如果可能的话,我希望它对 Markdown 文件的影响尽可能小,理想的情况是将整个内容添加到单独的文件中,并将 -H 与 Pandoc 一起使用,一切都会神奇地起作用。

% !TeX program = lualatex
\documentclass{article}

\usepackage[svgnames]{xcolor}
\usepackage{tcolorbox,marvosym,xstring}
\newcommand\boxcolor{}
\newcommand\mybox[3]{%
\IfStrEq{#1}{note}{\renewcommand\boxcolor{CornflowerBlue}}{%
   \IfStrEq{#1}{danger}{\renewcommand\boxcolor{Tomato}}{%
   \IfStrEq{#1}{warning}{\renewcommand\boxcolor{Crimson}}{}}}
\begin{tcolorbox}[colback=\boxcolor!15!white,          
                  colframe=\boxcolor,
                  title=\sffamily\bfseries\Info\quad #2]
                  \sffamily #3
\end{tcolorbox}}

\usepackage{luacode}
\begin{luacode}
function triplebang (s)
  if not (boxedflag) then
    if string.find ( s , '^!!!' ) then
      boxedflag=true
      return string.gsub ( s, '^!!! (%a*) "(.*)"$', '\\mybox{%1}{%2}{' )
    else
      return s
    end
  else
    if string.find (s , '^XXX' ) then 
      return string.sub ( s , 4 )
    else
      boxedflag=false
      return '}' .. s
    end
  end
end
\end{luacode}

\def\startlooking{\directlua{%
   boxedflag=false
   luatexbase.add_to_callback(
      'process_input_buffer', triplebang , 'triplebang' )}}
\def\stoplooking{\directlua{%
   luatexbase.remove_from_callback(
      'process_input_buffer' , 'triplebang' )}}

\begin{document}
\startlooking
Not part of the note.
!!! note "A Note Title"
XXXThis is
XXXa note with
XXXmultiple lines
XXX
XXXpossibly containing
XXXparagraph breaks.
Not part of the note either.
!!! danger "A Danger Title"
XXXThis is
XXXanother note with
XXXmultiple lines.
Further non-note text.
!!! warning "A Warning Title"
XXXThis is yet
XXXanother note with
XXXmultiple lines.
Still more non-note text.
\stoplooking
\end{document}

PS,我本来想对上述答案发表评论,但 (1) 它已经有六年了,而且 (2) 我没有足够的声誉来发表评论。

相关内容