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 reader: add extension for GitHub wiki's internal link syntax [[page name]] #2923

Closed
ferventcoder opened this issue May 17, 2016 · 10 comments · Fixed by #6458 or #7705
Closed

Comments

@ferventcoder
Copy link

Forgive me if this has already been noted as an issue but I did a bit of searching through issues and online and didn't turn up with anything.

I'm on the latest version of Pandoc (1.17.0.2) and I'm attempting to use markdown_github to convert to HTML. I'm noticing that Pandoc does not convert links that look like the following:

  • [[example link|MarkdownPage]]
  • [[MarkdownPage]]

It's possible we are using outdated constructs, but GitHub has supported this for years. I noticed that Sublime supports the second but not the first with it's regular markdown preview tool.

The command I'm running:
pandoc --from markdown_github+simple_tables+native_spans+native_divs+multiline_tables --to html5 [..snip..]

Is this something that could be added for conversion? Or is there an extension that already does this that I may have missed?

@jgm
Copy link
Owner

jgm commented May 17, 2016

The syntax is documented here.
However, I believe it only works for GitHub wikis, and not in other contexts (e.g. bug reports). Proof:
[[example link|MarkdownPage]]

It would be worth adding an extension for this.

@ferventcoder
Copy link
Author

Thanks @jgm! Pandoc is pretty amazing! I'll admit I haven't read the source, but this is the regex I'm using to do this conversion now:
https://github.com/ferventcoder/chocolatey.org/blob/45765dd4cc2f9d2675d0f48fd4dd60669afb8bf8/UpdateDocumentation.ps1#L12-L24

@mb21 mb21 changed the title Markdown conversion does not appear to convert [[name|link]] to urls Markdown reader: add extension for GitHub wiki's internal link syntax [[page name]] Sep 14, 2019
blackheaven added a commit to blackheaven/pandoc that referenced this issue Jun 14, 2020
blackheaven added a commit to blackheaven/pandoc that referenced this issue Jun 14, 2020
Changes overview:

 * Add a `Ext_markdown_github_wikilink` extension
   * Added in the `githubMarkdownExtensions` list
   * Added in the `getAllExtensions` list
 * Add the parser `githubWikiLink` in `Text.Pandoc.Readers.Markdown`
   * Added it high in the `inline` parsers list
 * Add two tests, one for each form
blackheaven added a commit to blackheaven/pandoc that referenced this issue Jun 14, 2020
Changes overview:

 * Add a `Ext_markdown_github_wikilink` extension
   * Added in the `githubMarkdownExtensions` list
   * Added in the `getAllExtensions` list
 * Add the parser `githubWikiLink` in `Text.Pandoc.Readers.Markdown`
   * Added it high in the `inline` parsers list
 * Add two tests, one for each form
blackheaven added a commit to blackheaven/pandoc that referenced this issue Aug 6, 2020
Changes overview:

 * Add a `Ext_markdown_github_wikilink` extension
   * Added in the `githubMarkdownExtensions` list
   * Added in the `getAllExtensions` list
 * Add the parser `githubWikiLink` in `Text.Pandoc.Readers.Markdown`
   * Added it high in the `inline` parsers list
 * Add two tests, one for each form
blackheaven added a commit to blackheaven/pandoc that referenced this issue Jan 16, 2021
Changes overview:

 * Add a `Ext_markdown_github_wikilink` extension
   * Added in the `githubMarkdownExtensions` list
   * Added in the `getAllExtensions` list
 * Add the parser `githubWikiLink` in `Text.Pandoc.Readers.Markdown`
   * Added it high in the `inline` parsers list
 * Add two tests, one for each form
@jgm jgm closed this as completed in #6458 Jan 17, 2021
jgm pushed a commit that referenced this issue Jan 17, 2021
Canges overview:

 * Add a `Ext_markdown_github_wikilink` constructor to `Extension` [API change].
 * Add the parser `githubWikiLink` in `Text.Pandoc.Readers.Markdown`
 * Add tests.
jgm added a commit that referenced this issue Jan 17, 2021
…#6458)"

This reverts commit 6efd346.

Since this extension is designed to be used with
GitHub markdown (gfm), we need to implement the parser
as a commonmark extension (commonmark-extensions),
rather than in pandoc's markdown reader.  When that is
done, we can add it here.
@jgm jgm reopened this Jan 17, 2021
@jgm
Copy link
Owner

jgm commented Jan 17, 2021

Re-opening, on the realization that we really need the parser in a commonmark extension (so it can be used withgfm). Once that is available, we could also add a parser to pandoc's markdown reader, but I don't want to just add it to the latter; it will cause too much confusion.

@jgm
Copy link
Owner

jgm commented Jan 17, 2021

The tests and extension module work in #6458 will be useful when the commonmark-hs extension is available.

@jgm
Copy link
Owner

jgm commented Aug 27, 2021

The wikilinks extension is available now for commonmork-hs:
https://hackage.haskell.org/package/commonmark-extensions-0.2.1.2/docs/Commonmark-Extensions-Wikilinks.html
So now there is no obstacle to supporting this syntax.

@jgm
Copy link
Owner

jgm commented Aug 27, 2021

Note that in commonmark-hs we support two forms of the extension,
wikilinks_title_before_pipe
wikilinks_title_after_pipe
since some markdown wiki formats put the title before the pipe (like GitHub) and others after.
It would be useful to support both in pandoc.

@jgm
Copy link
Owner

jgm commented Aug 27, 2021

I think it would be good to support multiple markdown wikilink syntaxes, not just the one used in GitHub wikis, but those used in popular note taking applications like obsidian and roam.
The problem is, these are all slightly different.
One difference is whether the title comes before or after the pipe.
Another is whether the URL is munged somehow (e.g. in GitHub wikis spaces are converted to - and other symbols are encoded).
Supporting the two pipe positions seems feasible, but if we try to support every other dimension of variation, it quickly gets out of hand.
Hence I'd favor supporting just the two pipe positions, and encoding spaces as well as other symbols in the URL; users who want to generate correct links for GitHub wikis would then need to use a small filter to change these spaces to dashes. Not sure though.

@edrex
Copy link

edrex commented Oct 16, 2021

Emanote (a publishing tool compatible with Obsidian and Foam) has its own implementation of the [[Page|Label]] syntax used by most wikis but it would be nice to switch to an upstream one.

https://github.com/srid/emanote/blob/master/src/Emanote/Pandoc/Markdown/Syntax/WikiLink.hs

tarleb added a commit to tarleb/pandoc that referenced this issue 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: jgm#2923
tarleb added a commit to tarleb/pandoc that referenced this issue 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: jgm#2923
tarleb added a commit to tarleb/pandoc that referenced this issue Dec 15, 2022
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
@jgm jgm closed this as completed in #7705 Jan 15, 2023
jgm pushed a commit that referenced this issue Jan 15, 2023
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: #2923
@mebu83
Copy link

mebu83 commented Jan 18, 2023

Thanks so much! This is awesome!

liruqi pushed a commit to chinapedia/pandoc that referenced this issue Mar 3, 2023
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
@anutator
Copy link

Please add mediawiki images conversion:
![[image1.png]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment