Markdown escaping problem #940

Open
opened 2025-11-02 03:42:30 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @michaelkuhn on GitHub (Aug 4, 2017).

Description

Escaping short links ([[link]]) does not work at the moment. Even if I type \[\[link\]\], Gitea still converts it into a link.

This is probably due to how Markdown is handled in markdown.go:

result := RenderRaw(rawBytes, urlPrefix, isWikiMarkdown)
result = PostProcess(result, urlPrefix, metas, isWikiMarkdown)

RenderRaw seems to remove the escaping backslashes, PostProcess then only sees a normal short link. Switching the order of the calls is also problematic because PostProcess converts links that it should not (for example, https://pthree.org/2012/04/17/install-zfs-on-debian-gnulinux/ is recognized as an issue link due to the numbers).

Originally created by @michaelkuhn on GitHub (Aug 4, 2017). - Gitea version (or commit ref): v1.1.0-467-g34df9def - Can you reproduce the bug at https://try.gitea.io: - [x] Yes: https://try.gitea.io/4kr_5fc85lzjshor/4kr_5fc85lzjshor/wiki/Home ## Description Escaping short links (`[[link]]`) does not work at the moment. Even if I type `\[\[link\]\]`, Gitea still converts it into a link. This is probably due to how Markdown is handled in `markdown.go`: ``` result := RenderRaw(rawBytes, urlPrefix, isWikiMarkdown) result = PostProcess(result, urlPrefix, metas, isWikiMarkdown) ``` `RenderRaw` seems to remove the escaping backslashes, `PostProcess` then only sees a normal short link. Switching the order of the calls is also problematic because `PostProcess` converts links that it should not (for example, https://pthree.org/2012/04/17/install-zfs-on-debian-gnulinux/ is recognized as an issue link due to the numbers).
GiteaMirror added the issue/confirmedtype/bug labels 2025-11-02 03:42:31 -06:00
Author
Owner

@jeromelebleu commented on GitHub (Aug 6, 2017):

Is #2168 can be related to this bug in a way? Or could this issue help to resolve it - or at least opens the discussion of the way to go? In my opinion, we should not have to escape short links in a code block...

Thanks in advance!

@jeromelebleu commented on GitHub (Aug 6, 2017): Is #2168 can be related to this bug in a way? Or could this issue help to resolve it - or at least opens the discussion of the way to go? In my opinion, we should not have to escape short links in a code block... Thanks in advance!
Author
Owner

@stale[bot] commented on GitHub (Feb 13, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Feb 13, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@michaelkuhn commented on GitHub (Feb 18, 2019):

FYI: This still happens with Gitea 1.7.

@michaelkuhn commented on GitHub (Feb 18, 2019): FYI: This still happens with Gitea 1.7.
Author
Owner

@schmittlauch commented on GitHub (Oct 21, 2019):

I just ran into this when trying to escape backticks inside a shell command, so they're getting displayed inside an inline code sample:

`foo=\`pwd\`/bin`
@schmittlauch commented on GitHub (Oct 21, 2019): I just ran into this when trying to escape backticks inside a shell command, so they're getting displayed inside an inline code sample: ``` `foo=\`pwd\`/bin` ```
Author
Owner

@lafriks commented on GitHub (Oct 23, 2019):

@schmittlauch that is different, to to use backtick in code you should use:

``foo=`pwd`/bin``
@lafriks commented on GitHub (Oct 23, 2019): @schmittlauch that is different, to to use backtick in code you should use: ``` ``foo=`pwd`/bin`` ```
Author
Owner

@silkentrance commented on GitHub (Jun 22, 2024):

with 1.21.11 you can use

\[[[woo]]

which renders as

[[woo]]

if you'd used

\[[woo]]

then it would render as

[woo]]

so there is still some bug in there somewhere

@silkentrance commented on GitHub (Jun 22, 2024): with 1.21.11 you can use ``` \[[[woo]] ``` which renders as ``` [[woo]] ``` if you'd used ``` \[[woo]] ``` then it would render as ``` [woo]] ``` so there is still some bug in there somewhere
Author
Owner

@wxiaoguang commented on GitHub (Apr 5, 2025):

The problem is that the render parsers are wrong. At the moment, the markdown render works like this:

MarkdownText 
-> GoldmarkMarkdownRender(...EmphasisParser,List,etc...) 
-> IntermediateHTML 
-> PostProcess(...Linkify,etc...) 
-> FinalHTML

In the GoldmarkMarkdownRender step, it renders \[\[ to [[, then in PostProcess step, Linkify translates more Markdown syntaxes including [[.

The fix should be like this: move the Linkify from PostProcess to GoldmarkMarkdownRender step. And this fix will also fix "Markdown Formatting tokens in URLs should not be parsed #17958" if we could make the Linkify have a proper priority with EmphasisParser

@wxiaoguang commented on GitHub (Apr 5, 2025): The problem is that the render parsers are wrong. At the moment, the markdown render works like this: ``` MarkdownText -> GoldmarkMarkdownRender(...EmphasisParser,List,etc...) -> IntermediateHTML -> PostProcess(...Linkify,etc...) -> FinalHTML ``` In the `GoldmarkMarkdownRender` step, it renders `\[\[` to `[[`, then in `PostProcess` step, `Linkify` translates more Markdown syntaxes including `[[`. The fix should be like this: move the `Linkify` from PostProcess to GoldmarkMarkdownRender step. And this fix will also fix "Markdown Formatting tokens in URLs should not be parsed #17958" if we could make the `Linkify` have a proper priority with `EmphasisParser`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#940