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

Add getSectionNumeral() function #1659

Merged
merged 8 commits into from Sep 24, 2022
5 changes: 5 additions & 0 deletions packages/core/spec/share/asciidoctor-spec.cjs
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
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
Expand Up @@ -2247,6 +2247,14 @@ export namespace Asciidoctor {
*/
setSectionName(value: string): void;

/**
* Get the section number of this section.
benjaminleonard marked this conversation as resolved.
Show resolved Hide resolved
*/
getSectionNumeral(): string;

ggrossetie marked this conversation as resolved.
Show resolved Hide resolved
// alias
getSectionNumber(): string;

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