Skip to content

Commit

Permalink
Merge pull request Expensify#30476 from bernhardoj/fix/29921-selection
Browse files Browse the repository at this point in the history
Fix selection includes SVG style and data-testid value
  • Loading branch information
johnmlee101 authored Oct 31, 2023
2 parents 74b7504 + 9ac8eba commit 0a27554
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"date-fns-tz": "^2.0.0",
"dom-serializer": "^0.2.2",
"domhandler": "^4.3.0",
"expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#2adc24c4e889b3a15f199a6b273e343c7d9cff78",
"expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#82bfcd1cb077afd03d1c8c069618c7dd5bd405d8",
"fbjs": "^3.0.2",
"htmlparser2": "^7.2.0",
"idb-keyval": "^6.2.1",
Expand Down
7 changes: 3 additions & 4 deletions src/libs/SelectionScraper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {parseDocument} from 'htmlparser2';
import CONST from '@src/CONST';
import GetCurrentSelection from './types';

const elementsWillBeSkipped = ['html', 'body'];
const markdownElements = ['h1', 'strong', 'em', 'del', 'blockquote', 'q', 'code', 'pre', 'a', 'br', 'li', 'ul', 'ol', 'b', 'i', 's'];
const tagAttribute = 'data-testid';

/**
Expand Down Expand Up @@ -113,10 +113,9 @@ const replaceNodes = (dom: Node, isChildOfEditorElement: boolean): Node => {
data = Str.htmlEncode(dom.data);
} else if (dom instanceof Element) {
domName = dom.name;
// We are skipping elements which has html and body in data-testid, since ExpensiMark can't parse it. Also this data
// has no meaning for us.
if (dom.attribs?.[tagAttribute]) {
if (!elementsWillBeSkipped.includes(dom.attribs[tagAttribute])) {
// If it's a markdown element, rename it according to the value of data-testid, so ExpensiMark can parse it
if (markdownElements.includes(dom.attribs[tagAttribute])) {
domName = dom.attribs[tagAttribute];
}
} else if (dom.name === 'div' && dom.children.length === 1 && isChildOfEditorElement) {
Expand Down

0 comments on commit 0a27554

Please sign in to comment.