Problem statement
I have several code listings containing HTML markup in my latex files. These listings contain multiple custom html tags (created in combination with corresponding AngularJS directives).
Such an HTML fragment could look for example like this:
<list-component data="angularDataObject"
list-type="dataActor">
</list-component>
<div id="test"></div>
Originating from a CamelCase name of a directive listComponent
in JavaScript, a dash is added in between resulting in list-component
to maintain code readability.
I tried using both listings and minted for syntax highlighting:
listings
Using listings I achieved the following result:
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=HTML]
<list-component data="angularDataObject"
list-type="dataActor">
</list-component>
<div id="test"></div>
\end{lstlisting}
\end{document}
As you can see, the tag name is not identified, neither the custom attribute list-type
. I think the word type
is recognized as standard html attribute and therefore highlighted.
minted
Using minted I achieved the following result:
\documentclass{article}
\usepackage{minted}
\usemintedstyle{borland}
\begin{document}
\begin{minted}{html}
<list-component data="angularDataObject"
list-type="dataActor">
</list-component>
<div id="test"></div>
\end{minted}
\end{document}
The minted result is even worse, as the word list
is highlighted before the dash - component
by contrast isn't, even though list
is not an HTML standard tag. Attributes look fine this time, but the closing tag is not identified at all and gets an ugly background behind the opening bracket <
.
My goal
I search for a plugin that is able to automaticly detect and highlight custom tags, without needing to add them each by each - since I might be unsure which tags I'll use in the future. Further it would be great to identify custom attributes, but I could go without that, if attributes are not highlighted at all. Finally it is essential that closing tags are at least highlighted the same way as the opening ones were highlighted before.
Thanks in advance for your generous help and advices!
By the way, while typing this question and adding language data for different code highlighting I discovered that Google Code prettifier is analyzing and displaying my code perfectly :-/
Other related TEX.SE questions
\listings code style for HTML5 (CSS, HTML, JavaScript) In this solution any tags must be noted in the settings in order to be identified.
How to highlight own keywords in HTML lstlistings? This solution allows individual highlighting of code parts, but changes need to be hard-coded into the listing. This ruins readability in the TEX markup.
How to use angle brackets for a keyword in \listings? This solution reuires once again that all tags are defined a priori.
listings
package does allow for additional, manually specified, keywords.. see section 3 of the documentationdocumentclass
and document-begin/-end before. The minted example is not totaly minimal, as the style definition is not needed, but as I already usedborland
for the screenshot, I would stick with that. The HTML markup contains all required items and for comparison a standrad div-tag with an attribute. Your suggested solution, by adding tags to listingsis already covered within two of the three referenced questions and is not exactly what I try to achieve. Nonetheless thanks for your idea! =)