Skip to content

Commit 43e8a4b

Browse files
authored
Add an extra newline between code blocks (#28)
1 parent c8fba5c commit 43e8a4b

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,10 @@ ${dd.getText()}
447447
if (result && result.length > 0) {
448448
if (!result.find(cell => cell.cell_type !== 'markdown')) {
449449
if (joinCharacter !== '' && result[0].metadata && result[0].metadata.node_name !== 'colist') {
450-
lastCell.source[lastCell.source.length - 1] = lastCell.source[lastCell.source.length - 1] + joinCharacter
450+
const blockJoiner = result[0].metadata.node_name === 'listing' && lastCell.metadata.node_name === 'listing'
451+
? '\n'
452+
: ''
453+
lastCell.source[lastCell.source.length - 1] = lastCell.source[lastCell.source.length - 1] + joinCharacter + blockJoiner
451454
}
452455
lastCell.source.push(...result.reduce((acc, cell) => acc.concat(cell.source), [])) // flatMap Node > 11
453456
} else {

test/converter.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,40 @@ matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
407407
print(f"matrix={matrix}")
408408
`)
409409
})
410+
it('should convert code blocks as Markdown', () => {
411+
const inputFile = path.join(__dirname, 'fixtures', 'multiple-codeblocks.adoc')
412+
const result = asciidoctor.convertFile(inputFile, {
413+
safe: 'safe',
414+
backend: 'jupyter',
415+
to_file: false
416+
})
417+
expect(result).is.not.empty()
418+
const ipynb = JSON.parse(result)
419+
expect(ipynb.cells[0].source.join('')).is.equal(`\`\`\`cpp
420+
#ifndef __MYFUNC_HPP__ #define __MYFUNC_HPP__
421+
422+
void mymsg();
423+
424+
#endif
425+
\`\`\`
426+
427+
\`\`\`cpp
428+
#include <iostream>
429+
430+
void mymsg()
431+
{
432+
std::cout << "Hello, world";
433+
}
434+
\`\`\`
435+
436+
\`\`\`cpp
437+
#include "myfunc.hpp"
438+
439+
int main()
440+
{
441+
mymsg();
442+
return 0;
443+
}
444+
\`\`\``)
445+
})
410446
})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.myfunc.hpp+
2+
[source,cpp]
3+
----
4+
#ifndef __MYFUNC_HPP__ #define __MYFUNC_HPP__
5+
6+
void mymsg();
7+
8+
#endif
9+
----
10+
11+
.myfunc.cpp
12+
[source,cpp]
13+
----
14+
#include <iostream>
15+
16+
void mymsg()
17+
{
18+
std::cout << "Hello, world";
19+
}
20+
----
21+
22+
.mymain.cpp
23+
[source,cpp]
24+
----
25+
#include "myfunc.hpp"
26+
27+
int main()
28+
{
29+
mymsg();
30+
return 0;
31+
}
32+
----

0 commit comments

Comments
 (0)