mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-11-19 10:38:20 +01:00
fix: no indented blank line after a nested list
A nested list left an indented blank line behind when saved, which showed as an extra empty line after the list in source view. Refs #277
This commit is contained in:
1 parent
2014365e4a
commit
e168f4e004
2 files changed
+7
-1
No files matched your search
@@ -82,7 +82,9 @@ export function joinListItemBlocks(blocks: readonly ListItemBlock[]): string {
|
||||
const parts: string[] = [];
|
||||
blocks.forEach((block, index) => {
|
||||
if (block.isList) {
|
||||
parts.push(block.text.replace(/\n$/, '').split('\n').map((line) => ' ' + line).join('\n'));
|
||||
// A serialized list ends with a blank line; left in, it became an indented blank line here
|
||||
// and an extra empty line after the outer list.
|
||||
parts.push(block.text.replace(/\n+$/, '').split('\n').map((line) => (line ? ' ' + line : line)).join('\n'));
|
||||
} else if (index === 0) {
|
||||
parts.push(block.text);
|
||||
} else {
|
||||
|
||||
@@ -521,6 +521,10 @@ const item = (text, isList = false) => ({ text, isList });
|
||||
|
||||
test('blocks after a list item\'s first paragraph stay inside the item, separated by a blank line', () => {
|
||||
assert.equal(joinListItemBlocks([item('only')]), 'only\n');
|
||||
// A nested list arrives ending in a blank line; it must not leave an indented blank line behind (issue #277).
|
||||
const list = (text) => ({ text, isList: true });
|
||||
assert.equal(joinListItemBlocks([item('parent'), list('- a\n- b\n\n')]), 'parent\n - a\n - b\n');
|
||||
assert.equal(joinListItemBlocks([item('parent'), list('- a\n - deep\n\n')]), 'parent\n - a\n - deep\n');
|
||||
assert.equal(joinListItemBlocks([item('first'), item('second\n')]), 'first\n\n second\n');
|
||||
assert.equal(
|
||||
joinListItemBlocks([item('step'), item('```sh\nrun\n\n\nagain\n```\n'), item('after\n')]),
|
||||
|
||||
Reference in new issue
Block a user