Skip to content

Commit

Permalink
Merge pull request #394 from parasharrajat/html-md
Browse files Browse the repository at this point in the history
Fixed lin-break <br> HTML parsing
  • Loading branch information
Jag96 authored Jul 15, 2021
2 parents 77b43a2 + 80f6e55 commit cf78cdc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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

0 comments on commit cf78cdc

Please sign in to comment.