HermanMartinus / bearblog

Free, no-nonsense, super fast blogging.
MIT License
2.36k stars 73 forks source link

Cant escape characters #245

Open Deijin27 opened 11 months ago

Deijin27 commented 11 months ago

I was trying to type a less-than sign into a post, escaping it with a backslash, but it is not visible in the published page. It works when not followed by a letter immediately.

I tried this
\<th\>

Also tried this
&lt;th&gt;

Is it possible to support this?

Deijin27 commented 11 months ago

The commonmark spec does suggest that it should be possible in example 14

https://spec.commonmark.org/0.30/#backslash-escapes

I guess it's just a niche situation that the library you use doesnt account for.

HermanMartinus commented 10 months ago

I did a dig into it and it does seem to be a quirk of the Mistune markdown parser. There is an option to escape all (which would break a few too many things) but no specific break character.

One thing I've noticed is that if there is a space present then it renders fine (with the space though): < th > and &lt; th &gt; both render as < th > < th >

This also only happens if there are opening and closing braces, so something like Less<More works fine. One reason I think this hasn't been pointed out before is that generally if you're trying to represent raw HTML as text you can just do it in a code block. This however doesn't solve for instances where Less<More>Less which would be interpreted as HTML-ish.

I'll give this some thought, but it seems like a minor issue in the grander scheme of things and easy to work around.

Thanks for pointing this out @Deijin27!

Deijin27 commented 10 months ago

I ran into the issue using an app called markdownr to convert html to markdown for offline viewing, and tried to create a page on bearblog to test more, and found bear had issues too but the opposite direction 😄

<> is often used when describing spelling reforms, to describe the letters that represent a sound. See this example

It would be easy enough to put them in inline code blocks, so it's very minor issue easy to workaround I agree.

HermanMartinus commented 10 months ago

😄 Yeah. Unfortunately we can't have one without the other. Either HTML is supported or not. The alternative being to include an explicit attribute of something like render_as: text/markdown/html which seems like overkill to me.

I appreciate having these cases pointed out, though.