Skip to content

Commit

Permalink
Allow code fences without newline chars
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperhuangg committed May 24, 2021
1 parent 4af5cbe commit 36531c0
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/ExpensiMark.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ export default class ExpensiMark {
name: 'codeFence',

// < is a backtick symbol we are matching on three of them before then after a new line character
regex: /```\n((?:(?!```)[\s\S])+)\n```/g,

regex: /(```[\n]?)((?:(?![\n]?```)[\s\S])+)([\n]?```)/g,
// We're using a function here to perform an additional replace on the content
// inside the backticks because Android is not able to use <pre> tags and does
// not respect whitespace characters at all like HTML does. We do not want to mess
// with the new lines here since they need to be converted into <br>. And we don't
// want to do this anywhere else since that would break HTML.
// &nbsp; will create styling issues so use &#32;
replacement: (match, firstCapturedGroup) => {
const group = firstCapturedGroup.replace(/(?:(?![\n\r])\s)/g, '&#32;');
replacement: (match, _, secondCapturedGroup) => {
const group = secondCapturedGroup.replace(/(?:(?![\n\r])\s)/g, '&#32;');
return `<pre>${group}</pre>`;
},
},
Expand Down

0 comments on commit 36531c0

Please sign in to comment.