Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom parsing on the web #585

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to export and use sortRanges from parseExpensiMark. This is a self-contained parser used as default which we plan to remove from the repo at some point so we shouldn't use any of its pieces in the library code. Instead, let's extract sortRanges to a separate file (maybe something like parserUtils.ts?) and import it here from there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I moved them to the rangeUtils since parserUtils.ts already exists on the web

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
Loading