Skip to content

Commit

Permalink
resolves #208 integrate with built-in template converter
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Apr 28, 2020
1 parent fdf8363 commit 7397e36
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/converter.js
Expand Up @@ -15,6 +15,12 @@ function registerTemplateConverter (processor, templates) {
constructor () {
this.baseConverter = processor.Html5Converter.create()
this.templates = templates
this.backendTraits = {
basebackend: 'html5',
outfilesuffix: '.pdf',
htmlsyntax: 'html',
supports_templates: true
}
}

convert (node, transform, opts) {
Expand Down
36 changes: 33 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -48,16 +48,17 @@
"yargs": "15.3.1"
},
"devDependencies": {
"@asciidoctor/core": "^2.1.0",
"@asciidoctor/core": "^2.2.0",
"chai": "4.2.0",
"cheerio": "^1.0.0-rc.3",
"dirty-chai": "2.0.1",
"mocha": "7.1.2",
"nunjucks": "^3.2.1",
"pixelmatch": "^5.1.0",
"rimraf": "^3.0.0",
"standard": "14.3.3"
},
"peerDependencies": {
"@asciidoctor/core": "^2.1.0"
"@asciidoctor/core": "^2.2.0"
}
}
1 change: 1 addition & 0 deletions templates/paragraph.njk
@@ -0,0 +1 @@
<p class="paragraph-nunjucks">{{ node.getContent() }}</p>
1 change: 1 addition & 0 deletions test/fixtures/templates/nunjucks/paragraph.njk
@@ -0,0 +1 @@
<p class="nunjucks">{{ node.getContent() | safe }}</p>
5 changes: 5 additions & 0 deletions test/templates_test.js
Expand Up @@ -265,5 +265,10 @@ Just a preamble.`, { safe: 'safe' })
const $ = cheerio.load(doc.convert())
expect($('#toc > ul.sectlevel1 > li')).to.have.length(0)
})

it('should use a template directory (Nunjucks)', () => {
const html = asciidoctor.convert('Hello *world*', { template_dirs: [`${__dirname}/fixtures/templates/nunjucks`] })
expect(html).to.equal('<p class="nunjucks">Hello <strong>world</strong></p>')
})
})
})

0 comments on commit 7397e36

Please sign in to comment.