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

feat(cover-page): add support for subtitle and revision infos #431

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Expand Up @@ -5,3 +5,4 @@ node_modules/
!/test/fixtures/*docinfo*-pdf.html
/test/output/visual-comparison-workdir/
build
.idea/
42 changes: 40 additions & 2 deletions lib/document/document-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,19 @@ ${faDom.css()}
if (node.getDocumentTitle()) {
const doc = node.getDocument()
if (this.hasTitlePage(doc)) {
const docTitle = node.getDocument().getDocumentTitle({ partition: true })
const title = docTitle.hasSubtitle() ? `<h1>${docTitle.getMain()}</h1><h2>${docTitle.getSubtitle()}</h2>` : `<h1>${docTitle.getCombined()}</h1>`
const formattedAuthors = `${this.formatAuthorsInfos(node.getDocument().getAuthors())}`
const formattedRevisionInfos = this.formatRevisionInfos(node.getDocument())
let titlePageContent = `${title}`
if (formattedAuthors || formattedAuthors) {
titlePageContent += `<div class="cover-details">
${formattedAuthors}
${formattedRevisionInfos}
</div>`
}
return `<div id="cover" class="title-page front-matter">
<h1>${node.getDocumentTitle()}</h1>
<h2>${node.getDocument().getAuthor()}</h2>
${titlePageContent}
</div>`
}
return `<div class="title-document">
Expand All @@ -498,6 +508,34 @@ ${faDom.css()}
return ''
}

/**
* returns a string that contains the formatted authors infos
* @param {Asciidoctor.Document.Author[]} authors
* @return {string}
*/
formatAuthorsInfos (authors) {
return authors.map((author, index) => {
if (author.getEmail()) return `<span class="author">${author.getName()} &lt<a class="email" href="mailto:${author.getEmail()}">${author.getEmail()}</a>&gt</span>`
else return `<span class="author">${author.getName()}</span>`
}).reduce((previousValue, currentValue) => previousValue.concat(`\r\n${currentValue}`), '')
}

/**
* returns a string that contains the formatted revision infos
* @param {Asciidoctor.Document} document
* @return {string}
*/
formatRevisionInfos (document) {
let res = ''
if (document.getRevisionNumber() || document.getRevisionDate()) {
res += '<span class="revinfos">'
if (document.getRevisionNumber()) res += `\r\n<span id="revnumber">Version ${document.getRevisionNumber()}</span>`
if (document.getRevisionDate()) res += `\r\n<span id="revdate">${document.getRevisionDate()}</span>`
res += '</span>'
}
return res
}

/**
* Generate an (hidden) outline otherwise Chrome won't generate "Dests" fields and we won't be able to generate a PDF outline.
*/
Expand Down
Loading