From 42ad9bef86a05dc711b776db8515f73958694e86 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Tue, 10 Jan 2023 18:40:43 +0000 Subject: [PATCH] resolves #1658 Call Document#<< (#1681) resolves https://github.com/asciidoctor/asciidoctor.js/issues/1658 --- packages/core/spec/share/asciidoctor-spec.cjs | 5 +++-- packages/core/src/asciidoctor-core-api.js | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/core/spec/share/asciidoctor-spec.cjs b/packages/core/spec/share/asciidoctor-spec.cjs index ed5f5e2a0..429c6f65b 100644 --- a/packages/core/spec/share/asciidoctor-spec.cjs +++ b/packages/core/spec/share/asciidoctor-spec.cjs @@ -980,7 +980,7 @@ paragraph 3 const doc = asciidoctor.load(`= Title == Section A`) - const sectionB = asciidoctor.Section.create(doc, 2, false, { attributes: { foo: 'bar' } }) + const sectionB = asciidoctor.Section.create(doc, 2, true, { attributes: { foo: 'bar' } }) sectionB.setTitle('Section B') doc.append(sectionB) const sections = doc.findBy({ context: 'section' }) @@ -989,10 +989,11 @@ paragraph 3 expect(secondSection.getName()).to.equal('Section B') expect(secondSection.getTitle()).to.equal('Section B') expect(secondSection.getSectionName()).to.be.undefined() - expect(secondSection.isNumbered()).to.equal(false) + expect(secondSection.isNumbered()).to.equal(true) expect(secondSection.isSpecial()).to.equal(false) expect(secondSection.getCaption()).to.be.undefined() expect(secondSection.getAttribute('foo')).to.equal('bar') + expect(secondSection.getNumeral()).to.equal('1') }) it('should set role', function () { diff --git a/packages/core/src/asciidoctor-core-api.js b/packages/core/src/asciidoctor-core-api.js index df6337928..2dc6e5efd 100644 --- a/packages/core/src/asciidoctor-core-api.js +++ b/packages/core/src/asciidoctor-core-api.js @@ -777,7 +777,8 @@ AbstractBlock.prototype.getSections = function () { * @memberof AbstractBlock */ AbstractBlock.prototype.getNumeral = function () { - return this.$numeral() + const numeral = this.$numeral() + return numeral === Opal.nil ? undefined : numeral } /** @@ -1471,6 +1472,18 @@ AbstractNode.prototype.normalizeAssetPath = function (assetRef, assetName, autoC */ const Document = Opal.Asciidoctor.Document +/** + * Append a content Block to this Document. + * If the child block is a Section, assign an index to it. + * @param {AbstractBlock} block - the child Block to append to this parent Block + * @returns {AbstractBlock} - the parent block to which this block was appended. + * @memberof Document + */ +Document.prototype.append = function (block) { + this['$<<'](block) + return this +} + /** * Returns the SyntaxHighlighter associated with this document. *