twostraws / Ignite

A static site generator for Swift developers.
MIT License
1.71k stars 94 forks source link

Bug: < and > are removed in markdown code snippets #98

Open markstamer opened 3 months ago

markstamer commented 3 months ago

I stumbled across an issue where a code snippet in a markdown file, such as, func store(in set: inout Set<AnyCancellable>) { } is rendered as func store(in set: inout Set) { }. The generic type is simple removed from the Set. Unfortunately I could find the issue in the Ignite framework or if this is an issue with swift-markdown.

twostraws commented 2 months ago

I think this might affect all Markdown libraries, because it's seeing them as HTML. For example, if I paste that same thing into iA Writer on my Mac (my Markdown editor), it does exactly the same thing.

markstamer commented 2 months ago

Outch, so writing an article about Swift generics using the markdown content approach of Ignite could be a bit of a problem.

markstamer commented 2 months ago

I don't have iA Writer to see it for myself but in VSCode previews it works. Maybe there is a misunderstanding in that I meant the code is either inline code or in a code block. Being able to display HTML code in a code block should be working in every Markdown library?

alexito4 commented 2 weeks ago

I've also had some issues with Swift code, specially a for loop with x..<y. I've been digging a bit and it seems that even tho the that code is inside a <pre> tag, that doesn't stop browsers from trying to parse html tags inside it. I've found that changing https://github.com/twostraws/Ignite/blob/02c14aefbd93b8cb31c27515c8104336c80d9d36/Sources/Ignite/Rendering/Markdown/MarkdownToHTML.swift#L126 to escape the string from codeBlock.code solves the problems. It's interesting that there are no more reports of this issue so maybe my conclusions are wrong.