Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown Export Strikethrough #1666

Closed
Wingysam opened this issue Feb 20, 2021 · 11 comments
Closed

Markdown Export Strikethrough #1666

Wingysam opened this issue Feb 20, 2021 · 11 comments

Comments

@Wingysam
Copy link

Trilium 0.45.8

When exporting a note to Markdown, strikethrough text is exported with only one tilde on each side, when there should be two.

Expected behavior: ~~strikethrough~~

Actual behavior: ~not strikethrough~

@zadam
Copy link
Owner

zadam commented Feb 20, 2021

This is a bug in turndown library - see mixmark-io/turndown-plugin-gfm#12

Unfortunately it looks like it's not maintained anymore :(

@Wingysam
Copy link
Author

It looks like it may be possible to remove the plugin's strike-through rule and replace it with a new one (rules.js#L36). Would you accept a pull request that does this?

@zadam
Copy link
Owner

zadam commented Feb 21, 2021

I think it would be much better to handle this upstream in the library itself. There's e.g. https://github.com/laurent22/joplin-turndown-plugin-gfm for which seems to be maintained and might accept such PR.

@martinkoutecky
Copy link

Hijacking this issue to say that I'm also not happy with the markdown export, specifically the way math is exported using backslashes and parentheses (\\(x^2\\)) which is not understood by e.g. github or vscode. Worse, backslashes in math mode get doubled, so \epsilon becomes \\epsilon etc. (Also, some things get unnecessarily escaped which ends up rendered correctly but is annoying to read, specifically [1] becomes \[1\]or - becomes \- etc.)

What would it take to change the exported markdown format to use the dollar-sign format ($x^2$) instead, and to get rid of the double backslashes?

@zadam
Copy link
Owner

zadam commented Mar 16, 2021

That's a complicated issue since ckeditor5-math saves the math expressions into HTML as e.g. <span class="math-tex">\(a/b\)</span>

Markdown converter doesn't know that this is a math syntax and converts it generically ...

@martinkoutecky
Copy link

I see. At which point in the conversion process would this need to be intercepted? The stuff that I encountered is actually simple to reverse - convert \\( to $ etc. But I suppose we should know we're doing this in some text which originated from a math-tex span, otherwise we would convert what was meant to look like \( to $ which would be incorrect, right?

@zadam
Copy link
Owner

zadam commented Mar 17, 2021

Ideally there's no interception and it's fixed at the source. You might try to open an issue in https://github.com/isaul32/ckeditor5-math to discuss why does this plugin uses this format ...

@martinkoutecky
Copy link

It's relatively clear to me why they use this format - the TeX renderer they use (I guess KaTeX?) allows the use of both the dollar-sign delimiter and the \(...\) delimitation and I suppose this is more convenient for them. They don't have to care about it being easily convertible to markdown.

How does export to markdown work? Is there an HTML->MD converter which gets called? I think that's the place where it needs to be fixed, because the HTML is correct as it is, no reason or even no way to fix it.

@zadam
Copy link
Owner

zadam commented Mar 18, 2021

Yes, turndown and joplin-turndown-plugin-gfm libraries are used to convert HTML to Markdown.

But somehow I'm not sure if that's a good place to fix it. This structure (span, class) is specific to ckeditor5-markdown.

Maybe it would be the easiest to just hack it using a simple regex in https://github.com/zadam/trilium/blob/master/src/services/export/md.js

@martinkoutecky
Copy link

That might be possible. One would replace <span class="math-tex">\(a/b\)</span> with $a/b$ ... but then how do you prevent turndown from escaping everything inside the dollar signs? Also, how would turndown know NOT to escape these dollar signs (but escape others)? I'd like to help, but as you see I'm unclear on what the flow is and none of the places you pointed out affords an easy fix yet.

@meichthys
Copy link
Collaborator

Trilium has entered maintenance mode. Future enhancements will be addressed in TrilumNext: TriliumNext#117

@meichthys meichthys closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
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

No branches or pull requests

4 participants