PDF export (via manually running latex)

This commit is contained in:
relikd
2020-11-14 20:29:11 +01:00
parent ea40bda0c7
commit 3fde15b9e9
32 changed files with 606 additions and 15 deletions

3
extras/pdf-export/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/pdf-de.pdf
/pdf-en.pdf
/setup-builddir.tex

View File

@@ -0,0 +1,43 @@
Copyright (c) 2010, Sebastian Kosch (sebastian@aldusleaf.org), with Reserved Font Name "Crimson Text".
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,93 @@
Copyright (c) 2012-2015, The Mozilla Foundation and Telefonica S.A.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,69 @@
%PDF-1.5
%<25><><EFBFBD><EFBFBD>
3 0 obj
<< /Length 4 0 R
/Filter /FlateDecode
>>
stream
x<EFBFBD>UPKRD1<08><>\@$B8<42>G<EFBFBD><47><EFBFBD>q<EFBFBD>\<5C><><EFBFBD>^<5E><>ge<67><65>n<EFBFBD><6E>w!<21><><EFBFBD><EFBFBD><EFBFBD>w<EFBFBD><77>oq%P"<22><>DM+<2B>1<EFBFBD> <0C>f<EFBFBD><66><EFBFBD>nO<6E><4F><EFBFBD><EFBFBD><08>-<2D>.<2E><>6<EFBFBD><36>`<60><19>E<EFBFBD>U7<55>,<2C>R<EFBFBD><52><EFBFBD>h<15>{<7B>Um q<05><>&
h2<68><32><EFBFBD>`)V0<56><30><11>4<EFBFBD><16>Ps<50><<3C>wLwL<77><4C><EFBFBD>,<2C>=<3D>t<EFBFBD><74><EFBFBD><1E>r<05><>j<EFBFBD>y<EFBFBD>DL<1D>;tgd
<EFBFBD>b<EFBFBD><EFBFBD><EFBFBD>f3<EFBFBD>u<><75><16><>.<2E><>n1N<31><4E>f4.<2E><>*<2A>j<EFBFBD> mW<>˜]Ң1<D2A2>0aQ<61><51><EFBFBD>{12to Ց-/ޕ<>3<03><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD>M<EFBFBD><11>
<EFBFBD>pP
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?w<>
endstream
endobj
4 0 obj
273
endobj
2 0 obj
<<
/ExtGState <<
/a0 << /CA 1 /ca 1 >>
>>
>>
endobj
5 0 obj
<< /Type /Page
/Parent 1 0 R
/MediaBox [ 0 0 1000 1000 ]
/Contents 3 0 R
/Group <<
/Type /Group
/S /Transparency
/I true
/CS /DeviceRGB
>>
/Resources 2 0 R
>>
endobj
1 0 obj
<< /Type /Pages
/Kids [ 5 0 R ]
/Count 1
>>
endobj
6 0 obj
<< /Creator (cairo 1.12.18 (http://cairographics.org))
/Producer (cairo 1.12.18 (http://cairographics.org))
>>
endobj
7 0 obj
<< /Type /Catalog
/Pages 1 0 R
>>
endobj
xref
0 8
0000000000 65535 f
0000000675 00000 n
0000000387 00000 n
0000000015 00000 n
0000000365 00000 n
0000000459 00000 n
0000000740 00000 n
0000000869 00000 n
trailer
<< /Size 8
/Root 7 0 R
/Info 6 0 R
>>

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,14 @@
\documentclass[a4paper,12pt,twoside]{article}
\usepackage[ngerman]{babel}
\include{setup}
\include{setup-builddir} % load \def\builddir{}
\def\tIngredients{Zutaten}
\def\tRecipe{Rezept}
\def\tPagePrefix{S.}
\begin{document}
\makefrontmatter
\graphicspath{{\builddir/de/}}
\include{\builddir/de/pdf-export}
\end{document}

View File

@@ -0,0 +1,14 @@
\documentclass[letter,12pt,twoside]{article}
\usepackage[english]{babel}
\include{setup}
\include{setup-builddir} % load \def\builddir{}
\def\tIngredients{Ingredients}
\def\tRecipe{recipe}
\def\tPagePrefix{p.}
\begin{document}
\makefrontmatter
\graphicspath{{\builddir/en/}}
\include{\builddir/en/pdf-export}
\end{document}

174
extras/pdf-export/setup.tex Normal file
View File

@@ -0,0 +1,174 @@
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry} % margin width
\usepackage{graphicx} % includegraphics
\usepackage{xcolor} % colors
\usepackage{sidenotes} % margin figure, etc.
\usepackage{enumitem} % setlist[description]
\usepackage{titleps} % footer page number
\usepackage{tocloft} % \cftbeforesecskip
\usepackage{ragged2e} % \RaggedRight
\usepackage{fontspec} % \setmainfont, \setsansfont, \setmonofont
\definecolor{red2}{HTML}{AA203A}
\definecolor{red3}{HTML}{EE6A84}
\usepackage{xurl}
\PassOptionsToPackage{hyphens}{url}
\usepackage{hyperref}
\renewcommand{\UrlFont}{\normalfont}
%% Use this if the font is _not_ installed on the system
%% but it requires the download of the additional fonts package
%% \setmonofont[Path=fonts/]{FiraSans-Light}
\setmainfont[
Path = fonts/,
BoldFont = Crimson-Bold,
ItalicFont = Crimson-Italic,
BoldItalicFont = Crimson-BoldItalic
]{Crimson-Roman}
\setsansfont[
Path = fonts/,
Scale = 0.95,
BoldFont = FiraSans-Medium,
ItalicFont = FiraSans-LightItalic,
BoldItalicFont = FiraSans-MediumItalic
]{FiraSans-Regular}
%% Use this if the font is installed on the system
%% this does not require additional fonts package
% \setmainfont[
% BoldFont = {Fira Sans Medium},
% ItalicFont = {Fira Sans Light Italic},
% BoldItalicFont = {Fira Sans Medium Italic}
% ]{Fira Sans Regular}
% \setmainfont[
% BoldFont = {Crimson Bold},
% ItalicFont = {Crimson Italic},
% BoldItalicFont = {Crimson Bold Italic}
% ]{Crimson Roman}
% Defines & Geometry
\def\marginwidth{60mm}
\def\marginsep{8.2mm}
\def\marginwoverflow{67mm} % -1.2mm for makebox
% space before \paragraph
\setlength{\parindent}{0pt}
% space between paragraphs
\setlength{\parskip}{0.4\baselineskip}
\geometry{
head=13.6pt,
top=2cm,
bottom=2cm,
inner=2cm,
outer=2cm,
marginparsep=\marginsep,
marginparwidth=\marginwidth,
includemp,
% showframe
}
% \renewcommand{\footnotesep}{2.5ex}
\renewcommand{\footnoterule}{
\kern -2pt
\hrule width \textwidth height .2pt
\kern 1.8pt}
% spacing before & after
\makeatletter
% footer
\renewcommand\@makefntext[1]{\noindent\makebox[0.5em][l]{\@makefnmark}#1}
% subsubsection
\renewcommand{\subsubsection}{%
\@startsection{subsubsection}{3}%
{\z@}{-2ex \@plus -1ex \@minus -1ex}{.2ex \@plus 1ex \@minus .2ex}%
{\normalfont\large\bfseries}%
}
% paragraph
\renewcommand{\paragraph}{%
\@startsection{paragraph}{4}%
{\z@}{1.5ex \@plus 1ex \@minus .2ex}{-.75em}%
{\normalfont\normalsize\bfseries}%
}
\makeatother
% adjust description environment
\setlist[description,enumerate,itemize]{%
topsep=0.7\baselineskip,
itemsep=0pt,
% itemindent=-2em,
% listparindent=-2em,
% leftmargin=0em,
font={\sffamily}
}
\setlist[enumerate,itemize]{leftmargin=1em,topsep=0\baselineskip,parsep=0pt}
\widowpenalty10000
\clubpenalty10000
% disable section numbering
\setcounter{secnumdepth}{0}
\setcounter{tocdepth}{1}
% \titleformat*{\section}{\LARGE\bfseries} # titlesec
\setlength{\cftbeforesecskip}{0.2em} % spacing in TOC
% Footer page numbering
\renewpagestyle{plain}{%
\setfoot[{\makebox[-\marginwoverflow][r]{\thepage}}][][]{}{}{{\makebox[-\marginwoverflow][l]{\thepage}}}
}
\pagestyle{plain}
% \graphicspath{{../src/content/}}
\newcommand{\makefrontmatter}{
\begin{titlepage}
\newgeometry{top=2.5cm,bottom=2.5cm,left=4cm,right=4cm}
\centering
\vspace*{.06\textheight}
\includegraphics[width=54mm]{misc/logo.pdf}\par
\vspace*{.06\textheight}
{\huge\sf recipe lekture}
\vfill
\today
\end{titlepage}
% \thispagestyle{empty}
\pagenumbering{roman}
\tableofcontents
\clearpage
\pagenumbering{arabic}
\setcounter{page}{1}
}
% Custom commands
\newcommand{\meta}[2]{%
\vspace{-0.75em}%
~\includegraphics[height=2ex]{misc/icon-time}\enspace\ifx\relax#1\relax\else#1\fi%
\quad%
\includegraphics[height=2ex]{misc/icon-yield}\enspace\ifx\relax#2\relax\else#2\fi%
\vspace{1em}%
}
\newcommand{\footer}[2]{%
\ifx\relax#1\relax\else{%
\enlargethispage{5.75ex}
\let\thefootnote\relax\footnotetext{%
\hspace{-.6em} Source: %
\ifx\relax#2\relax#1\else\href{#1}{#2}\fi%
}\fi%
}
}
\newcommand{\newrecipe}[2]{\clearpage\section{#2}\label{#1}}
\newcommand{\ingGroup}[1]{\vspace{.2ex}\item{\bfseries\color{red2}\hspace{-1em} #1}}
\newcommand{\ingName}[1]{{\color{red3}#1}}
\newcommand{\ingDetail}[1]{\emph{\footnotesize,#1}}
\newcommand{\pagelink}[1]{\tRecipe \tPagePrefix\,{\color{red2}\pageref{#1}}}
\newcommand{\recipelink}[2]{#2 (\tPagePrefix\,\pageref{#1})}
\newcommand{\external}[2]{#2\footnote{\href{#1}{#1}}}
% \newcommand{\external}[2]{#2\footnote{\url{#1}}}
\newenvironment{ingredients}[1]{
\begin{marginfigure}
\small
\ifx\relax#1\relax\else\includegraphics[width=\marginwidth]{#1}\fi
% \subsection*{\sffamily\tIngredients:}
\begin{description}
\RaggedRight\sffamily
}{
\end{description}
\end{marginfigure}
}

View File

@@ -0,0 +1,3 @@
_template: makepdf.tex
---
_model: none

1
src/content/recipes Symbolic link
View File

@@ -0,0 +1 @@
../../data/development/

View File

@@ -4,11 +4,23 @@ from lektor.databags import Databags
from markupsafe import Markup from markupsafe import Markup
from datetime import datetime from datetime import datetime
import unicodedata import unicodedata
import lektor_html_to_tex as tex
# ------- # -------
# Sorting # Sorting
def sorted_images(obj, attr='record_label'):
return sorted(obj.attachments.images, key=lambda x: getattr(x, attr))
def title_image(self, attr='record_label', small=False):
img = (sorted_images(self, attr) or [None])[0]
if img and small:
img = img.thumbnail(200, 150, mode='crop')
return img
def sortKeyInt(x): def sortKeyInt(x):
return int(x[0]) if x[0] else 0 return int(x[0]) if x[0] else 0
@@ -40,17 +52,24 @@ def noUmlaut(text):
def replaceFractions(txt): def replaceFractions(txt):
res = '' res = ' '
for c in u'-–—':
if c in txt:
txt = txt.replace(c, ' ')
for x in txt.split(): for x in txt.split():
if x == '':
continue
try: try:
i = ['1/2', '1/3', '2/3', '1/4', '3/4', '1/8'].index(x) i = ['1/2', '1/3', '2/3', '1/4', '3/4', '1/8'].index(x)
res += [u'½', u'', u'', u'¼', u'¾', u''][i] res += [u'½', u'', u'', u'¼', u'¾', u''][i]
except ValueError: except ValueError:
if x in u'-–—': if x == '':
res += u' - ' res += ''
elif res[-1:] == '':
res += x
else: else:
res += ' ' + x res += ' ' + x
return res.lstrip() return res.lstrip(' ')
def numFillWithText(num, fill=u'', empty=u'', total=5): def numFillWithText(num, fill=u'', empty=u'', total=5):
@@ -186,12 +205,12 @@ class HelperPlugin(Plugin):
partA, partB = partA.split('.', 1) partA, partB = partA.split('.', 1)
return self.translations[alt][partA][partB] return self.translations[alt][partA][partB]
def ingredientsForRecipe(recipe, alt='en'): def ingredientsForRecipe(recipe, alt='en', mode='raw'):
meaList = self.settings[alt]['measures'] meaList = self.settings[alt]['measures']
repFrac = self.settings[alt]['replFrac'] repFrac = self.settings[alt]['replFrac']
for line in recipe['ingredients']: for line in recipe['ingredients']:
line = line.strip() line = tex.raw_text_to_tex(line).strip()
if not line: if not line:
continue continue
elif line.endswith(':'): elif line.endswith(':'):
@@ -210,6 +229,8 @@ class HelperPlugin(Plugin):
# groups[undefinedKey].update(groups.pop('_undefined')) # groups[undefinedKey].update(groups.pop('_undefined'))
return groups.items() return groups.items()
self.env.jinja_env.filters['sorted_images'] = sorted_images
self.env.jinja_env.filters['title_image'] = title_image
self.env.jinja_env.filters['rating'] = numFillWithText self.env.jinja_env.filters['rating'] = numFillWithText
self.env.jinja_env.filters['replaceFractions'] = replaceFractions self.env.jinja_env.filters['replaceFractions'] = replaceFractions
self.env.jinja_env.filters['enumIngredients'] = ingredientsForRecipe self.env.jinja_env.filters['enumIngredients'] = ingredientsForRecipe

5
src/packages/html-to-tex/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
dist
build
*.pyc
*.pyo
*.egg-info

View File

@@ -0,0 +1,62 @@
# character set translations for LaTex special chars
s?&gt.?>?g
s?&lt.?<?g
s?\\?\\backslash ?g
s?{?\\{?g
s?}?\\}?g
s?%?\\%?g
s?\$?\\$?g
s?&?\\&?g
s?#?\\#?g
s?_?\\_?g
s?~?\\~?g
s?\^?\\^?g
s? ?~?g
# Paragraph borders
s?<p>?\\par ?g
s?</p>??g
# Headings
s?<title>\([^<]*\)</title>?\\section*{\1}?g
s?<hn>?\\part{?g
s?</hn>?}?g
s?<h1>?\\section*{?g
s?</h[0-9]>?}?g
s?<h2>?\\subsection*{?g
s?<h3>?\\subsubsection*{?g
s?<h4>?\\paragraph*{?g
s?<h5>?\\paragraph*{?g
s?<h6>?\\subparagraph*{?g
# UL is itemize
s?<ul>?\\begin{itemize}?g
s?</ul>?\\end{itemize}?g
s?<ol>?\\begin{enumerate}?g
s?</ol>?\\end{enumerate}?g
s?<li>?\\item ?g
s?</li>??g
# DL is description
s?<dl>?\\begin{description}?g
s?</dl>?\\end{description}?g
# closing delimiter for DT is first < or end of line which ever comes first NO
#s?<dt>\([^<]*\)<?\\item[\1]<?g
#s?<dt>\([^<]*\)$?\\item[\1]?g
#s?<dd>??g
#s?<dt>?\\item[?g
#s?<dd>?]?g
s?<dt>\([^<]*\)</dt>?\\item[\1]?g
s?<dd>??g
s?</dd>??g
# Italics
s?<it>\([^<]*\)</it>?{\\it \1}?g
s?<em>\([^<]*\)</em>?{\\it \1}?g
s?<b>\([^<]*\)</b>?{\\bf \1}?g
s?<strong>\([^<]*\)</strong>?{\\bf \1}?g
# old unused, because lektor generated internally other urls then output
# s?<a href="\.\.[^"]*/\([^"/][^"/]*\)/*">[^<]*</a>?\\recipelink{\1}?g
# recipe specific
s?<a href="recipes/\([^"/]*\)/*">\([^<]*\)</a>?\\recipelink{\1}{\2}?g
# Get rid of Anchors
s?<a href="\(http[^"]*\)">\([^<]*\)</a>?\\external{\1}{\2}?g
s?<a[^>]*>??g
s?</a>??g
# after href replace
s?"?''?g

View File

@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
from lektor.pluginsystem import Plugin # , get_plugin
import os
import subprocess
my_dir = os.path.dirname(os.path.realpath(__file__))
f_sed_a = os.path.join(my_dir, 'html2latex.sed')
def sed_repl_content(f_sed, content):
with subprocess.Popen(('echo', content), stdout=subprocess.PIPE) as ps:
o = subprocess.check_output(['sed', '-f', f_sed], stdin=ps.stdout)
ps.wait()
return o.decode('utf-8')
def html_to_tex(html):
return sed_repl_content(f_sed_a, html)
def raw_text_to_tex(text):
text = text.replace('\\', '\\backslash ').replace(' ', '~')
for c in '}{%$&#_~^':
if c in text:
text = text.replace(c, '\\' + c)
return text
# return sed_repl_content(f_sed_b, text)
class HtmlToTex(Plugin):
name = u'HTML to TEX converter'
description = u'Will convert html formatted text to (la)tex format.'
def on_before_build_all(self, builder, **extra):
# export current build dir
dest_file = my_dir
for x in range(3):
dest_file = os.path.dirname(dest_file)
dest_file = os.path.join(dest_file, 'extras', 'pdf-export',
'setup-builddir.tex')
with open(dest_file, 'w') as f:
f.write('\\def\\builddir{' + builder.destination_path + '}')
def on_setup_env(self, **extra):
self.env.jinja_env.filters['html_to_tex'] = html_to_tex
self.env.jinja_env.filters['raw_text_to_tex'] = raw_text_to_tex

View File

@@ -0,0 +1,12 @@
from setuptools import setup
setup(
name='lektor-html-to-tex',
py_modules=['lektor_html-to-tex'],
version='1.0',
entry_points={
'lektor.plugins': [
'html-to-tex = lektor_html_to_tex:HtmlToTex',
]
}
)

View File

@@ -2,8 +2,8 @@ CACHE MANIFEST
# Date build: {{ DATE_NOW }} # Date build: {{ DATE_NOW }}
{%- macro _print_(items) -%} {%- macro _print_(items) -%}
{%- for item in items -%} {%- for item in items if not item.endswith('tex') -%}
{{ item|replace('../', '', 1) }} {{ item }}
{% endfor -%} {% endfor -%}
{%- endmacro -%} {%- endmacro -%}
@@ -33,10 +33,10 @@ CACHE MANIFEST
{%- endfor -%} {%- endfor -%}
{%- endif -%} {%- endif -%}
{% set img = x.attachments.images.order_by('record_label').first() -%} {#{% set img = x | title_image(small=True) -%}
{%- if img -%} {%- if img -%}
{{- _add_(cacheList, img.thumbnail(200, 150, 'crop')) -}} {{- _add_(cacheList, img) -}}
{%- endif -%} {%- endif -%}#}
{%- if x.datamodel.has_own_children -%} {%- if x.datamodel.has_own_children -%}
{{- loop(x.children) -}} {{- loop(x.children) -}}

View File

@@ -2,7 +2,7 @@
<div class="tile-grid"> <div class="tile-grid">
{%- for recipe in recipes -%} {%- for recipe in recipes -%}
{%- if limit == 0 or loop.index <= limit -%} {%- if limit == 0 or loop.index <= limit -%}
{%- set img = recipe.attachments.images.order_by('record_label').first() -%} {%- set img = recipe | title_image(small=True) -%}
<a href="{{ recipe|url }}">{#--#} <a href="{{ recipe|url }}">{#--#}
<div class="recipe-tile"> <div class="recipe-tile">
@@ -17,7 +17,7 @@
{#- show image or placeholder text #} {#- show image or placeholder text #}
{% if img -%} {% if img -%}
<img class="lozad" data-src="{{ img.thumbnail(200, 150, 'crop')|url }}"> <img class="lozad" data-src="{{ img|url }}">
{%- else -%} {%- else -%}
<div class="placeholder">No Image</div> <div class="placeholder">No Image</div>
{%- endif -%} {%- endif -%}

31
src/templates/makepdf.tex Normal file
View File

@@ -0,0 +1,31 @@
{%- set recipe_label = localize(this.alt, 'ingredients.recipeLink') %}
{%- for recipe in site.get('/recipes', this.alt).children %}
\newrecipe{ {{- recipe._slug }}}{ {{- recipe.name | raw_text_to_tex }}}
\meta{ {{- recipe.time|duration(this.alt) if recipe.time else '' }}}{ {{- recipe.yield or '' }}}
\footer{ {{- recipe.source | string | raw_text_to_tex or '' }}}{ {{- recipe.source.host | raw_text_to_tex if recipe.source.host else '' }}}
{%- set img = recipe | title_image(small=True) %}
\begin{ingredients}{ {%- if img %}{{ img|url }}{% else %}{% endif %}}
{%- for ing in recipe|enumIngredients(this.alt, mode='tex') %}
{%- if ing['group'] %}
\ingGroup{ {{- ing['group'] | raw_text_to_tex }}}
{%- else %}
\item
{%- if ing['value'] or ing['measure'] -%}
[{%- if ing['value'] %}{{ ing['value'] }}{% endif -%}
{%- if ing['measure'] %}~{{ ing['measure'] }}{% endif -%}]
{%- endif %} \ingName{ {{- ing['name'] -}}}
{%- if ing['note'] %}\ingDetail{
{%- for prt in ing['note'].split() -%}
{%- if prt.startswith('@../') %} \pagelink{ {{- prt[4:-1] -}} }
{%- else %} {{ prt -}}
{%- endif -%}
{%- endfor -%}}
{%- endif -%}
{%- endif -%}
{%- endfor %}
\end{ingredients}
{{ recipe.directions.html | html_to_tex }}
{%- endfor %}

View File

@@ -4,7 +4,7 @@
<article class="recipe"> <article class="recipe">
<!-- date added: {{ this.date }} --> <!-- date added: {{ this.date }} -->
<section id="img-carousel" class="v-scroll center"> <section id="img-carousel" class="v-scroll center">
{%- for img in this.attachments.images.order_by('record_label') %} {%- for img in this | sorted_images %}
<img class="lozad" data-src="{{ img|url }}" height="400"> <img class="lozad" data-src="{{ img|url }}" height="400">
{%- endfor %} {%- endfor %}
</section> </section>