Skip to content

Commit

Permalink
Add splitting to parseExpensiMark
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Dec 23, 2024
1 parent 6190fc0 commit b0f3d57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/parseExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {unescapeText} from 'expensify-common/dist/utils';
import {decode} from 'html-entities';
import type {WorkletFunction} from 'react-native-reanimated/lib/typescript/commonTypes';
import type {MarkdownType, MarkdownRange} from './commonTypes';
import {splitRangesOnEmojis} from './rangeUtils';

function isWeb() {
return Platform.OS === 'web';
Expand Down Expand Up @@ -236,6 +237,8 @@ function parseTreeToTextAndRanges(tree: StackItem): [string, MarkdownRange[]] {
// getTagPriority returns a priority for a tag, higher priority means the tag should be processed first
function getTagPriority(tag: string) {
switch (tag) {
case 'syntax': // syntax has the lowest priority so other styles can be applied to it
return -1;
case 'blockquote':
return 2;
case 'h1':
Expand Down Expand Up @@ -287,8 +290,13 @@ function parseExpensiMark(markdown: string): MarkdownRange[] {
)}'\nOriginal input: '${JSON.stringify(markdown)}'`,
);
}
const sortedRanges = sortRanges(ranges);

let splittedRanges = splitRangesOnEmojis(ranges, 'italic');
splittedRanges = splitRangesOnEmojis(splittedRanges, 'strikethrough');

const sortedRanges = sortRanges(splittedRanges);
const groupedRanges = groupRanges(sortedRanges);

return groupedRanges;
}

Expand Down
3 changes: 1 addition & 2 deletions src/rangeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ function splitRangesOnEmojis(ranges: MarkdownRange[], type: MarkdownType): Markd
if (emojiStart >= currentStart && emojiEnd <= currentEnd) {
// Intersection
const newRange: MarkdownRange = {
type: currentRange.type,
start: currentStart,
length: emojiStart - currentStart,
type: currentRange.type,
...(currentRange?.depth && {depth: currentRange?.depth}),
};

Expand All @@ -53,7 +53,6 @@ function splitRangesOnEmojis(ranges: MarkdownRange[], type: MarkdownType): Markd
i++;
}
}

return newRanges;
}

Expand Down

0 comments on commit b0f3d57

Please sign in to comment.