I managed to "solve" this by replicating the keywordstyle within the literate set. There is probably a better way to do it, but this works well for a few keywords.
\documentclass{article}
\usepackage[brazilian]{babel}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage{listings}
\newcommand\keywordstyle[1]{{\color{red}\bfseries{#1}}}%
\lstset{%
literate=
{Ç}{{\c{C}}}1
{Ã}{{\~{A}}}1
{á}{{\'{a}}}1
{ENTÃO}{{\keywordstyle{ENT\~{A}O}}}5
{SENÃO}{{\keywordstyle{SEN\~{A}O}}}5
{FAÇA}{{\keywordstyle{FA\c{C}A}}}4
}
\lstdefinelanguage{pseudo}
{
extendedchars=true,
alsoletter={_},
morekeywords={ENQUANTO,PARA,SE,DECLARA,DECLARE,E,OU,FIM_ENQUANTO,FIM_PARA},
ndkeywords={NUMERO,TEXTO,LEIA,ESCREVA},
sensitive=true,
morecomment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]"
}
\begin{document}
\lstinputlisting[language=pseudo]{foo.pseudo}
\end{document}
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.
Best Answer
If you want to get more syntax highlighting than is provided by the HTML style of
listings
then you could do one of the following:listings
. See section 4.18 Language Definition in thelistings
manual.minted
.minted
includes support for regular Django templates (html+django
) and for templates written in Jinja (html+jinja
). See answer to Listings alternative