Skip to content

Commit

Permalink
Add range sortiing in web parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid committed Dec 12, 2024
1 parent 2581f3a commit 9e2a833
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/parseExpensiMark.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {expect} from '@jest/globals';
import type {MarkdownRange} from '../commonTypes';
import parseExpensiMark from '../parseExpensiMark';
import {parseExpensiMark} from '../parseExpensiMark';

declare module 'expect' {
interface Matchers<R> {
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/webParser.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {expect} from '@jest/globals';
import {parseRangesToHTMLNodes} from '../web/utils/parserUtils';
import parseExpensiMark from '../parseExpensiMark';
import {parseExpensiMark} from '../parseExpensiMark';

declare module 'expect' {
interface Matchers<R> {
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {default as MarkdownTextInput} from './MarkdownTextInput';
export type {MarkdownTextInputProps, MarkdownStyle} from './MarkdownTextInput';
export type {MarkdownType, MarkdownRange} from './commonTypes';
export {default as parseExpensiMark} from './parseExpensiMark';
export {parseExpensiMark} from './parseExpensiMark';
2 changes: 1 addition & 1 deletion src/parseExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,4 @@ function parseExpensiMark(markdown: string): MarkdownRange[] {
return groupedRanges;
}

export default parseExpensiMark;
export {parseExpensiMark, sortRanges};
4 changes: 3 additions & 1 deletion src/web/utils/parserUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {getCurrentCursorPosition, moveCursorToEnd, setCursorPosition} from './cu
import {addStyleToBlock, extendBlockStructure, getFirstBlockMarkdownRange, isBlockMarkdownType} from './blockUtils';
import type {InlineImagesInputProps, MarkdownRange} from '../../commonTypes';
import {getAnimationCurrentTimes, updateAnimationsTime} from './animationUtils';
import {sortRanges} from '../../parseExpensiMark';

type Paragraph = {
text: string;
Expand Down Expand Up @@ -167,7 +168,8 @@ function parseRangesToHTMLNodes(
return {dom: rootElement, tree: rootNode};
}

const markdownRanges = ungroupRanges(ranges);
const sortedRanges = sortRanges(ranges);
const markdownRanges = ungroupRanges(sortedRanges);
lines = mergeLinesWithMultilineTags(lines, markdownRanges);

let lastRangeEndIndex = 0;
Expand Down

0 comments on commit 9e2a833

Please sign in to comment.