Skip to content

Commit

Permalink
Merge pull request #593 from bernhardoj/fix/29921-remove-style-html-t…
Browse files Browse the repository at this point in the history
…o-text

Remove style tag when converting html to text
  • Loading branch information
lakchote authored Oct 27, 2023
2 parents e35083e + cae8908 commit 82bfcd1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions __tests__/ExpensiMark-HTMLToText-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ test('Test new line replacement on blockquote with heading inside', () => {
testString = '<blockquote><h1>heading A</h1><h1>heading B</h1></blockquote>';
expect(parser.htmlToText(testString)).toBe('heading A\n\nheading B');
});

test('Test remove style tag', () => {
const testString = '<div><svg><style>.default-avatar_20_svg__st1{fill:#008c59}</style></svg><p>a text</p></div>';
expect(parser.htmlToText(testString)).toBe('a text');
});
5 changes: 5 additions & 0 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ export default class ExpensiMark {
regex: /<\/(blockquote|h1|pre)>(.|\s)/gm,
replacement: '\n$2',
},
{
name: 'removeStyle',
regex: /<style>.*?<\/style>/gi,
replacement: '',
},
{
name: 'stripTag',
regex: /(<([^>]+)>)/gi,
Expand Down

0 comments on commit 82bfcd1

Please sign in to comment.