Skip to content

Commit

Permalink
Add getSectionNumeral() function (#1659)
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Grossetie <[email protected]>
  • Loading branch information
benjaminleonard and ggrossetie authored Sep 24, 2022
1 parent 99d06f7 commit 575221c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/core/spec/share/asciidoctor-spec.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ This is another paragraph.
expect(firstSection.title).to.equal('First section')
expect(firstSection.getSectionName()).to.equal('section')
expect(firstSection.isNumbered()).to.equal(false)
expect(firstSection.getSectionNumeral()).to.equal('.')
expect(firstSection.isSpecial()).to.equal(false)
expect(firstSection.getCaption()).to.be.undefined()
const secondSection = doc.getSections()[1]
Expand All @@ -603,6 +604,8 @@ This is another paragraph.
expect(secondSection.title).to.equal('Second section')
expect(secondSection.getSectionName()).to.equal('section')
expect(secondSection.isNumbered()).to.equal(true)
expect(secondSection.getSectionNumeral()).to.equal('1.')
expect(secondSection.getSectionNumber()).to.equal('1.')
expect(secondSection.isSpecial()).to.equal(false)
expect(secondSection.getCaption()).to.be.undefined()
const abstractSection = doc.getSections()[2]
Expand All @@ -612,6 +615,7 @@ This is another paragraph.
expect(abstractSection.title).to.equal('Abstract section')
expect(abstractSection.getSectionName()).to.equal('abstract')
expect(abstractSection.isNumbered()).to.equal(false)
expect(firstSection.getSectionNumeral()).to.equal('.')
expect(abstractSection.isSpecial()).to.equal(true)
expect(abstractSection.getCaption()).to.be.undefined()
const appendixSection = doc.getSections()[3]
Expand All @@ -620,6 +624,7 @@ This is another paragraph.
expect(appendixSection.getTitle()).to.equal('Copyright and License')
expect(appendixSection.title).to.equal('Copyright and License')
expect(appendixSection.getSectionName()).to.equal('appendix')
expect(appendixSection.getSectionNumeral()).to.equal('A.')
expect(appendixSection.isNumbered()).to.equal(true)
expect(appendixSection.isSpecial()).to.equal(true)
expect(appendixSection.getCaption()).to.equal('Appx A: ')
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/asciidoctor-core-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,17 @@ Section.prototype.setSectionName = function (value) {
this.sectname = value
}

/**
* Get the section numeral of this section.
* @returns {string}
* @memberof Section
*/
Section.prototype.getSectionNumeral = function () {
return this.$sectnum()
}

Section.prototype.getSectionNumber = Section.prototype.getSectionNumeral

/**
* Get the flag to indicate whether this is a special section or a child of one.
* @returns {boolean}
Expand Down
8 changes: 8 additions & 0 deletions packages/core/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,14 @@ export namespace Asciidoctor {
*/
setSectionName(value: string): void;

/**
* Get the section number of this section.
*/
getSectionNumeral(): string;

// alias
getSectionNumber(): string;

/**
* Get the flag to indicate whether this is a special section or a child of one.
*/
Expand Down

0 comments on commit 575221c

Please sign in to comment.