Skip to content

Commit

Permalink
resolves #1719 add context and node_name accessor in the type definit…
Browse files Browse the repository at this point in the history
…ion (#1718)
  • Loading branch information
RayOffiah committed Jan 6, 2024
1 parent 3ee0fec commit afddcea
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules/
npm-debug.log
/.idea/
3 changes: 3 additions & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ npm-debug.log

# generated using rollup
/spec/node/asciidoctor.spec.cjs

# IntelliJ project files
/.idea/
16 changes: 16 additions & 0 deletions packages/core/spec/node/asciidoctor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
13 changes: 13 additions & 0 deletions packages/core/types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('<html> -- the root of all web') === '&lt;html&gt;&#8201;&#8212;&#8201;the root of all web');
assert(Object.keys(block.getAttributes()).length === 0);
block.setAttribute('awesome', true);
Expand Down

0 comments on commit afddcea

Please sign in to comment.