Skip to content

Commit

Permalink
✨ NEW: Add myst_linkify_fuzzy_links option (#464)
Browse files Browse the repository at this point in the history
If `False`, only links that contain a scheme (such as `http:\\`) will be recognised as external links.
  • Loading branch information
chrisjsewell authored Dec 16, 2021
1 parent d84e625 commit aaead2f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/sphinx/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ To do so, use the keywords beginning `myst_`.
- `None`
- [URI schemes](https://en.wikipedia.org/wiki/List_of_URI_schemes) that will be recognised as external URLs in `[](scheme:loc)` syntax, or set `None` to recognise all.
Other links will be resolved as internal cross-references.
* - `myst_linkify_fuzzy_links`
- `True`
- If `False`, only links that contain a scheme (such as `http`) will be recognised as external links.
* - `myst_heading_anchors`
- `None`
- Enable auto-generated heading anchors, up to a maximum level, [see here](syntax/header-anchors) for details.
Expand Down
2 changes: 2 additions & 0 deletions docs/syntax/optional.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ Adding `"linkify"` to `myst_enable_extensions` (in the sphinx `conf.py` [configu

`www.example.com` -> www.example.com

To only match URLs that start with schema, such as `http://example.com`, set `myst_linkify_fuzzy_links=False`.

:::{important}
This extension requires that [linkify-it-py](https://github.com/tsutsu3/linkify-it-py) is installed.
Either directly; `pip install linkify-it-py` or *via* `pip install myst-parser[linkify]`.
Expand Down
9 changes: 8 additions & 1 deletion myst_parser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class MdParserConfig:
factory=lambda: ["dollarmath"], metadata={"help": "Enable extensions"}
)

linkify_fuzzy_links: bool = attr.ib(
default=True,
validator=instance_of(bool),
metadata={"help": "linkify: recognise URLs without schema prefixes"},
)

dmath_allow_labels: bool = attr.ib(
default=True,
validator=instance_of(bool),
Expand Down Expand Up @@ -223,8 +229,9 @@ def default_parser(config: MdParserConfig) -> MarkdownIt:
md.enable("replacements")
typographer = True
if "linkify" in config.enable_extensions:
# TODO warn, don't enable, if linkify-it-py not installed
md.enable("linkify")
if md.linkify is not None:
md.linkify.set({"fuzzy_link": config.linkify_fuzzy_links})

if "dollarmath" in config.enable_extensions:
md.use(
Expand Down

0 comments on commit aaead2f

Please sign in to comment.