Skip to content

Commit

Permalink
fix: return empty array instead of throwing error if text !== markdown (
Browse files Browse the repository at this point in the history
  • Loading branch information
daledah authored Jan 6, 2025
1 parent 6447ea9 commit 7b34f62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/__tests__/parseExpensiMark.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ test('no formatting', () => {
expect('Hello, world!').toBeParsedAs([]);
});

describe('parsing error', () => {
expect(`> [exa\nmple.com](https://example.com)`).toBeParsedAs([]);
});

test('bold', () => {
expect('Hello, *world*!').toBeParsedAs([
{type: 'syntax', start: 7, length: 1},
Expand Down
3 changes: 2 additions & 1 deletion src/parseExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,12 @@ function parseExpensiMark(markdown: string): MarkdownRange[] {
const tree = parseTokensToTree(tokens);
const [text, ranges] = parseTreeToTextAndRanges(tree);
if (text !== markdown) {
throw new Error(
console.error(
`[react-native-live-markdown] Parsing error: the processed text does not match the original Markdown input. This may be caused by incorrect parsing functions or invalid input Markdown.\nProcessed input: '${JSON.stringify(
text,
)}'\nOriginal input: '${JSON.stringify(markdown)}'`,
);
return [];
}
const sortedRanges = sortRanges(ranges);
const groupedRanges = groupRanges(sortedRanges);
Expand Down

0 comments on commit 7b34f62

Please sign in to comment.