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

Markdown, CommonMark: add support for wiki links. [API change] #7705

Merged
merged 1 commit into from
Jan 15, 2023

Conversation

tarleb
Copy link
Collaborator

@tarleb tarleb commented Nov 21, 2021

Adds commonmark extensions wikilinks_title_after_pipe and
wikilinks_title_before_pipe. The former enables links of style [[Name of page|Title]] and the latter [[Title|Name of page]]. Titles are
optional in both variants, so this works for both:
[[https://example.org]], [[Name of page]].

The writer is modified to render links with title wikilink as a
wikilink if a respective extension is enabled.

Pandoc will use wikilinks_title_after_pipe if both extensions are
enabled.

Closes: #2923

@tarleb
Copy link
Collaborator Author

tarleb commented Nov 21, 2021

Still needs documentation, but I'd already welcome feedback on the general direction.

@jgm
Copy link
Owner

jgm commented Nov 21, 2021

Two thoughts:

  • As noted in the linked issue, in GitHub wikis spaces are converted to - and other symbols are encoded ; I guess the idea would be not to do this conversion automatically, requiring a filter to be used? (Otherwise we'd have to support N different URL munging schemes...)
  • Would it be worth adding a parser for these syntaxes to the regular markdown reader, so the extensions work there as well as commonmark?

@tarleb
Copy link
Collaborator Author

tarleb commented Nov 21, 2021

Given the diversity of wikis with divergent behavior, requiring a filter to match the exact results seems somewhat reasonable to me.

I don't really have a strong opinion about implementing it in regular Markdown. On one hand, it would be nice to nudge more users to use CommonMark. But people relying on citations may not be able to switch. Also, @blackheaven did half of the work already in #6458. I think supporting it there as well would probably be the right choice.

@@ -557,6 +558,11 @@ inlineToMarkdown opts lnk@(Link attr@(ident,classes,kvs) txt (src, tit)) = do
| useAuto -> return $ literal srcSuffix
| otherwise -> return linktext
_ | useAuto -> return $ "<" <> literal srcSuffix <> ">"
| useAuto && useWikilink -> return $ "[[" <> literal srcSuffix <> "]]"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason for using this rather than the more portable <...> syntax?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation here was to preserve as much information as possible, esp the fact that this is a wikilink. That "wiki-autolink" syntax appears to enjoy wide support across implementations. But just falling back to explicit title/url wiki syntax could be saver, if a little less concise.

@jgm jgm added this to To Do in Wiki links Jan 7, 2022
@jgm
Copy link
Owner

jgm commented Mar 24, 2022

@tarleb any thoughts on these comments?

@tarleb
Copy link
Collaborator Author

tarleb commented Mar 25, 2022

I'm sorry, I didn't get around to it yet. It'll probably take another month or so until I can go back and finish this.

@skywind3000
Copy link

any progress ?? really want this feature

Adds the Markdown/CommonMark extensions `wikilinks_title_after_pipe` and
`wikilinks_title_before_pipe`. The former enables links of style `[[Name
of page|Title]]` and the latter `[[Title|Name of page]]`. Titles are
optional in both variants, so this works for both:
`[[https://example.org]]`, `[[Name of page]]`.

The writer is modified to render links with title `wikilink` as a
wikilink if a respective extension is enabled.

Pandoc will use `wikilinks_title_after_pipe` if both extensions are
enabled.

Closes: jgm#2923
@tarleb tarleb marked this pull request as ready for review December 15, 2022 23:21
@tarleb
Copy link
Collaborator Author

tarleb commented Dec 15, 2022

Should be good to go: the Markdown reader now uses basically the same algorithm as CommonMark, with two exceptions: single ] are allowed within the link, while newlines are not. This is modeled after GitHub wiki syntax. (Their implementation is maddening.)

@tarleb tarleb changed the title CommonMark: add support for wiki links. [API change] Markdown, CommonMark: add support for wiki links. [API change] Jan 7, 2023
@jgm jgm merged commit ca6d4bf into jgm:main Jan 15, 2023
@tarleb tarleb deleted the wikilinks branch January 15, 2023 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Markdown reader: add extension for GitHub wiki's internal link syntax [[page name]]
3 participants