Skip to content

Commit

Permalink
Fix the spacing for the implicit line breaks in odt again
Browse files Browse the repository at this point in the history
See #434
  • Loading branch information
ggodlewski committed Feb 17, 2024
1 parent 713ab49 commit 05cf628
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/odt/postprocess/mergeParagraphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ export function mergeParagraphs(markdownChunks: MarkdownChunks, rewriteRules: Re
const findFirstTextAfterPos = (start: number): string | null => {
for (let pos = start + 1; pos < markdownChunks.chunks.length; pos++) {
const currentChunk = markdownChunks.chunks[pos];
if ('text' in currentChunk && currentChunk.text !== '') {
if ('text' in currentChunk && currentChunk.text.trim() !== '') {
return currentChunk.text;
}
}
return null;
};

const nextText = findFirstTextAfterPos(nextParaClosing);
const nextText = findFirstTextAfterPos(position);
if (nextText === '* ' || nextText?.trim().length === 0) {
markdownChunks.chunks.splice(position, 2, {
isTag: false,
text: '\n',
mode: 'md',
comment: 'End of line, but next line is list' + nextText + ' ' + nextParaClosing
comment: 'End of line, but next line is list'
});
position--;
previousParaPosition = 0;
Expand Down
7 changes: 7 additions & 0 deletions test/odt_md/Issues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ describe('MarkDownTransformTest', () => {
assert.ok(compareTexts(testMarkdown, markdown, false));
});

it('test ./issue-434-2', async () => {
// https://github.com/mieweb/wikiGDrive/issues/434
const testMarkdown = fs.readFileSync(__dirname + '/issue-434-2.md').toString();
const markdown = await transformOdt('issue-434-2');
assert.ok(compareTexts(testMarkdown, markdown, false));
});

it('test ./issue-435-436', async () => {
// https://github.com/mieweb/wikiGDrive/issues/435
// https://github.com/mieweb/wikiGDrive/issues/436
Expand Down
2 changes: 1 addition & 1 deletion test/odt_md/example-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ After subtable</td>

### Heading 3 - a diagram with links

[Diagram](gdoc:1Du-DYDST4liLykJl0fHSCvuQYIYhtOfwco-ntn38Dy8)
[Diagram](gdoc:1Du-DYDST4liLykJl0fHSCvuQYIYhtOfwco-ntn38Dy8)
[Diagram](gdoc:1Du-DYDST4liLykJl0fHSCvuQYIYhtOfwco-ntn38Dy8)

### Heading 3 - with a Table of contents
Expand Down
15 changes: 15 additions & 0 deletions test/odt_md/issue-434-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
**This** is a line
**This** is line two


* This is a bulleted test
* Second line



hi

This is a cool new wikiGDrive! With a change.

![](1000000000000801000006000FC688CE4398B42C.jpg)![](100000000000080100000600C22E7BC1728488D6.jpg)![](10000000000009C4000007537CA7AEBC30C18882.jpg)![](10000000000009C400000753E2645860B6CEB342.jpg)
Binary file added test/odt_md/issue-434-2.odt
Binary file not shown.

0 comments on commit 05cf628

Please sign in to comment.