Skip to content

Commit

Permalink
fix: strip HTML tags properly (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Oct 17, 2020
1 parent bbbcbd4 commit 8e55d37
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (languageParser) {
// parser instead of the TSX parser.
const sourceCode = fs
.readFileSync(filepath, { encoding: 'utf8', flag: 'r' })
.replace(/<\/?[^>]+(>|$)/g, '');
.replace(/(?:<?[^>]+>(.*)<\/[^>]+>|<\/[^>]+\/>)/g, '$1');

const tree = parser.parse(sourceCode);
const parserService = getParserService(language, [
Expand Down
18 changes: 15 additions & 3 deletions test/filetypes/javascript/jsx.vader
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
# ==============================================================================
Given javascript (function that contains JSX):
const Test = ({ someVal }) => {
return <div>{true && someVal ? <small className="helper-text">{someVal}</small> : null}</div>;
return (
<div>
{true && someVal ? <small className="helper-text">{someVal}</small> : null}
<span />
<span />
</div>
);
};

Do (trigger doge):
\<C-d>

Expect javascript (generated comment with a description and a @return tag):
Expect javascript (generated comment with a description, @param and @return tags):
/**
* [TODO:description]
*
Expand All @@ -18,5 +24,11 @@ Expect javascript (generated comment with a description and a @return tag):
* @return {[TODO:type]} [TODO:description]
*/
const Test = ({ someVal }) => {
return <div>{true && someVal ? <small className="helper-text">{someVal}</small> : null}</div>;
return (
<div>
{true && someVal ? <small className="helper-text">{someVal}</small> : null}
<span />
<span />
</div>
);
};

0 comments on commit 8e55d37

Please sign in to comment.