diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-11-27 21:45:38 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-11-27 21:45:38 -0400 |
commit | 6844d1275f0b0025b09ca909a99d705447792e1f (patch) | |
tree | eb7e518f82254dce560a94d94cab851eefc46b2d | |
parent | a65693efe23b97da173463f207979f81767d791c (diff) |
content, test: transformContent: handle indentation more carefully
-rw-r--r-- | src/content/dependencies/transformContent.js | 11 | ||||
-rw-r--r-- | tap-snapshots/test/snapshot/transformContent.js.test.cjs | 39 | ||||
-rw-r--r-- | test/snapshot/transformContent.js | 39 |
3 files changed, 85 insertions, 4 deletions
diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index b0a7796c..2002ebee 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -562,11 +562,14 @@ export default { const transformMultiline = () => { const markedInput = extractNonTextNodes() - // Compress multiple line breaks into single line breaks. - .replace(/\n{2,}/g, '\n') + // Compress multiple line breaks into single line breaks, + // except when they're preceding or following indented + // text (by at least two spaces). + .replace(/(?<! .*)\n{2,}(?!^ )/gm, '\n') /* eslint-disable-line no-regex-spaces */ // Expand line breaks which don't follow a list, quote, - // or <br> / " ". - .replace(/(?<!^ *-.*|^>.*| $|<br>$)\n+/gm, '\n\n') /* eslint-disable-line no-regex-spaces */ + // or <br> / " ", and which don't precede or follow + // indented text (by at least two spaces). + .replace(/(?<!^ *-.*|^>.*|^ .*\n*| $|<br>$)\n+(?! |\n)/gm, '\n\n') /* eslint-disable-line no-regex-spaces */ // Expand line breaks which are at the end of a list. .replace(/(?<=^ *-.*)\n+(?!^ *-)/gm, '\n\n') // Expand line breaks which are at the end of a quote. diff --git a/tap-snapshots/test/snapshot/transformContent.js.test.cjs b/tap-snapshots/test/snapshot/transformContent.js.test.cjs index 85ee740f..9ab299e6 100644 --- a/tap-snapshots/test/snapshot/transformContent.js.test.cjs +++ b/tap-snapshots/test/snapshot/transformContent.js.test.cjs @@ -10,6 +10,45 @@ exports[`test/snapshot/transformContent.js > TAP > transformContent (snapshot) > <p>Very nice: <time datetime="Fri, 25 Oct 2413 03:00:00 GMT">10/25/2413</time></p> ` +exports[`test/snapshot/transformContent.js > TAP > transformContent (snapshot) > hanging indent list 1`] = ` +<p>Hello!</p> +<ul> +<li><p>I am a list item and I +go on and on and on +and on and on and on.</p> +</li> +<li><p>I am another list item. +Yeah.</p> +</li> +</ul> +<p>In-between!</p> +<ul> +<li>Spooky, +spooky, I say!</li> +<li>Following list item. +No empty line around me.</li> +<li>Very cool. +So, so cool.</li> +</ul> +<p>Goodbye!</p> +` + +exports[`test/snapshot/transformContent.js > TAP > transformContent (snapshot) > indent on a directly following line 1`] = ` +<div> + <span>Wow!</span> +</div> +` + +exports[`test/snapshot/transformContent.js > TAP > transformContent (snapshot) > indent on an indierctly following line 1`] = ` +<p>Some text.</p> +<p>Yes, some more text.</p> +<pre><code>I am hax0rz!! +All yor base r blong 2 us. +</code></pre> +<p>Aye.</p> +<p>Aye aye aye.</p> +` + exports[`test/snapshot/transformContent.js > TAP > transformContent (snapshot) > inline images 1`] = ` <p><img src="snooping.png"> as USUAL...</p> <p>What do you know? <img src="cowabunga.png" width="24" height="32"></p> diff --git a/test/snapshot/transformContent.js b/test/snapshot/transformContent.js index b05beac1..740d94df 100644 --- a/test/snapshot/transformContent.js +++ b/test/snapshot/transformContent.js @@ -37,6 +37,45 @@ testContentFunctions(t, 'transformContent (snapshot)', async (t, evaluate) => { `That's right, [[album:cool-album]]!`); quickSnapshot( + 'indent on a directly following line', + `<div>\n` + + ` <span>Wow!</span>\n` + + `</div>`); + + quickSnapshot( + 'indent on an indierctly following line', + `Some text.\n` + + `Yes, some more text.\n` + + `\n` + + ` I am hax0rz!!\n` + + ` All yor base r blong 2 us.\n` + + `\n` + + `Aye.\n` + + `Aye aye aye.`); + + quickSnapshot( + 'hanging indent list', + `Hello!\n` + + `\n` + + `* I am a list item and I\n` + + ` go on and on and on\n` + + ` and on and on and on.\n` + + `\n` + + `* I am another list item.\n` + + ` Yeah.\n` + + `\n` + + `In-between!\n` + + `\n` + + `* Spooky,\n` + + ` spooky, I say!\n` + + `* Following list item.\n` + + ` No empty line around me.\n` + + `* Very cool.\n` + + ` So, so cool.\n` + + `\n` + + `Goodbye!`); + + quickSnapshot( 'inline images', `<img src="snooping.png"> as USUAL...\n` + `What do you know? <img src="cowabunga.png" width="24" height="32">\n` + |