Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed lin-break <br> HTML parsing #394

Merged
merged 1 commit into from
Jul 15, 2021
Merged
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
4 changes: 2 additions & 2 deletions __tests__/ExpensiMark-Markdown-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ test('Test HTML string with seperate closing tags (<br><br/>) to markdown ', ()
});

test('Test HTML string with attributes', () => {
const testString = '<em style="color:red;">This is</em> a <button disabled>test</button>. None of <strong data-link=\'bad\'>these strings</strong>.';
const resultString = '_This is_ a test. None of *these strings*.';
const testString = '<em style="color:red;">This is</em><br style="border-color:red;"> a <button disabled>test</button>. None of <strong data-link=\'bad\'>these strings</strong>.';
const resultString = '_This is_\n a test. None of *these strings*.';

expect(parser.htmlToMarkdown(testString)).toBe(resultString);
});
4 changes: 3 additions & 1 deletion lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export default class ExpensiMark {

// Replaces open and closing <br><br/> tags with a single <br/>
pre: inputString => inputString.replace('<br></br>', '<br/>').replace('<br><br/>', '<br/>'),
regex: /<br\s*[/]?>\n?/gi,

// Include the immediately followed newline as `<br>\n` should be equal to one \n.
regex: /<br(?:"[^"]*"|'[^']*'|[^'">])*>(?![^<]*(<\/pre>|<\/code>))\n?/gi,
replacement: '\n'
},
{
Expand Down