Skip to content

Commit 4ffdaf4

Browse files
Filmbostock
andauthored
linkify carefully (#1031)
* linkify carefully * Update src/markdown.ts * fix undefined test --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent 2945151 commit 4ffdaf4

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/markdown.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,11 @@ export interface ParseOptions {
279279
style?: Config["style"];
280280
}
281281

282-
export function parseMarkdown(
283-
input: string,
284-
{root, path, markdownIt = (md) => md, style: configStyle}: ParseOptions
285-
): MarkdownPage {
282+
export function parseMarkdown(input: string, {root, path, markdownIt, style: configStyle}: ParseOptions): MarkdownPage {
286283
const parts = matter(input, {});
287-
const md = markdownIt(MarkdownIt({html: true}));
284+
let md = MarkdownIt({html: true, linkify: true});
285+
md.linkify.set({fuzzyLink: false, fuzzyEmail: false});
286+
if (markdownIt !== undefined) md = markdownIt(md);
288287
md.use(MarkdownItAnchor, {permalink: MarkdownItAnchor.permalink.headerLink({class: "observablehq-header-anchor"})});
289288
md.inline.ruler.push("placeholder", transformPlaceholderInline);
290289
md.core.ruler.before("linkify", "placeholder", transformPlaceholderCore);

test/input/linkify.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Linkify
2+
3+
https://observablehq.com/ is a link to https://observablehq.com.
4+
5+
mailto:[email protected] is a link too.
6+
7+
Observablehq.com and [email protected] are not links, since by default we disable fuzzy links.
8+

test/output/linkify.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h1 id="linkify" tabindex="-1"><a class="observablehq-header-anchor" href="#linkify">Linkify</a></h1>
2+
<p><a href="https://observablehq.com/">https://observablehq.com/</a> is a link to <a href="https://observablehq.com">https://observablehq.com</a>.</p>
3+
<p><a href="mailto:[email protected]">mailto:[email protected]</a> is a link too.</p>
4+
<p>Observablehq.com and [email protected] are not links, since by default we disable fuzzy links.</p>

test/output/linkify.md.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"data": null,
3+
"title": "Linkify",
4+
"style": null,
5+
"code": []
6+
}

0 commit comments

Comments
 (0)