-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fix code masked links #117
base: main
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this, the changes here look good to me. A few quick comments below.
Separately, I have put together a proper discord markdown parser for uses elsewhere in the bot and I'm starting to integrate that. At some point it might make sense to try to use that for the wiki code too.
after_escape = true; | ||
} else if (c === "`") { | ||
result += this.substitute_placeholders_no_code(piece); | ||
const end_of_inline_code = index_of_first_unescaped(line, "`", i + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know of any markdown dialects that let you escape \
within code. Github and discord don't so I don't think this is something we should try to support.
if (end_of_inline_code === null) { | ||
return result + line.substring(i); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a ` is unterminated generally it'd make sense to continue substituting through the rest of the string
* - the `result` string (may be empty string) of the substitution, and | ||
* - the `consumed_length` within the original string (may be zero). | ||
*/ | ||
private substitute_placeholders_in_link_mask(line: string, start: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unfortunate to need this but understandable
Prerequisite for: TCCPP/wiki-articles#17
In essence, this PR makes the
ArticleParser
fully aware of masked link syntax. This is absolutely necessary to have reference-style masked links around code blocks. The current approach is to simply partition a line like... into pieces, separated by backticks for inline code. This is broken because the last part of the line is
][ref]
, which is not recognized as a masked link.Additionally, this PR makes it possible to add "self-contained reference-stye links", i.e.
[mask]
, which is equivalent to[mask][mask]
.