Here is the MWE:
\documentclass[12pt]{article}
\usepackage[compatibility=false]{caption}
\usepackage{subcaption}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc aliquam,
ex et sollicitudin aliquet, magna elit mattis nunc, sed blandit sapien
mi vel risus. Sed sed efficitur nibh. Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
\begin{figure}%
\subcaptionbox{\label{foo}(a)}{}
\subcaptionbox{(b)}{}
\caption{(a) Lorem ipsum dolor sit amet, consectetur adipiscing elit;
(b) nunc aliquam, ex et sollicitudin aliquet, magna elit mattis nunc.}
\end{figure}
Morbi pretium (fig.~\ref{foo})%
, turpis sit amet tristique luctus,
sapien ipsum feugiat diam, et volutpat erat sapien ac massa. Aliquam
erat volutpat.
\end{document}
This compiles correctly with pdflatex (in two passes, obviously), and also with htlatex if I remove the \ref. With the \ref, htlatex gets through the first LaTeX pass all right, then on the second pass I get this:
! Missing \endcsname inserted.
<to be read again>
\protect
l.20 Morbi pretium (fig.~\ref{foo}
)%
?
Package caption Warning: \label without proper reference on input line 14.
See the caption package documentation for explanation.
LaTeX Warning: Reference `foo' on page 4 undefined on input line 20.
! Extra \endcsname.
\:::HRefTag ...sname cw:)Q\aXrefFile #1\endcsname
\relax \:warning {\string ...
l.20 Morbi pretium (fig.~\ref{foo}
)%
?
I'm guessing the problem has something to do with the catcode of :? Or maybe not, but, anyway, I don't know what to do about it.
BTW I at first tried using subfigure, but I found that the \caption command inside a subfigure doesn't result in a span of a distinctive class in the HTML output, so there was no way to apply CSS to the subcaptions.