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

Add named wikilink processing #624

Merged
merged 3 commits into from
May 24, 2021
Merged

Conversation

hi-learn-triz-and-usit
Copy link
Contributor

@hi-learn-triz-and-usit hi-learn-triz-and-usit commented May 23, 2021

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

@hi-learn-triz-and-usit
Copy link
Contributor Author

Could you update the docs to mention this? https://neuron.zettel.page/linking
Also please update CHANGELOG.md and the version in neuron.cabal (1.9.x.y -> 1.9.(x+1).0)

Done.

Anything else I missed?

@srid
Copy link
Owner

srid commented May 24, 2021

@hi-learn-triz-and-usit Yes, that's good.

I tested this locally, but it doesn't work? [...]

@srid
Copy link
Owner

srid commented May 24, 2021

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))
Copy link
Owner

@srid srid May 24, 2021

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)
Copy link
Owner

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.

@srid srid merged commit 164956f into srid:master May 24, 2021
@samwalls
Copy link
Contributor

samwalls commented May 27, 2021

I found that this breaks if the link is inside a markdown pipe table. However it can be fixed by using this syntax: [[my-page\|my-text]]. The use of tables should maybe be documented somewhere if not already, and with this information.

Example

|test column 1|test column 2|
|-------------|----------------------|
| apple       | [[my-page\|my-text]] |

@hi-learn-triz-and-usit
Copy link
Contributor Author

@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?

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.

Allow custom link text in wiki links
3 participants