diff --git a/src/__tests__/webParser.test.tsx b/src/__tests__/webParser.test.tsx index ffaa87f1..5fcec4da 100644 --- a/src/__tests__/webParser.test.tsx +++ b/src/__tests__/webParser.test.tsx @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import {expect} from '@jest/globals'; import {parseRangesToHTMLNodes} from '../web/utils/parserUtils'; -import type {MarkdownRange} from '../web/utils/parserUtils'; require('../../parser/react-native-live-markdown-parser.js'); @@ -16,8 +15,7 @@ const toBeParsedAsHTML = function (actual: string, expectedHTML: string) { throw new Error('Actual value must be a string'); } let expected = expectedHTML; - const ranges = global.parseExpensiMarkToRanges(actual); - const markdownRanges = ranges as MarkdownRange[]; + const markdownRanges = global.parseExpensiMarkToRanges(actual); const actualDOM = parseRangesToHTMLNodes(actual, markdownRanges, {}, true).dom; const actualHTML = actualDOM.innerHTML; diff --git a/src/commonTypes.ts b/src/commonTypes.ts new file mode 100644 index 00000000..fa2f0de5 --- /dev/null +++ b/src/commonTypes.ts @@ -0,0 +1,10 @@ +type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax'; + +interface MarkdownRange { + type: MarkdownType; + start: number; + length: number; + depth?: number; +} + +export type {MarkdownType, MarkdownRange}; diff --git a/src/web/utils/parserUtils.ts b/src/web/utils/parserUtils.ts index 05d4163a..3827e76c 100644 --- a/src/web/utils/parserUtils.ts +++ b/src/web/utils/parserUtils.ts @@ -4,15 +4,7 @@ import type {NodeType, TreeNode} from './treeUtils'; import type {PartialMarkdownStyle} from '../../styleUtils'; import {getCurrentCursorPosition, moveCursorToEnd, setCursorPosition} from './cursorUtils'; import {addStyleToBlock} from './blockUtils'; - -type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax' | 'mention-here' | 'mention-user' | 'mention-report'; - -type MarkdownRange = { - type: MarkdownType; - start: number; - length: number; - depth?: number; -}; +import type {MarkdownRange} from '../../commonTypes'; type Paragraph = { text: string; @@ -271,8 +263,7 @@ function updateInputStructure( const selection = getCurrentCursorPosition(target); cursorPosition = selection ? selection.start : null; } - const ranges = global.parseExpensiMarkToRanges(text); - const markdownRanges: MarkdownRange[] = ranges as MarkdownRange[]; + const markdownRanges = global.parseExpensiMarkToRanges(text); if (!text || targetElement.innerHTML === '
' || (targetElement && targetElement.innerHTML === '\n')) { targetElement.innerHTML = ''; targetElement.innerText = ''; @@ -298,5 +289,3 @@ function updateInputStructure( } export {updateInputStructure, parseRangesToHTMLNodes}; - -export type {MarkdownRange, MarkdownType}; diff --git a/src/web/utils/treeUtils.ts b/src/web/utils/treeUtils.ts index d85146db..f9354487 100644 --- a/src/web/utils/treeUtils.ts +++ b/src/web/utils/treeUtils.ts @@ -1,5 +1,5 @@ import type {HTMLMarkdownElement} from '../../MarkdownTextInput.web'; -import type {MarkdownRange, MarkdownType} from './parserUtils'; +import type {MarkdownRange, MarkdownType} from '../../commonTypes'; type NodeType = MarkdownType | 'line' | 'text' | 'br' | 'root'; diff --git a/types/global.d.ts b/types/global.d.ts index 80be06f2..9520011d 100644 --- a/types/global.d.ts +++ b/types/global.d.ts @@ -1,15 +1,8 @@ -export {}; - -type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax'; +import type {MarkdownRange} from '../src/commonTypes'; -type MarkdownRange = { - type: MarkdownType; - start: number; - length: number; - depth?: number; -}; +export {}; declare global { // eslint-disable-next-line no-var - var parseExpensiMarkToRanges: (markdown: string) => MarkdownMarkdownRange[]; + var parseExpensiMarkToRanges: (markdown: string) => MarkdownRange[]; }