diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-03-07 20:57:40 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-03-07 20:57:40 -0400 |
commit | fc6561a9b8603f2ab7732991b5b68a316413c1d2 (patch) | |
tree | 028decb4d7a243a6f3f29d07eb80ddf843e24725 | |
parent | e7c19e97447c69fdda5a89fcabda47f136578753 (diff) |
no paragraph break if previous line ends with <br>
-rwxr-xr-x | src/upd8.js | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/upd8.js b/src/upd8.js index 96fb3106..0d5a3ecb 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -484,6 +484,26 @@ function parseAttributes(string, {to}) { ])); } +function joinLineBreaks(sourceLines) { + const outLines = []; + + let lineSoFar = ''; + for (let i = 0; i < sourceLines.length; i++) { + const line = sourceLines[i]; + lineSoFar += line; + if (!line.endsWith('<br>')) { + outLines.push(lineSoFar); + lineSoFar = ''; + } + } + + if (lineSoFar) { + outLines.push(lineSoFar); + } + + return outLines; +} + function transformMultiline(text, { parseAttributes, transformInline @@ -529,7 +549,9 @@ function transformMultiline(text, { // interested in doing lol. sorry!!! let inBlockquote = false; - for (let line of splitLines(text)) { + let lines = splitLines(text); + lines = joinLineBreaks(lines); + for (let line of lines) { const imageLine = line.startsWith('<img'); line = line.replace(/<img (.*?)>/g, (match, attributes) => img({ lazy: true, |