@file-viewer/renderer-text 2.1.0 → 2.1.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.
- package/dist/markdown.d.ts +1 -0
- package/dist/markdown.js +19 -1
- package/package.json +2 -2
package/dist/markdown.d.ts
CHANGED
package/dist/markdown.js
CHANGED
|
@@ -35,6 +35,24 @@ const applyMarkdownZoom = (host, zoom) => {
|
|
|
35
35
|
host.style.setProperty('--markdown-padding', `${45 * zoom}px`);
|
|
36
36
|
host.style.setProperty('--markdown-font-size', `${16 * zoom}px`);
|
|
37
37
|
};
|
|
38
|
+
export const stripMarkdownFrontmatter = (text) => {
|
|
39
|
+
const input = text.replace(/^\uFEFF/, '');
|
|
40
|
+
if (!input.startsWith('---')) {
|
|
41
|
+
return input;
|
|
42
|
+
}
|
|
43
|
+
const firstLineEnd = input.indexOf('\n');
|
|
44
|
+
const firstLine = firstLineEnd >= 0 ? input.slice(0, firstLineEnd).trim() : input.trim();
|
|
45
|
+
if (firstLine !== '---') {
|
|
46
|
+
return input;
|
|
47
|
+
}
|
|
48
|
+
const closePattern = /\r?\n(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/g;
|
|
49
|
+
closePattern.lastIndex = firstLineEnd >= 0 ? firstLineEnd : 3;
|
|
50
|
+
const match = closePattern.exec(input);
|
|
51
|
+
if (!match) {
|
|
52
|
+
return input;
|
|
53
|
+
}
|
|
54
|
+
return input.slice(match.index + match[0].length).replace(/^\r?\n/, '');
|
|
55
|
+
};
|
|
38
56
|
export default async function renderMarkdown(buffer, target) {
|
|
39
57
|
const text = await readText(buffer);
|
|
40
58
|
let zoom = 1;
|
|
@@ -44,7 +62,7 @@ export default async function renderMarkdown(buffer, target) {
|
|
|
44
62
|
root.dataset.viewerZoomProvider = 'markdown';
|
|
45
63
|
const article = document.createElement('article');
|
|
46
64
|
article.className = 'markdown-body';
|
|
47
|
-
article.innerHTML = await marked(text);
|
|
65
|
+
article.innerHTML = await marked(stripMarkdownFrontmatter(text));
|
|
48
66
|
applyMarkdownZoom(root, zoom);
|
|
49
67
|
root.append(article);
|
|
50
68
|
target.replaceChildren(createStyle(), root);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@file-viewer/renderer-text",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Standalone code, text, Markdown, patch diff, and Git bundle renderer plugin for Flyfish File Viewer.",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"LICENSE"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@file-viewer/core": "^2.1.
|
|
60
|
+
"@file-viewer/core": "^2.1.2",
|
|
61
61
|
"diff2html": "^3.4.56",
|
|
62
62
|
"highlight.js": "^11.11.1",
|
|
63
63
|
"marked": "^18.0.5",
|