generated from executablebooks/mdformat-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
141 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""Match markdown anchors from the mkdocs-autorefs plugin. | ||
Matches: | ||
```md | ||
[](){#some-anchor-name} | ||
``` | ||
Docs: https://mkdocstrings.github.io/autorefs | ||
""" | ||
|
||
import re | ||
|
||
from markdown_it import MarkdownIt | ||
from markdown_it.rules_inline import StateInline | ||
|
||
LINK_PATTERN = re.compile(r"\[\]\(<?>?\){#(?P<anchor>[^ }]+)}") | ||
MKDOCS_ANCHORS_PREFIX = "mkdocs_anchor" | ||
|
||
|
||
def _mkdocs_anchors_plugin(state: StateInline, silent: bool) -> bool: | ||
match = LINK_PATTERN.match(state.src[state.pos : state.posMax]) | ||
if not match: | ||
return False | ||
|
||
if silent: | ||
return True | ||
|
||
anchor = match["anchor"] | ||
o_token = state.push(f"{MKDOCS_ANCHORS_PREFIX}_open", "a", 1) | ||
o_token.attrs = {"id": anchor, "href": ""} | ||
o_token.meta = {"content": f"[](){{#{anchor}}}"} | ||
state.push(f"{MKDOCS_ANCHORS_PREFIX}_close", "a", -1) | ||
|
||
state.pos += match.end() | ||
|
||
return True | ||
|
||
|
||
def mkdocs_anchors_plugin(md: MarkdownIt) -> None: | ||
md.inline.ruler.before( | ||
"link", | ||
MKDOCS_ANCHORS_PREFIX, | ||
_mkdocs_anchors_plugin, | ||
{"alt": ["link"]}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Anchor links (FIXME: Remove inserted newline) | ||
. | ||
[](){#some-anchor-name} | ||
# Some Title | ||
. | ||
[](){#some-anchor-name} | ||
|
||
# Some Title | ||
. | ||
|
||
Broken Anchor links (https://github.com/KyleKing/mdformat-mkdocs/issues/25) | ||
. | ||
[](<>){#some-anchor-name} | ||
. | ||
[](){#some-anchor-name} | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Anchor links (https://github.com/KyleKing/mdformat-mkdocs/issues/25) | ||
. | ||
[](){#some-anchor-name} | ||
. | ||
<p><a id="some-anchor-name" href=""></a></p> | ||
. | ||
|
||
For header (https://github.com/DFiantHDL/DFHDL/blob/192d7e58e1107da6b0a885e54a853a88bb619f29/docs/user-guide/state/index.md?plain=1#L1-L4 & https://dfianthdl.github.io/user-guide/state/#state-initialization) | ||
. | ||
[](){#state} | ||
# State & Initialization | ||
|
||
Semantically, every DFiant dataflow variable references a token stream (TS). | ||
. | ||
<p><a id="state" href=""></a></p> | ||
<h1>State & Initialization</h1> | ||
<p>Semantically, every DFiant dataflow variable references a token stream (TS).</p> | ||
. | ||
|
||
Example inline (https://github.com/gustavofoa/dicasdeprogramacao.com.br/blob/e35771b41fce6b7c46875bcf65000f241755c13b/content/posts/iniciante-em-programacao/2013-05-02-operadores-relacionais.md?plain=1#L116C44-L118C16) | ||
. | ||
**maior **e **menor** para | ||
verificar a precedência alfabética de um [](){#spiderWordFound4}texto em | ||
relação a outro | ||
. | ||
<p>**maior **e <strong>menor</strong> para | ||
verificar a precedência alfabética de um <a id="spiderWordFound4" href=""></a>texto em | ||
relação a outro</p> | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters