Skip to content

Commit afddcea

Browse files
authored
resolves #1719 add context and node_name accessor in the type definition (#1718)
1 parent 3ee0fec commit afddcea

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/node_modules/
22
npm-debug.log
3+
/.idea/

packages/core/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ npm-debug.log
66

77
# generated using rollup
88
/spec/node/asciidoctor.spec.cjs
9+
10+
# IntelliJ project files
11+
/.idea/

packages/core/spec/node/asciidoctor.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,22 @@ image::https://asciidoctor.org/images/octocat.jpg[GitHub mascot]`
825825
expect(blocksWithLineNumber.length >= 18).to.be.true()
826826
})
827827

828+
it('should be able to convert the context of a block', () => {
829+
const doc = asciidoctor.loadFile(resolveFixture('documentblocks.adoc'))
830+
const blocks = doc.findBy({ context: 'ulist' })
831+
expect(blocks.length).to.equal(2)
832+
blocks[0].context = 'colist'
833+
expect(blocks[0].getContext()).to.equal('colist')
834+
})
835+
836+
it('should be able to set the name of a node', () => {
837+
const doc = asciidoctor.loadFile(resolveFixture('documentblocks.adoc'))
838+
const blocks = doc.findBy({ context: 'ulist' })
839+
expect(blocks.length).to.equal(2)
840+
blocks[0].node_name = 'colist'
841+
expect(blocks[0].getNodeName()).to.equal('colist')
842+
})
843+
828844
if (asciidoctorCoreSemVer.gte('200')) {
829845
// REMIND: Before Asciidoctor 2.0.0 date was not UTC
830846
it('should get document date (and honor SOURCE_DATE_EPOCH)', () => {

packages/core/types/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,10 @@ export class AbstractNode implements Logging {
27162716
*
27172717
* @returns An Array of Strings representing the substitution operation or nothing if no subs are found.
27182718
*/
2719+
2720+
node_name: string;
2721+
context: string
2722+
27192723
resolveSubstitutions(subs: string, type?: string, defaults?: string[], subject?: string): string[] | undefined;
27202724

27212725
/**

packages/core/types/tests.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,19 @@ assert(doc.getSourcemap());
108108
// Block
109109
const block = processor.Block.create(doc, 'paragraph');
110110
assert(block.getContext() === 'paragraph');
111+
112+
// Try to alter the block context
113+
block.context = 'ulist';
114+
assert(block.getContext() === 'ulist');
115+
block.context = 'paragraph';
116+
assert(block.getContext() === 'paragraph');
117+
118+
// Try to alter the name of the node
119+
block.node_name = 'ulist'
120+
assert(block.getNodeName() === 'ulist')
121+
block.node_name = 'paragraph'
122+
assert(block.getNodeName() === 'paragraph')
123+
111124
assert(block.applySubstitutions('<html> -- the root of all web') === '&lt;html&gt;&#8201;&#8212;&#8201;the root of all web');
112125
assert(Object.keys(block.getAttributes()).length === 0);
113126
block.setAttribute('awesome', true);

0 commit comments

Comments
 (0)