From c8fba5cd692afb57756beea5edbbb606b615092b Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Wed, 20 Sep 2023 16:08:57 +0200 Subject: [PATCH] resolves #24 handle description list without text (#27) --- src/index.js | 3 ++- test/converter.spec.js | 19 +++++++++++++++++++ .../description-list-without-text.adoc | 11 +++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/description-list-without-text.adoc diff --git a/src/index.js b/src/index.js index ea37ea8..13888ac 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,4 @@ +/* global Opal */ class JupyterConverter { constructor (backend) { this.backend = backend @@ -386,7 +387,7 @@ class JupyterConverter { for (const term of terms) { source += `* **${term.getText()}**\\` } - if (dd) { + if (dd && dd !== Opal.nil) { if (dd.hasText()) { source += ` ${dd.getText()} diff --git a/test/converter.spec.js b/test/converter.spec.js index 613705c..d088dbc 100644 --- a/test/converter.spec.js +++ b/test/converter.spec.js @@ -388,4 +388,23 @@ $$ `) await debug(result, 'nested-blocks.ipynb') }) + it('should convert a description list without text', () => { + const inputFile = path.join(__dirname, 'fixtures', 'description-list-without-text.adoc') + const result = asciidoctor.convertFile(inputFile, { + safe: 'safe', + backend: 'jupyter', + to_file: false + }) + expect(result).is.not.empty() + const ipynb = JSON.parse(result) + expect(ipynb.cells[0].source.join('')).is.equal(`# Basics + +## Introduction + +* **Basic Matrix Creation**\\`) + expect(ipynb.cells[1].source.join('')).is.equal(`import numpy as np +matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) +print(f"matrix={matrix}") +`) + }) }) diff --git a/test/fixtures/description-list-without-text.adoc b/test/fixtures/description-list-without-text.adoc new file mode 100644 index 0000000..8ed321e --- /dev/null +++ b/test/fixtures/description-list-without-text.adoc @@ -0,0 +1,11 @@ += Basics + +== Introduction + +Basic Matrix Creation:: +[%dynamic,python] +---- +import numpy as np +matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) +print(f"matrix={matrix}") +---- \ No newline at end of file