Skip to content

Commit

Permalink
Mark latex_escape filters as safe, removing the necessarity of using …
Browse files Browse the repository at this point in the history
…raw everywhere
  • Loading branch information
bobvandevijver committed Aug 9, 2019
1 parent 8344b8c commit 8c06be1
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Resources/views/Base/letter.tex.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
\@setplength{refvpos}{ {{- refvpos -}} }
\makeatletter

\date{ {{- date|latex_escape|raw -}} }
\date{ {{- date|latex_escape -}} }

{% include '@BobVLatex/extra_commands.twig.twig' %}

Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Element/blacktitle.tex.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% include '@BobVLatex/extra_commands.twig.twig' %}

{\normalfont\huge\bfseries}{}{\colorbox{black}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textcolor{white}{\textbf{ {{- title|latex_escape|raw -}} }}}}}
{\normalfont\huge\bfseries}{}{\colorbox{black}{\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\textcolor{white}{\textbf{ {{- title|latex_escape -}} }}}}}
\vspace*{-0.2cm}
2 changes: 1 addition & 1 deletion Resources/views/Element/custom_element.tex.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% block bobv_latex_custom_element %}

% Custom element
{{ custom|latex_escape|raw }}
{{ custom|latex_escape }}
{% endblock bobv_latex_custom_element %}
4 changes: 2 additions & 2 deletions Resources/views/Element/graphic.tex.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
\centering
{% endif %}
{% if caption != false %}
\caption{ {{- caption|latex_escape|raw -}} }
\caption{ {{- caption|latex_escape -}} }
{% endif %}
\label{ {{- label|latex_escape|raw -}} }
\label{ {{- label|latex_escape -}} }
\end{figure}

{% endblock bobv_latex_graphic_element %}
6 changes: 3 additions & 3 deletions Resources/views/Element/letter.tex.twig
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{% block bobv_latex_letter_element %}


\begin{letter}{ {{- address|latex_escape|raw -}} }
\begin{letter}{ {{- address|latex_escape -}} }

% Letter element
{% include '@BobVLatex/extra_commands.twig.twig' %}

\opening{ {{- opening|latex_escape|raw -}},}
\opening{ {{- opening|latex_escape -}},}

{{ text|latex_escape|raw }}
{{ text|latex_escape }}

\end{letter}

Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Element/listing.tex.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ enumerate ? '\\begin{enumerate}' : '\\begin{itemize}' }}
{% include '@BobVLatex/extra_commands.twig.twig' %}
{% for item in list %}
\item {{ item|latex_escape|raw }}
\item {{ item|latex_escape }}
{% endfor %}
{{ enumerate ? '\\end{enumerate}' : '\\end{itemize}' }}

Expand Down
12 changes: 6 additions & 6 deletions Resources/views/Element/longtable.tex.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
\begin{longtable}{ {%- for row in rows %}{{ row }} {% endfor -%} }

{% if caption != null %}
\caption{ {{- caption|latex_escape|raw -}} }
\caption{ {{- caption|latex_escape -}} }
{% endif %}

{# First head #}
{% if firsthead != null %}
{{ firsthead|latex_escape(false)|raw }}
{{ firsthead|latex_escape(false) }}
\endfirsthead
{% endif %}

{# Head #}
{% if head != null %}
{{ head|latex_escape(false)|raw }}
{{ head|latex_escape(false) }}
\endhead
{% endif %}

{# Foot #}
{% if foot != null %}
{{ foot|latex_escape(false)|raw }}
{{ foot|latex_escape(false) }}
\endfoot
{% endif %}

{# Last foot #}
{% if lastfoot %}
{{ lastfoot|latex_escape(false)|raw }}
{{ lastfoot|latex_escape(false) }}
\endlastfoot
{% endif %}

Expand All @@ -40,7 +40,7 @@
{% set first = true %}
{% for cellData in rowData['data'] %}
{% if not first %}&{% endif %}
{{ cellData|latex_escape|raw }}
{{ cellData|latex_escape }}
{% set first = false %}
{% endfor %}
\\
Expand Down
4 changes: 2 additions & 2 deletions Resources/views/Element/table.tex.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% if caption != null %}
\begin{table}[h!]
\caption{ {{- caption|latex_escape|raw -}} }
\caption{ {{- caption|latex_escape -}} }
{% endif %}

{% if width == '\\textwidth' %}
Expand All @@ -20,7 +20,7 @@

{% for cellData in rowData['data'] %}
{% if not loop.first %}&{% endif %}
{{ cellData|latex_escape|raw }}
{{ cellData|latex_escape }}
{% endfor %}
\\

Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Element/text.tex.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
% Text element
{% include '@BobVLatex/extra_commands.twig.twig' %}

{{ text|latex_escape|raw }}
{{ text|latex_escape }}
{% endblock bobv_latex_text_element %}
8 changes: 4 additions & 4 deletions Resources/views/Element/titlepage.tex.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
% Title page
\title{
\vspace{ {{ vspace|raw }} }
\textmd{\textbf{ {{- title|latex_escape|raw -}} }}\\
\normalsize\vspace{ {{- vspace_subtitle|latex_escape|raw -}} }\small{ {{- subtitle|latex_escape|raw -}} }
\textmd{\textbf{ {{- title|latex_escape -}} }}\\
\normalsize\vspace{ {{- vspace_subtitle|latex_escape -}} }\small{ {{- subtitle|latex_escape -}} }
}

\author{\textbf{ {{- author|latex_escape|raw -}} }}
\date{ {{- date|latex_escape|raw -}} } % Insert date here if you want it to appear below your name
\author{\textbf{ {{- author|latex_escape -}} }}
\date{ {{- date|latex_escape -}} } % Insert date here if you want it to appear below your name

{% include '@BobVLatex/extra_commands.twig.twig' %}

Expand Down
10 changes: 5 additions & 5 deletions Twig/BobVLatexExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public function __construct() {
* @return array
*/
public function getFilters() {
return array(
new \Twig_SimpleFilter('latex_escape', array($this->parser, 'parseText')),
new \Twig_SimpleFilter('latex_escape_all', array($this, 'latexEscapeAll')),
new \Twig_SimpleFilter('latex_parse_html', array($this->parser, 'parseHtml')),
);
return [
new \Twig_SimpleFilter('latex_escape', [$this->parser, 'parseText'], ['is_safe' => ['all']]),
new \Twig_SimpleFilter('latex_escape_all', [$this, 'latexEscapeAll'], ['is_safe' => ['all']]),
new \Twig_SimpleFilter('latex_parse_html', [$this->parser, 'parseHtml'], ['is_safe' => ['all']]),
];
}

/**
Expand Down

0 comments on commit 8c06be1

Please sign in to comment.