pbek / QOwnNotes

QOwnNotes is a plain-text file notepad and todo-list manager with Markdown support and Nextcloud / ownCloud integration.
https://www.qownnotes.org/
GNU General Public License v2.0
4.61k stars 410 forks source link

scripting feature: pre markdown converter hook #1328

Closed bessw closed 4 years ago

bessw commented 4 years ago

A hook to be able to modify what is passed to the markdown to html converter could be useful.

I think about something like:

/**
 * This function is called before the markdown html of a note is generated
 *
 * It allows you to modify what is passed to the markdown to html converter.
 *
 * The method can for example be used in multiple scripts to render code (like LaTeX math or mermaid) to its grafical representation for the preview.
 *
 * (the modification will only be applyed to the view, but not saved to the actual markdown note file)
 *
 * @param {NoteApi} note - the note object
 * @return {string} the modified note that should be passed to the md2html converter or an empty string if nothing should be modified
 */
function preNoteToMarkdownHtmlHook(note);
pbek commented 4 years ago

Thank you for your suggestion.

pbek commented 4 years ago

19.10.11

pbek commented 4 years ago

There now is a new release, could you please test it and report if it works for you?

bessw commented 4 years ago

The hook works great, I'll create a pull request if I get my script for on the fly LaTeX rendering running.

pbek commented 4 years ago

Great, thank you for testing!

r00tr4v3n commented 4 years ago

@bessw Any update on the script? @pbek Why should I prefer the markdown hook for an (Latex) image instead of the more powerful html with the corresponding hook?

pbek commented 4 years ago

@r00tr4v3n can you please elaborate on your question.

r00tr4v3n commented 4 years ago

You mention LaTeX math and mermaid explicitly in the docs of preNoteToMarkdownHtmlHook. But it only allows changes in the markdown file like replacing a $x^2$ to ![img](path). Why shouldn't be the noteToMarkdownHtmlHook preferred where I can inject a <img src="http://latex-gen.org/x^2"> for the equation? Is there a way to change the html of the preview later on?

bessw commented 4 years ago

I think I was tinkering on two scripts where I tried to use it mainly to get better performance on big notes with LaTeX math:

But after some time I got frustrated by Qt's javascript engine not supporting any library I wanted to use and the preview not supporting any advanced html and thus the need to modify libraries I wanted to use and the need to generate images and saving them in tmp files to display anything except text.

In the end I turned to Electron / cordova, chained some libraries together that are around on the web and got an editor with LaTeX and mermaid working in no time compared to my tries to get this in QOwnNotes using the scripting engine. (since this is a huge project its vary WIP and many features that QOwnNotes has aren't jet or anywhere soon implemented)

r00tr4v3n commented 4 years ago

In the end I turned to Electron / cordova, chained some libraries together that are around on the web and got an editor with LaTeX and mermaid working in no time compared to my tries to get this in QOwnNotes using the scripting engine. (since this is a huge project its vary WIP and many features that QOwnNotes has aren't jet or anywhere soon implemented)

So you build your own Electron based notes app with LaTex support?

bessw commented 4 years ago

I'm trying, but it's a long way.