Ok, after some thinking about how to do this with listings
while avoiding manually specifying keywords, I suppose a syntax based solution may work.
I.e. I defined a language for listings
using moredelim
and morestring
to handle the most basic syntax of XML
and get the following results:
the corresponding code is:
\documentclass{report}
\usepackage{listings}
\usepackage{color}
\lstdefinelanguage{XML_SYNTAX}{%
alsoletter=-,
morestring=[b]",stringstyle=\color[rgb]{0,0,1},
moredelim=*[s][{\color[rgb]{0.75,0,0}}]{<}{>},
moredelim=[s][{\color[rgb]{0,0,0}}]{<!--}{-->},
moredelim=[s][{\color[rgb]{0,0.75,0}}]{\ }{=},
moredelim=[s][{\color[rgb]{0,0.75,0}}]{\ }{=} % here there is \tab
}
\lstset{
% Basic design
backgroundcolor=\color[rgb]{0.9,0.9,0.9},
basicstyle={\small\ttfamily},
breaklines=true,
frame=l,
tabsize=2,
% Line numbers
xleftmargin={0.75cm},
numbers=left,
stepnumber=1,
firstnumber=1,
numberfirstline=true,
% HTML formatting
language=XML_SYNTAX,
}
\begin{document}
\begin{lstlisting}
<!-- with tab -->
<list-component data="angularDataObject"
list-type="dataActor">
</list-component>
<!-- with space -->
<list-component data="angularDataObject"
list-type="dataActor">
</list-component>
<!-- some other tag -->
<div id="test"></div>
\end{lstlisting}
\end{document}
For explanation of what the the code does, refer to sections 3.2, 3.3 and 4.18 onwards of the listings
documentation.
Note: for some reason the list-type
attribute is still wrong, although I told listings
to treat -
as a letter with alsoletter={-}
- maybe you can figure out why that is, otherwise I'll have some time for more testing in a few hours.
This was due to my usage of a tab for indentation, rather than a space. As that is fixed now, more debugging to do, since the closing >
of the list-component
tag has now become green as well..
Thanks to @Jubobs this is fixed as well - it was my bad to have an extra *
in the attribute style line. In addition I fixed things to that indentation with tabs also works.
This appears to be a bug in minted
(which I currently maintain). The development version treats style definitions in a slightly different way from the last release, and it is working correctly.
My guess is that in the old treatment of styles, style definitions could overlap somewhat in limited circumstances. Since the bw
style is more minimalistic, it probably doesn't create all of the macros that some styles do. However, those macros would be created by the default
style, and this was causing problems. In the development version, each style has its own completely isolated set of macros, so such conflicts aren't possible.
Best Answer
Regarding
minted
, the answer is: You have to write an extension to the JavaScript lexer of pygmentize or modify a copy of the lexer. See the answers to the question How to add custom C++ keywords to be recognized by Minted? for details.If you are not bound to use
minted
, use the packagelistings
. Here is an example for defining JavaScript highlighting (adapted from this answer to the question language option supported in listings. You can easily define your own classes of keywords and their formatting.