@erudit-js/prose 4.3.1-dev.1 → 4.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -49,6 +49,8 @@ onMounted(async () => {
|
|
|
49
49
|
(/AppleWebKit/.test(ua) && !/Chrome/.test(ua)) ||
|
|
50
50
|
/\b(iPad|iPhone|iPod)\b/.test(ua);
|
|
51
51
|
|
|
52
|
+
prepareMarkdown();
|
|
53
|
+
|
|
52
54
|
if (hasLatex(diagramContent.value)) {
|
|
53
55
|
await prepareMathDiagram();
|
|
54
56
|
}
|
|
@@ -126,6 +128,29 @@ function hasLatex(content: string): boolean {
|
|
|
126
128
|
return latexRegex.display.test(content) || latexRegex.inline.test(content);
|
|
127
129
|
}
|
|
128
130
|
|
|
131
|
+
function prepareMarkdown() {
|
|
132
|
+
const mathPattern = /\$\$[\s\S]*?\$\$|\$(?!\$).*?(?<!\$)\$/g;
|
|
133
|
+
|
|
134
|
+
const applyMarkdown = (text: string): string => {
|
|
135
|
+
return text
|
|
136
|
+
.replace(/\*\*(.+?)\*\*/g, '<b>$1</b>')
|
|
137
|
+
.replace(/\*(.+?)\*/g, '<i>$1</i>');
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const content = diagramContent.value;
|
|
141
|
+
const parts: string[] = [];
|
|
142
|
+
let lastIndex = 0;
|
|
143
|
+
|
|
144
|
+
for (const match of content.matchAll(mathPattern)) {
|
|
145
|
+
parts.push(applyMarkdown(content.slice(lastIndex, match.index)));
|
|
146
|
+
parts.push(match[0]);
|
|
147
|
+
lastIndex = match.index + match[0].length;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
parts.push(applyMarkdown(content.slice(lastIndex)));
|
|
151
|
+
diagramContent.value = parts.join('');
|
|
152
|
+
}
|
|
153
|
+
|
|
129
154
|
async function prepareMathDiagram() {
|
|
130
155
|
await import('katex/dist/katex.min.css');
|
|
131
156
|
const katex = await import('katex');
|
|
@@ -141,11 +166,7 @@ async function prepareMathDiagram() {
|
|
|
141
166
|
displayMode,
|
|
142
167
|
output: 'mathml',
|
|
143
168
|
})
|
|
144
|
-
.replace(/<mtd>/g, '<mtd style="padding: 0.2em 0;">')
|
|
145
|
-
.replace(
|
|
146
|
-
/<annotation encoding="application\/x-tex">[\s\S]*?<\/annotation>/g,
|
|
147
|
-
'',
|
|
148
|
-
);
|
|
169
|
+
.replace(/<mtd>/g, '<mtd style="padding: 0.2em 0;">');
|
|
149
170
|
});
|
|
150
171
|
};
|
|
151
172
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@erudit-js/prose",
|
|
4
|
-
"version": "4.3.
|
|
4
|
+
"version": "4.3.2",
|
|
5
5
|
"description": "📝 JSX prose subsystem for Erudit sites",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"prepack": "bun run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@erudit-js/core": "4.3.
|
|
35
|
+
"@erudit-js/core": "4.3.2",
|
|
36
36
|
"@floating-ui/vue": "^1.1.11",
|
|
37
37
|
"image-size": "^2.0.2",
|
|
38
38
|
"katex": "^0.16.38",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"glob": "^13.0.6",
|
|
46
|
-
"oxc-transform": "0.
|
|
46
|
+
"oxc-transform": "0.120.0",
|
|
47
47
|
"ts-xor": "^1.3.0"
|
|
48
48
|
}
|
|
49
49
|
}
|