Compare commits
11 Commits
3af740f21a
...
master
Author | SHA1 | Date | |
---|---|---|---|
a2caffb06b | |||
d1220c9fb8 | |||
c794416654 | |||
d35e810681 | |||
2c77311e6c | |||
7b39bb9bdc | |||
8ea8563ec6 | |||
2c7dd2e3da | |||
ce1887a8df | |||
40650a5839 | |||
3958887efe |
70
filters/pandoc_plantuml_filter.py
Executable file
70
filters/pandoc_plantuml_filter.py
Executable file
@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
"""
|
||||
Pandoc filter to process code blocks with class "plantuml" into
|
||||
plant-generated images.
|
||||
Needs `plantuml.jar` from http://plantuml.com/.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import re
|
||||
import hashlib
|
||||
|
||||
from pandocfilters import toJSONFilter, Para, Image, RawBlock
|
||||
from pandocfilters import get_filename4code, get_caption, get_extension
|
||||
|
||||
PLANTUML_BIN = os.environ.get('PLANTUML_BIN', 'plantuml')
|
||||
|
||||
pattern = re.compile('%{(.*)\}$')
|
||||
|
||||
def plantuml(key, value, format_, meta):
|
||||
|
||||
if key == 'Header':
|
||||
if 'tikz'in (str(meta)):
|
||||
os.environ["PLANTUML_LATEX_EXPORT"] = 'latex'
|
||||
|
||||
if key == 'CodeBlock':
|
||||
if os.getenv("DEBUG", "f").lower() in ("1", "true"):
|
||||
print("plantuml", key, value, format_, meta)
|
||||
|
||||
[[ident, classes, keyvals], code] = value
|
||||
|
||||
if "plantuml" in classes:
|
||||
caption, typef, keyvals = get_caption(keyvals)
|
||||
|
||||
if "PLANTUML_LATEX_EXPORT" in os.environ:
|
||||
latex_img_format = "latex"
|
||||
else:
|
||||
latex_img_format = "eps"
|
||||
|
||||
os.makedirs("output/images", exist_ok=True)
|
||||
filename = "output/images/" + hashlib.sha1(code.encode(sys.getfilesystemencoding())).hexdigest()
|
||||
filetype = get_extension(format_, "png", html="svg", latex=latex_img_format, beamer=latex_img_format)
|
||||
|
||||
src = filename + '.uml'
|
||||
dest = filename + '.' + filetype
|
||||
|
||||
if not os.path.isfile(dest):
|
||||
txt = code.encode(sys.getfilesystemencoding())
|
||||
if not txt.startswith(b"@start"):
|
||||
txt = b"@startuml\n" + txt + b"\n@enduml\n"
|
||||
with open(src, "wb") as f:
|
||||
f.write(txt)
|
||||
subprocess.check_call(PLANTUML_BIN.split() + ["-t" + filetype, src])
|
||||
if (filetype == "latex") and (latex_img_format == 'latex'):
|
||||
latex = open(dest).read()
|
||||
return RawBlock('latex', latex.split("\\begin{document}")[-1].split("\\end{document}")[0])
|
||||
else:
|
||||
return Para([Image([ident, [], keyvals], caption, [dest, typef])])
|
||||
|
||||
|
||||
def main():
|
||||
toJSONFilter(plantuml)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1,3 +1,4 @@
|
||||
<!-- START Pandoc generated HTML -->
|
||||
$for(include-before)$
|
||||
$include-before$
|
||||
$endfor$
|
||||
@ -10,3 +11,4 @@ $body$
|
||||
$for(include-after)$
|
||||
$include-after$
|
||||
$endfor$
|
||||
<!-- END Pandoc generated HTML -->
|
||||
|
@ -10,6 +10,9 @@ $if(latex-dir-rtl)$
|
||||
\PassOptionsToPackage{RTLdocument}{bidi}
|
||||
$endif$
|
||||
$endif$
|
||||
$if(CJKmainfont)$
|
||||
\PassOptionsToPackage{space}{xeCJK}
|
||||
$endif$
|
||||
%
|
||||
\documentclass[
|
||||
$if(fontsize)$
|
||||
@ -55,9 +58,9 @@ $for(beameroption)$
|
||||
\setbeameroption{$beameroption$}
|
||||
$endfor$
|
||||
% Prevent slide breaks in the middle of a paragraph
|
||||
\widowpenalties 1 10000
|
||||
\widowpenalty10000
|
||||
\clubpenalty10000
|
||||
\raggedbottom
|
||||
\usepackage[defaultlines=3,all]{nowidow}
|
||||
$if(section-titles)$
|
||||
\setbeamertemplate{part page}{
|
||||
\centering
|
||||
@ -127,15 +130,17 @@ $endif$
|
||||
$if(mainfont)$
|
||||
\setmainfont[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$]{$mainfont$}
|
||||
$else$
|
||||
\setmainfont[Scale=1.0]{Georgia}
|
||||
\setmainfont[Scale=1.0]{PT Serif}
|
||||
$endif$
|
||||
$if(sansfont)$
|
||||
\setsansfont[$for(sansfontoptions)$$sansfontoptions$$sep$,$endfor$]{$sansfont$}
|
||||
$else$
|
||||
\setmainfont[Scale=1.0]{PT Sans}
|
||||
$endif$
|
||||
$if(monofont)$
|
||||
\setmonofont[$for(monofontoptions)$$monofontoptions$$sep$,$endfor$]{$monofont$}
|
||||
$else$
|
||||
\setmonofont[Scale=0.75]{Pragmata Pro}
|
||||
\setmonofont[Scale=0.75]{Iosevka Prog}
|
||||
$endif$
|
||||
$for(fontfamilies)$
|
||||
\newfontfamily{$fontfamilies.name$}[$for(fontfamilies.options)$$fontfamilies.options$$sep$,$endfor$]{$fontfamilies.font$}
|
||||
@ -169,6 +174,12 @@ $if(CJKmainfont)$
|
||||
\fi
|
||||
$endif$
|
||||
\fi
|
||||
|
||||
\setlength{\parindent}{12.5mm}
|
||||
\usepackage[defaultlines=3,all]{nowidow}
|
||||
\usepackage[nobottomtitles]{titlesec}
|
||||
\renewcommand{\bottomtitlespace}{.15\textheight}
|
||||
|
||||
$if(beamer)$
|
||||
$if(theme)$
|
||||
\usetheme[$for(themeoptions)$$themeoptions$$sep$,$endfor$]{$theme$}
|
||||
@ -195,14 +206,15 @@ $endif$
|
||||
\usepackage[$for(microtypeoptions)$$microtypeoptions$$sep$,$endfor$]{microtype}
|
||||
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
|
||||
}{}
|
||||
\usepackage{indentfirst}
|
||||
$if(indent)$
|
||||
$else$
|
||||
\makeatletter
|
||||
\@ifundefined{KOMAClassName}{% if non-KOMA class
|
||||
\IfFileExists{parskip.sty}{%
|
||||
\usepackage{parskip}
|
||||
}{% else
|
||||
\setlength{\parindent}{0pt}
|
||||
}{% else%
|
||||
\setlength{\parindent}{12.5mm}
|
||||
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
|
||||
}{% if KOMA class
|
||||
\KOMAoptions{parskip=half}}
|
||||
@ -221,6 +233,9 @@ $endif$
|
||||
$if(author-meta)$
|
||||
pdfauthor={$author-meta$},
|
||||
$endif$
|
||||
$if(lang)$
|
||||
pdflang={$lang$},
|
||||
$endif$
|
||||
$if(subject)$
|
||||
pdfsubject={$subject$},
|
||||
$endif$
|
||||
@ -239,7 +254,7 @@ $endif$
|
||||
}
|
||||
\urlstyle{same} % disable monospaced font for URLs
|
||||
$if(verbatim-in-note)$
|
||||
\VerbatimFootnotes % allows verbatim text in footnotes
|
||||
\VerbatimFootnotes % allow verbatim text in footnotes
|
||||
$endif$
|
||||
$if(geometry)$
|
||||
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
|
||||
@ -262,7 +277,11 @@ $if(highlighting-macros)$
|
||||
$highlighting-macros$
|
||||
$endif$
|
||||
$if(tables)$
|
||||
\usepackage{longtable,booktabs}
|
||||
\usepackage{longtable,booktabs,array}
|
||||
$if(multirow)$
|
||||
\usepackage{multirow}
|
||||
$endif$
|
||||
\usepackage{calc} % for calculating minipage widths
|
||||
$if(beamer)$
|
||||
\usepackage{caption}
|
||||
% Make caption package work with longtable
|
||||
@ -270,6 +289,11 @@ $if(beamer)$
|
||||
\def\fnum@table{\tablename~\thetable}
|
||||
\makeatother
|
||||
$else$
|
||||
% Correct order of tables after \paragraph or \subparagraph
|
||||
\usepackage{etoolbox}
|
||||
\makeatletter
|
||||
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
|
||||
\makeatother
|
||||
% Allow footnotes in longtable head/foot
|
||||
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
|
||||
\makesavenoteenv{longtable}
|
||||
@ -357,6 +381,9 @@ $else$
|
||||
\usepackage[shorthands=off,russian]{babel}
|
||||
\fi
|
||||
$endif$
|
||||
\ifluatex
|
||||
\usepackage{selnolig} % disable illegal ligatures
|
||||
\fi
|
||||
$if(dir)$
|
||||
\ifxetex
|
||||
% Load bidi as late as possible as it modifies e.g. graphicx
|
||||
@ -380,6 +407,78 @@ $for(bibliography)$
|
||||
\addbibresource{$bibliography$}
|
||||
$endfor$
|
||||
$endif$
|
||||
$if(csl-refs)$
|
||||
\newlength{\cslhangindent}
|
||||
\setlength{\cslhangindent}{1.5em}
|
||||
\newlength{\csllabelwidth}
|
||||
\setlength{\csllabelwidth}{3em}
|
||||
\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing
|
||||
{% don't indent paragraphs
|
||||
\setlength{\parindent}{0pt}
|
||||
% turn on hanging indent if param 1 is 1
|
||||
\ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
|
||||
% set entry spacing
|
||||
\ifnum #2 > 0
|
||||
\setlength{\parskip}{#2\baselineskip}
|
||||
\fi
|
||||
}%
|
||||
{}
|
||||
\usepackage{calc}
|
||||
\newcommand{\CSLBlock}[1]{#1\hfill\break}
|
||||
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
|
||||
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
|
||||
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
|
||||
$endif$
|
||||
$if(csquotes)$
|
||||
\usepackage{csquotes}
|
||||
$endif$
|
||||
|
||||
\RequirePackage{enumitem} % убрать вертикальный отступ перед списками
|
||||
|
||||
\setlist[itemize]{%
|
||||
topsep=0pt,
|
||||
parsep=0pt,
|
||||
leftmargin=0cm,
|
||||
listparindent=\parindent{},
|
||||
itemindent=\labelwidth{}
|
||||
}
|
||||
\setlist[enumerate]{%
|
||||
topsep=0pt,
|
||||
parsep=0pt,
|
||||
leftmargin=0cm,
|
||||
listparindent=\parindent{},
|
||||
itemindent=\labelwidth{}
|
||||
}
|
||||
|
||||
\AddEnumerateCounter{\asbuk}{\@asbuk}{\cyra}
|
||||
|
||||
\renewcommand{\theenumi}{\arabic{enumi}}
|
||||
\renewcommand{\labelenumi}{\theenumi)}
|
||||
\renewcommand{\theenumii}{\asbuk{enumi}}
|
||||
\renewcommand{\labelenumii}{\theenumii)}
|
||||
|
||||
\renewcommand{\labelitemi}{\bfseries\textemdash}
|
||||
\renewcommand{\labelitemii}{\bfseries\textemdash}
|
||||
\renewcommand{\labelitemiii}{\bfseries\textemdash}
|
||||
\renewcommand{\labelitemiv}{\bfseries\textemdash}
|
||||
|
||||
%\renewcommand{\@listi}{%
|
||||
% \setlength{\itemsep}{0pt}}
|
||||
%\renewcommand{\@listii}{%
|
||||
% \setlength{\itemsep}{0pt}}
|
||||
%\renewcommand{\@listiii}{%
|
||||
% \setlength{\itemsep}{0pt}}
|
||||
%\renewcommand{\@listiv}{%
|
||||
% \setlength{\itemsep}{0pt}}
|
||||
%\let\@listI\@listi
|
||||
%\@listi
|
||||
|
||||
\setlength{\labelwidth}{\parindent}
|
||||
\addtolength{\labelwidth}{\labelsep}
|
||||
\addtolength{\labelwidth}{0.7em}
|
||||
\setlength{\itemindent}{0pt}
|
||||
\setlength{\leftmargin}{\labelwidth}
|
||||
|
||||
|
||||
$if(title)$
|
||||
\title{$title$$if(thanks)$\thanks{$thanks$}$endif$}
|
||||
@ -412,6 +511,46 @@ $if(logo)$
|
||||
$endif$
|
||||
$endif$
|
||||
|
||||
\usepackage{float}
|
||||
\let\origfigure=\figure
|
||||
\let\endorigfigure=\endfigure
|
||||
\renewenvironment{figure}[1][]{%
|
||||
\origfigure[H]
|
||||
\centering
|
||||
}{%
|
||||
\endorigfigure
|
||||
}
|
||||
|
||||
\usepackage{acro}
|
||||
\NewAcroTemplate[list]{acrolist}{%
|
||||
\AcroNeedPackage{array}%
|
||||
\acronymsmapF{%
|
||||
\AcroAddRow{
|
||||
\acrowrite{short}%
|
||||
\acroifT{alt}{/\acrowrite{alt}}
|
||||
&~---~
|
||||
\acrowrite{list}%
|
||||
\acroifanyT{foreign,extra}{ (}%
|
||||
\acroifT{foreign}{\acrowrite{foreign}\acroifT{extra}{, }}%
|
||||
\acroifT{extra}{\acrowrite{extra}}%
|
||||
\acroifanyT{foreign,extra}{)}%
|
||||
\acropagefill
|
||||
\acropages
|
||||
{\acrotranslate{page}\nobreakspace}
|
||||
{\acrotranslate{pages}\nobreakspace}%
|
||||
\tabularnewline
|
||||
}%
|
||||
}
|
||||
{\AcroRerun}%
|
||||
\acroheading
|
||||
\acropreamble
|
||||
\par\noindent
|
||||
\begin{tabular}{>{}lp{.7\linewidth}}
|
||||
\AcronymTable
|
||||
\end{tabular}
|
||||
}
|
||||
\acsetup{make-links = true, pdfcomments/use = true, list/template = acrolist, first-style = short}
|
||||
|
||||
\begin{document}
|
||||
$if(has-frontmatter)$
|
||||
\frontmatter
|
||||
@ -434,11 +573,12 @@ $include-before$
|
||||
|
||||
$endfor$
|
||||
$if(toc)$
|
||||
\cleardoublepage
|
||||
$if(toc-title)$
|
||||
\renewcommand*\contentsname{$toc-title$}
|
||||
$endif$
|
||||
$if(beamer)$
|
||||
\begin{frame}
|
||||
\begin{frame}[allowframebreaks]
|
||||
$if(toc-title)$
|
||||
\frametitle{$toc-title$}
|
||||
$endif$
|
||||
@ -453,6 +593,7 @@ $endif$
|
||||
\tableofcontents
|
||||
}
|
||||
$endif$
|
||||
\cleardoublepage
|
||||
$endif$
|
||||
$if(lot)$
|
||||
\listoftables
|
||||
|
Reference in New Issue
Block a user