The problem here is due to how HTML works. As \textcolor
can be used for shorter texts inside paragraphs, it must produce HTML tags that can be used inside paragraphs. As you use \textcolor
for several paragraphs and even list environment, the produced markup is invalid. It works for the first line, as the start of color is marked up correctly, but the browser closes the color element as soon as the list starts.
To solve this, I would introduce a new environment, which can be configured to produce a correct HTML markup. I would modify your file in this way:
\documentclass[12pt]{book}
\usepackage{enumitem}
\usepackage{xcolor}
\newenvironment{colorenv}[1]{\color{#1}}{}
\begin{document}
\begin{colorenv}{blue}
This text is blue.
\begin{enumerate}
\item This text is black, although I would like to have it blue.
\end{enumerate}
\end{colorenv}
\begin{enumerate}
\item
\begin{colorenv}{blue}
This text is still black, although I would like to have it blue.
\end{colorenv}
\end{enumerate}
\end{document}
The colorenv
can be then configured in the configuration file:
\Preamble{xhtml}
\ExplSyntaxOn
\renewenvironment{colorenv}[1]{
\get:xcolorcss{#1}\:colorenv
\ifvmode\IgnorePar\fi\EndP\HCode{<div~style="color:\:colorenv">}\par\ShowPar
}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
\ExplSyntaxOff
\begin{document}
\EndPreamble
The \get:xcolorcss
command converts the color name, such as blue
to hexadecimal RGB value, which can be used in CSS instructions. It is saved in the \:colorenv
command, which we then use in <div~style="color:\:colorenv">
instruction.
This is the result: