Skip to content

Commit

Permalink
Add tag hierarchy checking to parser ranges sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Jan 19, 2024
1 parent 4072b1c commit 7d5f331
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
13 changes: 12 additions & 1 deletion parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,19 @@ function parseTreeToTextAndRanges(tree: StackItem): [string, Range[]] {
return [text, ranges];
}

function getTagHierarchyValue(tag: string) {
switch (tag) {
case 'blockquote':
return 2;
case 'h1':
return 1;
default:
return 0;
}
}

function sortRanges(ranges: Range[]) {
return ranges.sort((a, b) => a[1] - b[1] || b[2] - a[2] || 0); // sort by location to properly handle bold+italic
return ranges.sort((a, b) => a[1] - b[1] || b[2] - a[2] || getTagHierarchyValue(b[0]) - getTagHierarchyValue(a[0]) || 0); // sort by location to properly handle bold+italic
}

function parseExpensiMarkToRanges(markdown: string): Range[] {
Expand Down
Loading

0 comments on commit 7d5f331

Please sign in to comment.