diff --git a/src/LinkRenderer.php b/src/LinkRenderer.php index 88df4cc..3f3a65f 100644 --- a/src/LinkRenderer.php +++ b/src/LinkRenderer.php @@ -30,7 +30,11 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer) $out = $childRenderer->renderNodes($node->children()); - $url = \str_replace('_', '\\_', $node->getUrl()); + $replacements = [ + '_' => '\\_', + '#' => '\#', + ]; + $url = \str_replace(\array_keys($replacements), $replacements, $node->getUrl()); $allowUnsafeLinks = $this->config->get('allow_unsafe_links'); if (! $allowUnsafeLinks && RegexHelper::isLinkPotentiallyUnsafe($url)) { diff --git a/tests/data/links.md b/tests/data/links.md index 72a5406..e40f783 100644 --- a/tests/data/links.md +++ b/tests/data/links.md @@ -1,4 +1,4 @@ -Link with protocol: [label](https://example.org). +Link with protocol and fragment: [label](https://example.org/lorem#ipsum). Relative link: [label](./example.html). diff --git a/tests/data/links.tex b/tests/data/links.tex index 860d2a5..77a15d4 100644 --- a/tests/data/links.tex +++ b/tests/data/links.tex @@ -1,4 +1,4 @@ -Link with protocol: label\footnote{\url{https://example.org}}. +Link with protocol and fragment: label\footnote{\url{https://example.org/lorem\#ipsum}}. Relative link: label\footnote{\url{./example.html}}.