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.
Instead of specifying a proper computer language for syntax highlighting in the environments of the minted
package, you can use the option text
. This will just typeset the input verbatim-like without syntax-highlighting but with the full functionality of the minted
package.
In your case, you probably want to do use \inputminted
with the firstline
and lastline
option. Additionally, just give text
as first mandatory argument:
\documentclass{article}
\usepackage{minted}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.C}
int main() {
printf("hello, world");
return 0;
}
\end{filecontents*}
\begin{document}
\inputminted[firstline=2,lastline=3]{text}{\jobname.C}
\end{document}
Best Answer
You need to write a new lexer and/or formatter for pygmentize in python, see
https://pygments.org/docs/cmdline/#custom-lexers-and-formatters