michal-h21 / make4ht

Build system for tex4ht
132 stars 15 forks source link

domfilter warnings with tcolorbox, minted, and mintinline environments: 'Unbalanced Tag (/code)' #92

Closed alder711 closed 1 year ago

alder711 commented 1 year ago

Hi, Michal.

I am trying to put minted environments within tcolorbox environments. Here is my main.tex:

\documentclass{article}
        \usepackage{minted}    % For code-like text
        \usepackage{xcolor}    % For text colors
        \usepackage{tcolorbox} % For tip/note boxes

        % Specify tcolorbox options
        \tcbset{
                titlebox=visible
        }
        %define colors
        \definecolor{light-gray}{gray}{0.85}    % Stack Exchange grey
        % Specify minted options
        \setminted{
                numbers=none,
                showspaces=false,
                breaklines=true,
                fontfamily=tt,
                frame=single,
                obeytabs=false,
                stripall=true,
                tabsize=8,
                bgcolor=light-gray
        }
        % Note color box (tcolorbox)
        \newtcolorbox{note}{%
                colback=cyan!5!white,
                colframe=cyan!75!black,
                fonttitle=\bfseries,
                title=Note
        }
        % Warning color box (tcolorbox)
        \newtcolorbox{warning}{%
                colback=orange!5!white,
                colframe=orange!75!black,
                fonttitle=\bfseries,
                title=Warning
        }
\begin{document}
        An inline code: \mintinline{c}{struct latex_t;}

        \begin{note}
                This is a note. It has code:
                \begin{minted}[frame=none]{python}
def function:
        print("%")
        return
                \end{minted}
        \end{note}

        \begin{warning}
                This is a warning!
        \end{warning}
\end{document}

When I compile with make4ht --format html5+latexmk_build --backend tex4ht --loglevel info --shell-escape main.tex, everything compiles fine, except that I see the following warnings:

[WARNING] domfilter: DOM parsing of main.html failed:
[WARNING] domfilter: /usr/share/texmf-dist/tex/luatex/luaxml/luaxml-mod-xml.lua:175: Unbalanced Tag (/code) [char=597]

Looking at the generated main.html, it seems to be an issue with the <span> tags, specifically an unclosed tag:

<!--l. 40--><p class="noindent" >An inline code: <code class="minted-inline"><span 
class="colorbox" id="colorbox1"><span id="textcolor2">struct</span><span id="textcolor3"> </span><span id="textcolor4">latex_t</span>;<!--
</span>--></code>

If I remove the following line from main.tex, everything compiles fine:

An inline code: \mintinline{c}{struct latex_t;}

Software versions:

Any insight would be appreciated. Thanks in advance!

alder711 commented 1 year ago

Update: it looks like if I comment out the line

\Configure{MintedHideNewline}{\HCode{<!--}}{\HCode{-->}}

in minted.4ht (which on Arch Linux is at /usr/share/texmf-dist/tex/generic/tex4ht/minted.4ht), the errors disappear. I am not sure if this is the correct aproach, but I did notice that the closing tag for the troublesome <span> above was indeed present, but commented out, which is why I tried this solution. Please let me know if this is not the correct solution though, @michal-h21 .

michal-h21 commented 1 year ago

Thanks for the report. The MintedHideNewline configuration tried to fix some issue, probably in the TeX4ht documentation generation, but I cannot reproduce it now, so I think we can safely remove it. I've updated TeX4ht sources, so the issue should be gone after TeX Live update.

alder711 commented 1 year ago

Awesome, thanks @michal-h21 . I'll close the issue.