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

Move MarkdownType and MarkdownRange to commonTypes.ts #466

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions src/__tests__/webParser.test.tsx
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/commonTypes.ts
Original file line number Diff line number Diff line change
@@ -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};
15 changes: 2 additions & 13 deletions src/web/utils/parserUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 === '<br>' || (targetElement && targetElement.innerHTML === '\n')) {
targetElement.innerHTML = '';
targetElement.innerText = '';
Expand All @@ -298,5 +289,3 @@ function updateInputStructure(
}

export {updateInputStructure, parseRangesToHTMLNodes};

export type {MarkdownRange, MarkdownType};
2 changes: 1 addition & 1 deletion src/web/utils/treeUtils.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
13 changes: 3 additions & 10 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -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[];
}
Loading