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

Fix code masked links #117

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Eisenwave
Copy link
Contributor

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

[`mask`][ref]

... 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].

Copy link

Copy link
Member

@jeremy-rifkin jeremy-rifkin left a 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);
Copy link
Member

@jeremy-rifkin jeremy-rifkin Dec 3, 2024

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.

Comment on lines +244 to +246
if (end_of_inline_code === null) {
return result + line.substring(i);
}
Copy link
Member

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) {
Copy link
Member

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

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

Successfully merging this pull request may close these issues.

2 participants