const path = require('path')
const customStyleContent = (node) => {
const stylesheet = node.getAttribute('stylesheet') || `${__dirname}/slides.css`
if (path.isAbsolute(stylesheet)) {
return stylesheet
}
const stylesDirectory = node.getAttribute('stylesdir')
let start = node.getDocument().getBaseDir()
if (stylesDirectory) {
if (path.isAbsolute(stylesDirectory)) {
start = stylesDirectory
} else {
start = path.join(node.getDocument().getBaseDir(), stylesDirectory)
}
} else {
start = node.getDocument().getBaseDir()
}
return path.join(start, stylesheet)
}
const titleSliderHeader = (node) => {
const doctitle = node.getDocumentTitle({ partition: true })
if (doctitle.hasSubtitle()) {
return `
${doctitle.getMain()}
${doctitle.getSubtitle()}
`
}
return `${node.getDocumentTitle()}
`
}
const titleSlide = (node) => {
return `
${titleSliderHeader(node)}
`
}
const getImageCanvas = (node) => {
const images = node.findBy({ context: 'image', role: 'canvas' })
if (images && images.length > 0) {
return images[0]
}
return undefined
}
const sectionInlineStyle = (node) => {
const image = getImageCanvas(node)
if (image) {
const roles = node.getRoles()
let backgroundSize
if (roles && roles.includes('contain')) {
backgroundSize = 'contain'
} else {
backgroundSize = 'cover'
}
return `style="background-image: url(${node.getImageUri(image.getAttribute('target'))}); background-size: ${backgroundSize}; background-repeat: no-repeat"`
}
return ''
}
const sectionTitle = (node) => {
const titleSeparator = node.getDocument().getAttribute('title-separator') || ':'
const parts = node.getTitle().split(titleSeparator)
const main = parts[0]
const subtitle = parts[1]
if (subtitle) {
return ``
}
return `${node.getTitle()}
`
}
const sectionRoles = (node) => {
const roles = node.getRoles() || []
roles.unshift('slide')
const image = getImageCanvas(node)
if (image) {
roles.push('image')
}
return roles
}
const elementId = (node) => {
const id = node.getId()
if (id) {
return ` id="${id}"`
}
return ''
}
module.exports = {
paragraph: (node) => `${node.getContent()}
`,
section: (node) => `
${sectionTitle(node)}
${node.getContent()}
`,
document: (node) => `
${titleSlide(node)}
${node.getContent()}
`,
open: (node) => `${node.getContent()}
`,
image: (node) => {
const roles = node.getRoles()
if (roles && roles.includes('canvas')) {
return ''
}
const height = node.getAttribute('height')
const width = node.getAttribute('width')
return `
`
}
}