-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmdsvex.config.js
64 lines (57 loc) · 1.98 KB
/
mdsvex.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import abbr from "remark-abbr"
import urls from "rehype-urls"
import slug from "rehype-slug"
import autoLinkHeadings from "rehype-autolink-headings"
import addClasses from "rehype-add-classes"
import figure from "rehype-figure"
import twemoji from "remark-twemoji"
import plantuml from "@akebifiky/remark-simple-plantuml"
import remarkEmbedder from '@remark-embedder/core';
import oembedTransformer from '@remark-embedder/transformer-oembed'
import { visit } from "unist-util-visit";
function processUrl(url, node) {
if (node.tagName === "a") {
node.properties.class = "text-link"
if (!url.href.startsWith("/")) {
// Open external links in new tab
node.properties.target = "_blank"
// Fix a security concern with offsite links
// See: https://web.dev/external-anchors-use-rel-noopener/
node.properties.rel = "noopener"
}
}
}
function addWordCountToFrontmatterData({
attribute = "wordCount",
} = {}) {
return function (info, file) {
let text = "";
visit(info, ["text", "code"], (node) => {
text += node.value;
});
file.data.fm[attribute] = text.split(/\s+/).length;
};
}
/** @type {import('mdsvex').MdsvexOptions} */
const mdsvexConfig = {
extensions: [ '.md', '.svx' ],
remarkPlugins: [
addWordCountToFrontmatterData, // adds wordCount to frontmatter
[remarkEmbedder.default, {transformers: [oembedTransformer.default]}],
abbr, // adds support for footnote-like abbreviations
[twemoji, {
ext: '.svg',
folder: 'svg',
}],
[plantuml, { baseUrl: "https://www.plantuml.com/plantuml/svg" }],
],
rehypePlugins:[
figure, // convert images into <figure> elements
[urls, processUrl], // adds rel and target to <a> elements
slug, // adds slug to <h1>-<h6> elements
[autoLinkHeadings, { behavior: "prepend" }], // prepends slugged <h1>-<h6> elements with an <a>
[addClasses, { "ul,ol": "list" }] // add classes to these elements
],
smartypants: true,
};
export default mdsvexConfig;