From 6844d1275f0b0025b09ca909a99d705447792e1f Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 27 Nov 2023 21:45:38 -0400 Subject: content, test: transformContent: handle indentation more carefully --- src/content/dependencies/transformContent.js | 11 +++--- .../test/snapshot/transformContent.js.test.cjs | 39 ++++++++++++++++++++++ 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(/(? / " ". - .replace(/(?.*| $|
$)\n+/gm, '\n\n') /* eslint-disable-line no-regex-spaces */ + // or
/ " ", and which don't precede or follow + // indented text (by at least two spaces). + .replace(/(?.*|^ .*\n*| $|
$)\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) >

Very nice:

` +exports[`test/snapshot/transformContent.js > TAP > transformContent (snapshot) > hanging indent list 1`] = ` +

Hello!

+ +

In-between!

+ +

Goodbye!

+` + +exports[`test/snapshot/transformContent.js > TAP > transformContent (snapshot) > indent on a directly following line 1`] = ` +
+ Wow! +
+` + +exports[`test/snapshot/transformContent.js > TAP > transformContent (snapshot) > indent on an indierctly following line 1`] = ` +

Some text.

+

Yes, some more text.

+
I am hax0rz!!
+All yor base r blong 2 us.
+
+

Aye.

+

Aye aye aye.

+` + exports[`test/snapshot/transformContent.js > TAP > transformContent (snapshot) > inline images 1`] = `

as USUAL...

What do you know?

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 @@ -36,6 +36,45 @@ testContentFunctions(t, 'transformContent (snapshot)', async (t, evaluate) => { `This is [[album:cool-album|my favorite album]].\n` + `That's right, [[album:cool-album]]!`); + quickSnapshot( + 'indent on a directly following line', + `
\n` + + ` Wow!\n` + + `
`); + + 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', ` as USUAL...\n` + -- cgit 1.3.0-6-gf8a5