Skip to content

Commit

Permalink
Remove underscore from markdown parser (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skalakid authored Jun 17, 2024
1 parent 2ada06e commit a06ae8d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module.exports = {
'error',
{ fixMixedExportsWithInlineTypeSpecifier: false },
],
'valid-jsdoc': 'off',
'tsdoc/syntax': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/array-type': ['error', {default: 'array-simple'}],
Expand Down
12 changes: 6 additions & 6 deletions parser/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// eslint-disable-next-line import/no-unresolved
import ExpensiMark from 'expensify-common/dist/ExpensiMark';
import _ from 'underscore';
import * as Utils from './utils';

type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax';
type Range = {
Expand Down Expand Up @@ -49,7 +49,7 @@ function parseTokensToTree(tokens: Token[]): StackItem {
const stack: StackItem[] = [{tag: '<>', children: []}];
tokens.forEach(([type, payload]) => {
if (type === 'TEXT') {
const text = _.unescape(payload);
const text = Utils.unescapeText(payload);
const top = stack[stack.length - 1];
top!.children.push(text);
} else if (type === 'HTML') {
Expand Down Expand Up @@ -160,10 +160,10 @@ function parseTreeToTextAndRanges(tree: StackItem): [string, Range[]] {
appendSyntax('```');
} else if (node.tag.startsWith('<a href="')) {
const rawHref = node.tag.match(/href="([^"]*)"/)![1]!; // always present
const href = _.unescape(rawHref);
const href = Utils.unescapeText(rawHref);
const isLabeledLink = node.tag.match(/data-link-variant="([^"]*)"/)![1] === 'labeled';
const dataRawHref = node.tag.match(/data-raw-href="([^"]*)"/);
const matchString = dataRawHref ? _.unescape(dataRawHref[1]!) : href;
const matchString = dataRawHref ? Utils.unescapeText(dataRawHref[1]!) : href;
if (!isLabeledLink && node.children.length === 1 && typeof node.children[0] === 'string' && (node.children[0] === matchString || `mailto:${node.children[0]}` === href)) {
addChildrenWithStyle(node.children[0], 'link');
} else {
Expand All @@ -178,12 +178,12 @@ function parseTreeToTextAndRanges(tree: StackItem): [string, Range[]] {
const alt = node.tag.match(/alt="([^"]*)"/);
const hasAlt = node.tag.match(/data-link-variant="([^"]*)"/)![1] === 'labeled';
const rawLink = node.tag.match(/data-raw-href="([^"]*)"/);
const linkString = rawLink ? _.unescape(rawLink[1]!) : src;
const linkString = rawLink ? Utils.unescapeText(rawLink[1]!) : src;

appendSyntax('!');
if (hasAlt) {
appendSyntax('[');
processChildren(_.unescape(alt?.[1] || ''));
processChildren(Utils.unescapeText(alt?.[1] || ''));
appendSyntax(']');
}
appendSyntax('(');
Expand Down
3 changes: 1 addition & 2 deletions parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"typescript": "^5.3.3"
},
"dependencies": {
"expensify-common": "2.0.12",
"underscore": "^1.13.6"
"expensify-common": "2.0.12"
}
}
Loading

0 comments on commit a06ae8d

Please sign in to comment.