Skip to content

Update htmlcdparser.py#19

Open
7MS8 wants to merge 5 commits into
cetinkaya:masterfrom
7MS8:master
Open

Update htmlcdparser.py#19
7MS8 wants to merge 5 commits into
cetinkaya:masterfrom
7MS8:master

Conversation

@7MS8

@7MS8 7MS8 commented Apr 12, 2026

Copy link
Copy Markdown

Add KaTeX/LaTeX equation rendering
When pasting from Claude.ai or copilot or other sites that use KaTeX, LaTeX equations are now automatically rendered to PNG and embedded as images in Zim.
How it works: the parser detects tags inside KaTeX HTML, extracts the raw LaTeX source, and renders it to PNG via latex/dvipng (the same tools used by Zim's built-in Equation Editor plugin). The PNG is saved to the page's attachments folder and embedded as {{./eq_....png}}.
Requirements: latex and dvipng must be installed (same dependency as Zim's Equation Editor plugin).
Also included: a few minor fixes (hr tag parsing, Umlaut normalization, regex multiline flags, dash escaping).

Fix: hr tag blocking subsequent tags + LaTeX/KaTeX rendering
Removed hr from beg/end dicts – it was setting inside_tag="hr" and blocking all following tags Added inline LaTeX rendering: KaTeX tags are parsed for raw LaTeX source and rendered to PNG via latex/dvipng Added NFC Unicode normalization to fix Umlaut parsing (ä, ö, ü) Added re.MULTILINE to line-start regex patterns
Added escaping for 5+ dash sequences (Zim horizontal rule syntax)

7MS8 added 5 commits April 12, 2026 14:26
Fix: hr tag blocking subsequent tags + LaTeX/KaTeX rendering

Removed hr from beg/end dicts – it was setting inside_tag="hr" and blocking all following tags
Added inline LaTeX rendering: KaTeX <annotation> tags are parsed for raw LaTeX source and rendered to PNG via latex/dvipng
Added NFC Unicode normalization to fix Umlaut parsing (ä, ö, ü)
Added re.MULTILINE to line-start regex patterns
Added escaping for 5+ dash sequences (Zim horizontal rule syntax)
mathml to png for copilot
latex font conf
added dependency description
Comment thread htmlcdparser.py
if loglines is not None:
loglines.append(str(msg))

def _show_debug_terminal(lines):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all operating systems have /tmp folder. Is there another way to show the debug log?

Comment thread htmlcdparser.py
"tr": "",
"th": "|",
"td": "|",
"hr": "-----\n",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to be related to latex.

Comment thread htmlcdparser.py
return
if tag == "blockquote":
self.inside_blockquote = True
#If the tag a is in a non-nestable one, tag a prevails and the previous one is deleted. In block sentences it is not done

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to keep the comments and existing code for parsing html?

Comment thread htmlcdparser.py
#end of nestable tag
if self.inside_tag == tag:
self.inside_tag = "";
#Init href of tag a

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to keep these comments?

Comment thread htmlcdparser.py
return
if tag == "blockquote":
self.inside_blockquote = False
#end of nestable tag

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to keep these comments?

@cetinkaya

Copy link
Copy Markdown
Owner

This is perhaps a useful functionality, but too many parts of the code are being changed at once. Please let me take some time to review the code and test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants