Skip to content
Closed
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
11 changes: 11 additions & 0 deletions parser/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
presets: [
[
'@babel/env',
{
modules: false,
},
],
],
plugins: ['@babel/plugin-transform-classes'],
};
4 changes: 2 additions & 2 deletions parser/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// @ts-ignore - to review how it's implemented in ExpensiMark
import { ExpensiMark } from 'expensify-common/lib/ExpensiMark';
import ExpensiMark from 'expensify-common/lib/ExpensiMark';
import _ from 'underscore';

type Range = [string, number, number];
type Token = ['TEXT' | 'HTML', string];
type StackItem = { tag: string; children: Array<StackItem | string> };

function parseMarkdownToHTML(markdown: string): string {
const parser = ExpensiMark;
const parser = new ExpensiMark();
const html = parser.replace(markdown, {
shouldKeepRawInput: true,
});
Expand Down
6 changes: 5 additions & 1 deletion parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
"test": "jest",
"build": "esbuild index.ts --bundle --minify --outfile=react-native-live-markdown-parser.js",
"run": "node react-native-live-markdown-parser.js",
"postinstall": "patch-package"
"postinstall": "patch-package && babel ./node_modules/expensify-common/lib/ExpensiMark.js --out-file ./node_modules/expensify-common/lib/ExpensiMark.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.7",
"@babel/plugin-transform-classes": "^7.23.5",
"@babel/preset-env": "^7.23.7",
"@types/underscore": "^1.11.15",
"esbuild": "0.19.4",
"esbuild-plugin-tsc": "^0.4.0",
Expand Down
122 changes: 1 addition & 121 deletions parser/patches/expensify-common+1.0.0.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,125 +9,5 @@ index 4225717..0ae0962 100644
- EMOJIS: /[\p{Extended_Pictographic}\u200d\u{1f1e6}-\u{1f1ff}\u{1f3fb}-\u{1f3ff}\u{e0020}-\u{e007f}\u20E3\uFE0F]|[#*0-9]\uFE0F?\u20E3/gu,
+ EMOJIS: /[\u200d\u{1f1e6}-\u{1f1ff}\u{1f3fb}-\u{1f3ff}\u{e0020}-\u{e007f}\u20E3\uFE0F]|[#*0-9]\uFE0F?\u20E3/gu,
},

REPORT: {
diff --git a/node_modules/expensify-common/lib/ExpensiMark.js b/node_modules/expensify-common/lib/ExpensiMark.js
index 4e149ca..c94b383 100644
--- a/node_modules/expensify-common/lib/ExpensiMark.js
+++ b/node_modules/expensify-common/lib/ExpensiMark.js
@@ -7,8 +7,8 @@ const MARKDOWN_LINK_REGEX = new RegExp(`\\[([^\\][]*(?:\\[[^\\][]*][^\\][]*)*)]\

const SLACK_SPAN_NEW_LINE_TAG = '<span class="c-mrkdwn__br" data-stringify-type="paragraph-break" style="box-sizing: inherit; display: block; height: unset;"></span>';

-export default class ExpensiMark {
- constructor() {
+export const ExpensiMark = {
+ initializer() {
/**
* The list of regex replacements to do on a comment. Check the link regex is first so links are processed
* before other delimiters
@@ -457,7 +457,7 @@ export default class ExpensiMark {
* @type {Object[]}
*/
this.shouldKeepWhitespaceRules = this.rules.filter(rule => !this.whitespaceRulesToDisable.includes(rule.name)).map(rule => rule.name);
- }
+ },

/**
* Replaces markdown with html elements
@@ -503,7 +503,7 @@ export default class ExpensiMark {
}

return replacedText;
- }
+ },

/**
* Checks matched URLs for validity and replace valid links with html elements
@@ -610,7 +610,7 @@ export default class ExpensiMark {
}

return replacedText;
- }
+ },

/**
* Checks matched Emails for validity and replace valid links with html elements
@@ -649,7 +649,7 @@ export default class ExpensiMark {
replacedText = replacedText.concat(textToCheck.substr(startIndex));
}
return replacedText;
- }
+ },

/**
* replace block element with '\n' if :
@@ -689,7 +689,7 @@ export default class ExpensiMark {
});

return joinedText;
- }
+ },

/**
* Replaces HTML with markdown
@@ -716,7 +716,7 @@ export default class ExpensiMark {
generatedMarkdown = generatedMarkdown.replace(rule.regex, rule.replacement);
});
return Str.htmlDecode(this.replaceBlockElementWithNewLine(generatedMarkdown));
- }
+ },

/**
* Convert HTML to text
@@ -735,7 +735,7 @@ export default class ExpensiMark {
// We use 'htmlDecode' instead of 'unescape' to replace entities like '&#32;'
replacedText = Str.htmlDecode(replacedText);
return replacedText;
- }
+ },

/**
* Modify text for Quotes replacing chevrons with html elements
@@ -798,7 +798,7 @@ export default class ExpensiMark {
replacedText = textToCheck;
}
return replacedText;
- }
+ },

/**
* Format the content of blockquote if the text matches the regex or else just return the original text
@@ -819,7 +819,7 @@ export default class ExpensiMark {
return replacement(textToFormat);
}
return textToCheck;
- }
+ },

/**
* Check if the input text includes only the open or the close tag of an element.
@@ -858,7 +858,7 @@ export default class ExpensiMark {

// If there are any tags left in the stack, they're unclosed
return tagStack.length !== 0;
- }
+ },

/**
* @param {String} comment
@@ -880,7 +880,7 @@ export default class ExpensiMark {
console.warn('Error parsing url in ExpensiMark.extractLinksInMarkdownComment', {error: e});
return undefined;
}
- }
+ },

/**
* Compares two markdown comments and returns a list of the links removed in a new comment.
@@ -895,3 +895,5 @@ export default class ExpensiMark {
return linksInOld === undefined || linksInNew === undefined ? [] : _.difference(linksInOld, linksInNew);
}
}
+
+ExpensiMark.initializer();
Loading