Skip to content

Commit aaead2f

Browse files
authored
✨ NEW: Add myst_linkify_fuzzy_links option (#464)
If `False`, only links that contain a scheme (such as `http:\\`) will be recognised as external links.
1 parent d84e625 commit aaead2f

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

docs/sphinx/reference.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ To do so, use the keywords beginning `myst_`.
2323
- `None`
2424
- [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.
2525
Other links will be resolved as internal cross-references.
26+
* - `myst_linkify_fuzzy_links`
27+
- `True`
28+
- If `False`, only links that contain a scheme (such as `http`) will be recognised as external links.
2629
* - `myst_heading_anchors`
2730
- `None`
2831
- Enable auto-generated heading anchors, up to a maximum level, [see here](syntax/header-anchors) for details.

docs/syntax/optional.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ Adding `"linkify"` to `myst_enable_extensions` (in the sphinx `conf.py` [configu
243243

244244
`www.example.com` -> www.example.com
245245

246+
To only match URLs that start with schema, such as `http://example.com`, set `myst_linkify_fuzzy_links=False`.
247+
246248
:::{important}
247249
This extension requires that [linkify-it-py](https://github.com/tsutsu3/linkify-it-py) is installed.
248250
Either directly; `pip install linkify-it-py` or *via* `pip install myst-parser[linkify]`.

myst_parser/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class MdParserConfig:
4747
factory=lambda: ["dollarmath"], metadata={"help": "Enable extensions"}
4848
)
4949

50+
linkify_fuzzy_links: bool = attr.ib(
51+
default=True,
52+
validator=instance_of(bool),
53+
metadata={"help": "linkify: recognise URLs without schema prefixes"},
54+
)
55+
5056
dmath_allow_labels: bool = attr.ib(
5157
default=True,
5258
validator=instance_of(bool),
@@ -223,8 +229,9 @@ def default_parser(config: MdParserConfig) -> MarkdownIt:
223229
md.enable("replacements")
224230
typographer = True
225231
if "linkify" in config.enable_extensions:
226-
# TODO warn, don't enable, if linkify-it-py not installed
227232
md.enable("linkify")
233+
if md.linkify is not None:
234+
md.linkify.set({"fuzzy_link": config.linkify_fuzzy_links})
228235

229236
if "dollarmath" in config.enable_extensions:
230237
md.use(

0 commit comments

Comments
 (0)