Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #1719 add context and node_name accessor in the type definition #1718

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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