-
Notifications
You must be signed in to change notification settings - Fork 1
/
svelte.config.js
70 lines (57 loc) · 1.6 KB
/
svelte.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
65
66
67
68
69
70
// @ts-check
import adapter from '@sveltejs/adapter-auto';
import preprocess from 'svelte-preprocess';
/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').PhrasingContent} PhrasingContent
*/
import { visit } from 'unist-util-visit';
const find = /\\\n/g;
/**
* remark has escaped breaks built into change to <br>, but mdsvex is using an older version I believe
* temp solution for now, stolen from: https://github.com/remarkjs/remark-breaks
*/
/**
* @type {import('unified').Plugin<void[], Root>}
*/
function remarkEscapedBreaks() {
return (tree) => {
visit(tree, 'text', (node, index, parent) => {
/** @type {PhrasingContent[]} */
const result = [];
let start = 0;
find.lastIndex = 0;
let match = find.exec(node.value);
while (match) {
const position = match.index;
if (start !== position) {
result.push({
type: 'text',
value: node.value.slice(start, position)
});
}
result.push({ type: 'break' });
start = position + match[0].length;
match = find.exec(node.value);
}
if (result.length > 0 && parent && typeof index === 'number') {
if (start < node.value.length) {
result.push({ type: 'text', value: node.value.slice(start) });
}
parent.children.splice(index, 1, ...result);
return index + result.length;
}
});
};
}
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://github.com/sveltejs/svelte-preprocess
// for more information about preprocessors
extensions: ['.svelte'],
preprocess: [preprocess()],
kit: {
adapter: adapter()
}
};
export default config;