From f0aa12068eea91ba84556b87e9c3f31e84a68b0b Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Fri, 30 Aug 2024 14:11:33 +0200 Subject: [PATCH 1/2] Rename type `Range` to `MarkdownRange` --- parser/__tests__/index.test.ts | 6 +++--- parser/index.ts | 16 ++++++++-------- types/global.d.ts | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/parser/__tests__/index.test.ts b/parser/__tests__/index.test.ts index 67dfdc49..bee27572 100644 --- a/parser/__tests__/index.test.ts +++ b/parser/__tests__/index.test.ts @@ -1,15 +1,15 @@ import {expect} from '@jest/globals'; -import type {Range} from '../index'; +import type {MarkdownRange} from '../index'; require('../react-native-live-markdown-parser.js'); declare module 'expect' { interface Matchers { - toBeParsedAs(expectedRanges: Range[]): R; + toBeParsedAs(expectedRanges: MarkdownRange[]): R; } } -const toBeParsedAs = function (actual: string, expectedRanges: Range[]) { +const toBeParsedAs = function (actual: string, expectedRanges: MarkdownRange[]) { const actualRanges = global.parseExpensiMarkToRanges(actual); if (JSON.stringify(actualRanges) !== JSON.stringify(expectedRanges)) { return { diff --git a/parser/index.ts b/parser/index.ts index 5bc36794..a7e98546 100644 --- a/parser/index.ts +++ b/parser/index.ts @@ -3,7 +3,7 @@ import ExpensiMark from 'expensify-common/dist/ExpensiMark'; import {unescapeText} from './utils'; type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax'; -type Range = { +type MarkdownRange = { type: MarkdownType; start: number; length: number; @@ -87,7 +87,7 @@ function parseTokensToTree(tokens: Token[]): StackItem { return stack[0]!; } -function parseTreeToTextAndRanges(tree: StackItem): [string, Range[]] { +function parseTreeToTextAndRanges(tree: StackItem): [string, MarkdownRange[]] { let text = ''; function processChildren(node: StackItem | string) { @@ -109,7 +109,7 @@ function parseTreeToTextAndRanges(tree: StackItem): [string, Range[]] { ranges.push({type, start, length: end - start}); } - const ranges: Range[] = []; + const ranges: MarkdownRange[] = []; function dfs(node: StackItem | string) { if (typeof node === 'string') { text += node; @@ -226,12 +226,12 @@ function getTagPriority(tag: string) { } } -function sortRanges(ranges: Range[]) { +function sortRanges(ranges: MarkdownRange[]) { // sort ranges by start position, then by length, then by tag hierarchy return ranges.sort((a, b) => a.start - b.start || b.length - a.length || getTagPriority(b.type) - getTagPriority(a.type) || 0); } -function groupRanges(ranges: Range[]) { +function groupRanges(ranges: MarkdownRange[]) { const lastVisibleRangeIndex: {[key in MarkdownType]?: number} = {}; return ranges.reduce((acc, range) => { @@ -250,10 +250,10 @@ function groupRanges(ranges: Range[]) { } return acc; - }, [] as Range[]); + }, [] as MarkdownRange[]); } -function parseExpensiMarkToRanges(markdown: string): Range[] { +function parseExpensiMarkToRanges(markdown: string): MarkdownRange[] { try { const html = parseMarkdownToHTML(markdown); const tokens = parseHTMLToTokens(html); @@ -276,4 +276,4 @@ function parseExpensiMarkToRanges(markdown: string): Range[] { } globalThis.parseExpensiMarkToRanges = parseExpensiMarkToRanges; -export type {MarkdownType, Range}; +export type {MarkdownType, MarkdownRange}; diff --git a/types/global.d.ts b/types/global.d.ts index 59d2e998..80be06f2 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -2,7 +2,7 @@ export {}; type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax'; -type Range = { +type MarkdownRange = { type: MarkdownType; start: number; length: number; @@ -11,5 +11,5 @@ type Range = { declare global { // eslint-disable-next-line no-var - var parseExpensiMarkToRanges: (markdown: string) => Range[]; + var parseExpensiMarkToRanges: (markdown: string) => MarkdownMarkdownRange[]; } From fe306dcdcbd61148b61e530059cf1252aa19cc4f Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Fri, 30 Aug 2024 14:13:18 +0200 Subject: [PATCH 2/2] Update Podfile.lock --- example/ios/Podfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index cedb01a5..4fa10252 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1053,13 +1053,13 @@ PODS: - React-jsi (= 0.73.4) - React-logger (= 0.73.4) - React-perflogger (= 0.73.4) - - RNLiveMarkdown (0.1.96): + - RNLiveMarkdown (0.1.121): - glog - hermes-engine - RCT-Folly (= 2022.05.16.00) - React-Core - - RNLiveMarkdown/common (= 0.1.96) - - RNLiveMarkdown/common (0.1.96): + - RNLiveMarkdown/common (= 0.1.121) + - RNLiveMarkdown/common (0.1.121): - glog - hermes-engine - RCT-Folly (= 2022.05.16.00) @@ -1278,7 +1278,7 @@ SPEC CHECKSUMS: React-runtimescheduler: ed48e5faac6751e66ee1261c4bd01643b436f112 React-utils: 6e5ad394416482ae21831050928ae27348f83487 ReactCommon: 840a955d37b7f3358554d819446bffcf624b2522 - RNLiveMarkdown: ffa97e63f100bd32fad2f6f3b689031188761578 + RNLiveMarkdown: 522e631ecd54c207f3bdbd5e87edf8a549eefdb7 SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Yoga: 64cd2a583ead952b0315d5135bf39e053ae9be70