Skip to content

Conversation

@chrisjsewell
Copy link
Member

The myst_url_schemes configuration has been extended, in a back-compatible manner,
to also allow writing as a dictionary, with customisations of the link URL/text, via templates, such as:

myst_url_schemes = {
    "http": None,
	"https": None,
    "wiki": "https://en.wikipedia.org/wiki/{{path}}#{{fragment}}",
    "gh-issue": {
        "url": "https://github.com/executablebooks/MyST-Parser/issue/{{path}}#{{fragment}}",
        "title": "Issue #{{path}}",
        "classes": ["github"],
    },
}

Allowing for <gh-issue:639> and [URI](wiki:Uniform_Resource_Identifier#URI_references).

The inline_attrs extension also allows for specific links to be marked as external, using [](my-link){.external}.

@codecov
Copy link

codecov bot commented Feb 10, 2023

Codecov Report

Base: 89.99% // Head: 89.72% // Decreases project coverage by -0.27% ⚠️

Coverage data is based on head (3b10f37) compared to base (84c320b).
Patch coverage: 89.18% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #695      +/-   ##
==========================================
- Coverage   89.99%   89.72%   -0.27%     
==========================================
  Files          23       22       -1     
  Lines        2589     2658      +69     
==========================================
+ Hits         2330     2385      +55     
- Misses        259      273      +14     
Flag Coverage Δ
pytests 89.72% <89.18%> (-0.27%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
myst_parser/config/main.py 86.50% <82.60%> (-2.03%) ⬇️
myst_parser/parsers/docutils_.py 82.19% <83.33%> (-1.28%) ⬇️
myst_parser/mdit_to_docutils/base.py 93.05% <100.00%> (+0.01%) ⬆️
myst_parser/mocking.py 84.82% <100.00%> (-0.67%) ⬇️
myst_parser/sphinx_ext/directives.py 81.53% <100.00%> (ø)
myst_parser/sphinx_ext/main.py 88.57% <100.00%> (ø)
myst_parser/parsers/mdit.py 96.96% <0.00%> (+1.51%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@chrisjsewell
Copy link
Member Author

The `myst_url_schemes` configuration has been extended,
in a back-compatible manner,
to also allow customisation of the link URL/text, via templates.

The `inline_attrs` extension also allows for specific links
to be marked as external, using `{.external}`.
@rowanc1
Copy link
Member

rowanc1 commented Feb 10, 2023

Only looked through the docs and not the code, this looks great. On the face of it very similar to the like transformers we have in mystjs, but allows these to be set as data. The config options look sensible.

There is also very similar functionality in the extlink in sphinx:
https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html#confval-extlinks

How do you think this compares to extlink, and/or the advantages of this to address similar/same functionality? I like that these are picked up as markdown links, but maybe the config can be closer, or the same as sphinx already has?

@chrisjsewell
Copy link
Member Author

How do you think this compares to extlink, and/or the advantages of this to address similar/same functionality?

These allow word functionality, by not simply using the %s, which to some degree is a deprecated aspect of python (replace by f-strings), by allowing the url to be fully decomposed. The dict format also allows future extensibility (for mor keys), rather than the tulple format, and this is already apparent in the ability to add classes to specific schemes.

Note I explicitly don't allow full jinja templating or actual python function manipulation of the string, in order to still allow for a "language-agnostic" configuration. I believe this is a good middle ground, of "full-extensibility" vs cross-language compatibility

@rowanc1
Copy link
Member

rowanc1 commented Feb 10, 2023

Yep makes sense, the tuple format isn't very customizable, and this allows for named parts but stays close to a familiar format (jinja) without the complexity (which isn't necessary for links).

I feel like this is something that we could pick up really easily in mystjs from a config/functionality standpoint so don't see any divergence there!

I like the idea of having some of these turned on by default in jupyterbook in the future, especially the wiki/doi links.

@chrisjsewell chrisjsewell merged commit 879cfca into master Feb 11, 2023
@chrisjsewell chrisjsewell deleted the external_schemes branch February 11, 2023 18:27
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.

Configure external link recognition (and handling)

3 participants