I would like to create a code style for HTML5 that can be used with the \listings package.
An HTML5 document consists of three languages: CSS, HTML and JavaScript. That makes the whole thing a bit more complicated, because one can only define a keyword field for three languages.
I oriented myself on the style of the NetBeans IDE (Screenshot). I have come very far. Nevertheless, there are some problems ...

Bug #1
The keyword canvas occurs both as an HTML tag and a variable. I want the HTML tag to be blue but not the JavaScript variable within the <script> block.
Bug #2 Because I make blue slashes for the ending HTML tags, the forward slashes in my JavaScript texts also get blue.
Missing Feature #3 Identifiers (#square, .box) in the CSS code are not green.
Can anyone help me to solve these problems? I don't want to use \minted because I've got already a lot of code with \listings in my documents.
I have also created a minimal working example:
\documentclass{scrreprt}
\usepackage{color}
\definecolor{lightgray}{rgb}{0.95, 0.95, 0.95}
\definecolor{darkgray}{rgb}{0.4, 0.4, 0.4}
\definecolor{purple}{rgb}{0.65, 0.12, 0.82}
\definecolor{ocherCode}{rgb}{1, 0.5, 0} % #FF7F00 -> rgb(239, 169, 0)
\definecolor{blueCode}{rgb}{0, 0, 0.93} % #0000EE -> rgb(0, 0, 238)
\definecolor{greenCode}{rgb}{0, 0.6, 0} % #009900 -> rgb(0, 153, 0)
\usepackage{upquote}
\usepackage{listings}
\makeatletter
\lstdefinelanguage{HTML5}{
sensitive=true,
keywords={%
% JavaScript
typeof, new, true, false, catch, function, return, null, catch, switch, var, if, in, while, do, else, case, break,
% HTML
html, title, meta, style, head, body, script, canvas,
% CSS
border:, transform:, -moz-transform:, transition-duration:, transition-property:,
transition-timing-function:
},
% http://texblog.org/tag/otherkeywords/
otherkeywords={<, >, \/},
ndkeywords={class, export, boolean, throw, implements, import, this},
comment=[l]{//},
% morecomment=[s][keywordstyle]{<}{>},
morecomment=[s]{/*}{*/},
morecomment=[s]{<!}{>},
morestring=[b]',
morestring=[b]",
alsoletter={-},
alsodigit={:}
}
\lstset{%
% Basic design
backgroundcolor=\color{lightgray},
basicstyle={\small\ttfamily},
frame=l,
% Line numbers
xleftmargin={0.75cm},
numbers=left,
stepnumber=1,
firstnumber=1,
numberfirstline=true,
% Code design
identifierstyle=\color{black},
keywordstyle=\color{blue}\bfseries,
ndkeywordstyle=\color{greenCode}\bfseries,
stringstyle=\color{ocherCode}\ttfamily,
commentstyle=\color{darkgray}\ttfamily,
% Code
language={HTML5},
tabsize=2,
showtabs=false,
showspaces=false,
showstringspaces=false,
extendedchars=true,
breaklines=true
}
\makeatother
\begin{document}
\begin{lstlisting}
<!DOCTYPE html>
<html>
<head>
<title>Canvas-Rotation</title>
<meta charset="UTF-8" />
<style>
#square {
border: 1px solid black;
transform: scale(10) rotate(3deg) translateX(0px);
-moz-transform: scale(10) rotate(3deg) translateX(0px);
}
.box {
transition-duration: 2s;
transition-property: transform;
transition-timing-function: linear;
}
</style>
</head>
<body>
<canvas id="square" width="200" height="200"></canvas>
<script>
var canvas = document.createElement('canvas');
canvas.width = 200;
canvas.height = 200;
var image = new Image();
image.src = 'images/card.png';
image.width = 114;
image.height = 158;
image.onload = window.setInterval(function() {
rotation();
}, 1000/60);
</script>
</body>
</html>
\end{lstlisting}
\end{document}
I know that the task is pretty tough! But maybe we can do that collectively?
An HTML5 code formatting could be used universally.
P.S. I have read that there are commands like usekeywordsintag and tagstyle. But everytime I want to use them I get the error:
! Package keyval Error: tagstyle undefined.

usekeywordsintagif you uselanguage=htmlsomewhere in your\lstdefinelanguage. From thelistingsmanual, page 28, "The package either use the first order keywords in tags or prints all identifiers inside<>in keyword style." – hpesoj626 Feb 22 at 22:57styleandscript. However,listingsdon't seem to provide such an option. (And neither could I discover a way to hack it in.) I think that this would be a nice feature to have (given that the mixture of languages in a single file or code chunk is becoming more and more common). Maybe you could put forth a feature request to the author/maintainer oflistings? – Sašo Živanović Feb 23 at 18:56