-
-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add named wikilink processing #624
Conversation
Done. Anything else I missed? |
@hi-learn-triz-and-usit Yes, that's good.
|
Oops! Nevermind, PEBKAC. I didn't even checkout your branch. :-P |
[url] -> pure (url, Nothing) | ||
[url, name] -> pure (url, Just name) | ||
[] -> fail "Empty wiki-link encountered" | ||
_ -> fail ("Multiple pipe ('|') characters encountered; here are the parts: " ++ T.unpack (T.intercalate ", " parts)) |
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'd think sometimes the user might want to use "foo | bar" as the custom text, so in theory we can allow everything to the right of the first |
as the custom text. But let's merge the PR in its current state since this is an improvement.
In emanote, as an aside, this is how we do it (it also obviates the dependency on split
): https://github.com/srid/ema/blob/d8e14ab63a9b25f44591c38c929b04b957f1546d/src/Ema/Helper/Markdown.hs#L206-L211
_ -> fail ("Multiple pipe ('|') characters encountered; here are the parts: " ++ T.unpack (T.intercalate ", " parts)) | ||
cmAutoLink :: CM.IsInline a => Connection -> (Text, Maybe Text) -> a | ||
cmAutoLink conn (url, name) = | ||
CM.link url title $ CM.str (url `fromMaybe` name) |
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.
The operator use of fromMaybe
here is unorthodox. For future reference, I'd just write fromMaybe url name
.
I found that this breaks if the link is inside a markdown pipe table. However it can be fixed by using this syntax: Example |test column 1|test column 2|
|-------------|----------------------|
| apple | [[my-page\|my-text]] | |
@samwalls I think that what breaks is not the parsing of the wikilink but the parsing of the table, which I believe is Pandoc's responsibility. Would you mind checking if the same thing happens in emanote? |
Let me know if there are any issues.
I didn't add tests because there are currently no tests for parsing the wikilinks anyway.
This is technically a breaking change if anyone has pipes in their wikilinks, but I don't think that's a huge problem.
There's also both styles of
[[url|name]]
and[[name|url]]
in use; I went with the former because it works better with the defaults in the recommended VSCode configuration.Resolves #373