fix: normalize milkdown roundtrip markdown to avoid spurious updates
Co-authored-by: rfc1437 <774975+rfc1437@users.noreply.github.com>
This commit is contained in:
@@ -38,8 +38,8 @@ export function unescapeMacroSyntax(markdown: string): string {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unorderedListItemPattern = /^\s{0,3}[-+*]\s/;
|
const unorderedListItemPattern = /^[-+*]\s/;
|
||||||
const orderedListItemPattern = /^\s{0,3}\d+\.\s/;
|
const orderedListItemPattern = /^\d+\.\s/;
|
||||||
|
|
||||||
function getListLineType(line: string): 'ordered' | 'unordered' | null {
|
function getListLineType(line: string): 'ordered' | 'unordered' | null {
|
||||||
if (unorderedListItemPattern.test(line)) return 'unordered';
|
if (unorderedListItemPattern.test(line)) return 'unordered';
|
||||||
@@ -52,7 +52,7 @@ export function normalizeMilkdownMarkdown(markdown: string): string {
|
|||||||
const lines = unescaped.split('\n');
|
const lines = unescaped.split('\n');
|
||||||
const normalized: string[] = [];
|
const normalized: string[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < lines.length; i += 1) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
const line = lines[i];
|
const line = lines[i];
|
||||||
|
|
||||||
const previousListType = i > 0 ? getListLineType(lines[i - 1]) : null;
|
const previousListType = i > 0 ? getListLineType(lines[i - 1]) : null;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import type { Root, List, ListItem } from 'mdast';
|
|||||||
import { visit } from 'unist-util-visit';
|
import { visit } from 'unist-util-visit';
|
||||||
import { normalizeMilkdownMarkdown } from '../../../src/renderer/utils/markdownEscape';
|
import { normalizeMilkdownMarkdown } from '../../../src/renderer/utils/markdownEscape';
|
||||||
|
|
||||||
const wxrRefDir = '/home/runner/work/bDS/bDS/tests/assets/wxr-ref';
|
const wxrRefDir = path.join(__dirname, '../../assets/wxr-ref');
|
||||||
|
|
||||||
const remarkTightListsPlugin: Plugin<[Record<string, unknown>], Root> = () => {
|
const remarkTightListsPlugin: Plugin<[Record<string, unknown>], Root> = () => {
|
||||||
return (tree: Root) => {
|
return (tree: Root) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user