From a433d3ebbad9d04b6c1d253fc51c5e3bbabcce13 Mon Sep 17 00:00:00 2001 From: raymond Date: Wed, 27 Dec 2023 11:06:36 +0000 Subject: [PATCH] added test to ensure that node_name and context are exposed. context and node_name now exposed as properties. add setContext function to API --- .gitignore | 1 + packages/core/.gitignore | 3 +++ packages/core/spec/node/asciidoctor.spec.js | 16 ++++++++++++++++ packages/core/types/index.d.ts | 4 ++++ packages/core/types/tests.ts | 13 +++++++++++++ 5 files changed, 37 insertions(+) diff --git a/.gitignore b/.gitignore index 91fa8cf82..4d41f8c75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /node_modules/ npm-debug.log +/.idea/ diff --git a/packages/core/.gitignore b/packages/core/.gitignore index e2cc03e92..7de593cfa 100644 --- a/packages/core/.gitignore +++ b/packages/core/.gitignore @@ -6,3 +6,6 @@ npm-debug.log # generated using rollup /spec/node/asciidoctor.spec.cjs + +# IntelliJ project files +/.idea/ diff --git a/packages/core/spec/node/asciidoctor.spec.js b/packages/core/spec/node/asciidoctor.spec.js index e92498e99..8a6011fbb 100644 --- a/packages/core/spec/node/asciidoctor.spec.js +++ b/packages/core/spec/node/asciidoctor.spec.js @@ -825,6 +825,22 @@ image::https://asciidoctor.org/images/octocat.jpg[GitHub mascot]` expect(blocksWithLineNumber.length >= 18).to.be.true() }) + it('should be able to convert the context of a block', () => { + const doc = asciidoctor.loadFile(resolveFixture('documentblocks.adoc')) + const blocks = doc.findBy({ context: 'ulist' }) + expect(blocks.length).to.equal(2) + blocks[0].context = 'colist' + expect(blocks[0].getContext()).to.equal('colist') + }) + + it('should be able to set the name of a node', () => { + const doc = asciidoctor.loadFile(resolveFixture('documentblocks.adoc')) + const blocks = doc.findBy({ context: 'ulist' }) + expect(blocks.length).to.equal(2) + blocks[0].node_name = 'colist' + expect(blocks[0].getNodeName()).to.equal('colist') + }) + if (asciidoctorCoreSemVer.gte('200')) { // REMIND: Before Asciidoctor 2.0.0 date was not UTC it('should get document date (and honor SOURCE_DATE_EPOCH)', () => { diff --git a/packages/core/types/index.d.ts b/packages/core/types/index.d.ts index 41e4e6f6a..77ea80e40 100644 --- a/packages/core/types/index.d.ts +++ b/packages/core/types/index.d.ts @@ -2716,6 +2716,10 @@ export class AbstractNode implements Logging { * * @returns An Array of Strings representing the substitution operation or nothing if no subs are found. */ + + node_name: string; + context: string + resolveSubstitutions(subs: string, type?: string, defaults?: string[], subject?: string): string[] | undefined; /** diff --git a/packages/core/types/tests.ts b/packages/core/types/tests.ts index 986006765..0387634db 100644 --- a/packages/core/types/tests.ts +++ b/packages/core/types/tests.ts @@ -108,6 +108,19 @@ assert(doc.getSourcemap()); // Block const block = processor.Block.create(doc, 'paragraph'); assert(block.getContext() === 'paragraph'); + +// Try to alter the block context +block.context = 'ulist'; +assert(block.getContext() === 'ulist'); +block.context = 'paragraph'; +assert(block.getContext() === 'paragraph'); + +// Try to alter the name of the node +block.node_name = 'ulist' +assert(block.getNodeName() === 'ulist') +block.node_name = 'paragraph' +assert(block.getNodeName() === 'paragraph') + assert(block.applySubstitutions(' -- the root of all web') === '<html> — the root of all web'); assert(Object.keys(block.getAttributes()).length === 0); block.setAttribute('awesome', true);