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

Unable to parse relative URL to parent directories #819

Open
AmadeusW opened this issue Sep 30, 2024 · 3 comments
Open

Unable to parse relative URL to parent directories #819

AmadeusW opened this issue Sep 30, 2024 · 3 comments
Labels

Comments

@AmadeusW
Copy link

I'm writing a Markdown renderer that formats user .md files into navigable .html pages.
Some user documents contain relative paths to a parent directory, like these:

[example link](..\example.md)
[example link](\..\example.md)

Currently, LinkHelper.TryParseInlineLink calls LinkHelper.TryParseInlineLink, which calls LinkHelper.TryParseUrl leaving isAutoLink unset as false. This means that TryParseUrl treats the slash as escape character and effectively removes it.
The character is not recorded as a part of trivia, and there's no way to infer its presence by examining the AST.

Setting isAutoLink to true seems to address this issue, but I don't know what auto link is, and whether this is an appropriate wokaround.
I was thinking about a solution where we'd set a property on InlineProcessor.MarkdownPaserContext to influence LinkInlineParser.TryProcessLinkOrImage, but would like to get your opinion before making code changes.

@AmadeusW AmadeusW changed the title Unable to parse relative URL that starts with \.. Unable to parse relative URL to parent directories Sep 30, 2024
@AmadeusW
Copy link
Author

@xoofx I'd appreciate your opinion how to best fix this, or how to override the behavior of LinkInlineParser

@xoofx
Copy link
Owner

xoofx commented Oct 15, 2024

I would use / instead of \ and you wouldn't have to change the parser:

[example link](../example.md)
[example link](/../example.md)

None of the CommonMark parser are supporting \ in that case and they all trim it in the same way here

@xoofx xoofx added the question label Oct 15, 2024
@jefflomax
Copy link

While I do not recommend it - I pre-parsed markdown to rewrite the links to the standard, then passed that to this wonderful library. It's a pain, if you can get escaped unix style paths that's better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants