mirror of
https://github.com/docmost/docmost.git
synced 2026-08-24 11:42:18 +10:00
improve markdown import and export
This commit is contained in:
@@ -13,7 +13,8 @@ interface TabbedToken {
|
||||
activeTabIndex: number;
|
||||
}
|
||||
|
||||
const HEADER_RE = /^===([!+])?\s*["'“”‘’]([^"'“”‘’\n]+)["'“”‘’]\s*$/gm;
|
||||
const HEADER_RE =
|
||||
/^===([!+])?\s*["'“”‘’]((?:\\.|[^"'“”‘’\n])+?)["'“”‘’]\s*$/gm;
|
||||
|
||||
export const tabsExtension = {
|
||||
name: 'tabbed',
|
||||
@@ -38,7 +39,7 @@ export const tabsExtension = {
|
||||
index: m.index,
|
||||
raw: m[0],
|
||||
marker: m[1] ?? '',
|
||||
label: m[2].trim(),
|
||||
label: unescapeTabLabel(m[2].trim()),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -87,7 +88,7 @@ export const tabsExtension = {
|
||||
if (body.length > 0) {
|
||||
body = body
|
||||
.split('\n')
|
||||
.map((line) => line.replace(/^\s{2,4}/, ''))
|
||||
.map((line) => line.replace(/^(?:\t| {2,4})/, ''))
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
@@ -137,6 +138,10 @@ export const tabsExtension = {
|
||||
},
|
||||
};
|
||||
|
||||
function unescapeTabLabel(value: string): string {
|
||||
return value.replace(/\\(["\\])/g, '$1');
|
||||
}
|
||||
|
||||
function escapeHtml(value: string): string {
|
||||
return value
|
||||
.replace(/&/g, '&')
|
||||
|
||||
@@ -69,7 +69,7 @@ function tabs(turndownService: _TurndownService) {
|
||||
|
||||
const isNestedTabsNode =
|
||||
node.parentElement?.closest('div[data-type="tabs"]') !== null;
|
||||
|
||||
|
||||
const tabBlocks = tabNodes.map((tabNode, index) => {
|
||||
const labelNode = tabNode.querySelector(
|
||||
':scope > div[data-type="tabLabel"]',
|
||||
@@ -279,15 +279,16 @@ function video(turndownService: _TurndownService) {
|
||||
function sanitizeTabLabel(value: string): string {
|
||||
return value
|
||||
.replace(/[\r\n]+/g, ' ')
|
||||
.replace(/\\/g, '\\\\')
|
||||
.replace(/"/g, '\\"')
|
||||
.trim();
|
||||
}
|
||||
|
||||
function indentMarkdownBlock(content: string): string {
|
||||
if (!content) return ' ';
|
||||
if (!content) return '\t';
|
||||
|
||||
return content
|
||||
.split('\n')
|
||||
.map((line) => (line.trim() ? ` ${line}` : ''))
|
||||
.map((line) => (line.trim() ? `\t${line}` : ''))
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user