EDIT The PGF team reported that this bug was fixed on 2018-12-29
There is a bug in pgf that stops it playing nicely with tikz/pgf. As discovered by michal.h21, the solution is a simple a one line change to pgfsys-tex4ht.def. This bug was reported to the pgf team in 2014, together with a patch, but it remains unfixed as of TeXLive 2017.
Question
Is there a way that I can patch the pgf file pgfsys-tex4ht.def from within LaTeX?
It is possible to fix the problem by editing/replacing the system version of pgfsys-tex4ht.def. What I would like, however, is a way of patching this from inside LaTeX because I want to be able to work around this problem in a package. (In an ideal world, the pgf team would just apply Michael's patch, and so fix the problem once and for all, but they just don't seem to be interested in doing this...)
The actual error that occurs is:
! Undefined control sequence.
\pgfsys@svg@newline ->\Hnewline
l.190 \pgfusepathqfill}
and the fix is to replace the line \def\pgfsys@svg@newline{\Hnewline} in
pgfsys-tex4ht.def with
\def\pgfsys@svg@newline{^^J} %% corrected
I have tried patching this line in many ways, in latex files, my class file, in cfg files and mk4 files. Sadly, nothing that I have tried fixes the problem. For reasons I don't understand, once the pgfsys-tex4ht.def file has been read it is really hard to convince htlatex to use any other definition of \pgfsys@svg@newline or \Hnewline.
To see the bug in action, compile the following really simple MWE with htlatex:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw(0,0)--(10,0);
\end{tikzpicture}
\end{document}
The problem only occurs with htlatex and friends -- the MWE compiles without issue using (pdf)latex.