-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathtemplates_test.js
124 lines (102 loc) · 6.83 KB
/
templates_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* global it, describe */
const cheerio = require('cheerio')
const chai = require('chai')
const expect = chai.expect
const dirtyChai = require('dirty-chai')
chai.use(dirtyChai)
const asciidoctor = require('@asciidoctor/core')()
const converter = require('../lib/converter.js')
const templates = require('../lib/document/templates.js')
converter.registerTemplateConverter(asciidoctor, templates)
describe('Default converter', () => {
it('should include a title page if title-page attribute is defined', () => {
const doc = asciidoctor.load(`= Title
Guillaume Grossetie
:title-page:
== Section`)
const $ = cheerio.load(doc.convert({ header_footer: true }))
expect($('.title-page > h1').text()).to.equal('Title')
})
it('should include a title page if doctype is book', () => {
const doc = asciidoctor.load(`= Title
Guillaume Grossetie
== Section`, { doctype: 'book' })
const $ = cheerio.load(doc.convert({ header_footer: true }))
expect($('.title-page > h1').text()).to.equal('Title')
})
it('should not include a title page', () => {
const doc = asciidoctor.load(`= Title
Guillaume Grossetie
== Section`)
const $ = cheerio.load(doc.convert({ header_footer: true }))
expect($('.title-page > h1').length).to.equal(0)
})
it('should not include a title page if the document title is empty', () => {
const doc = asciidoctor.load('Hello world!', { attributes: { 'title-page': '' } })
const $ = cheerio.load(doc.convert({ header_footer: true }))
expect($('.title-page > h1').length).to.equal(0)
})
it('should not include a document title if the document title is empty', () => {
const doc = asciidoctor.load('Hello world!')
const $ = cheerio.load(doc.convert({ header_footer: true }))
expect($('.title-document > h1').length).to.equal(0)
})
it('should include a custom stylesheet', () => {
const doc = asciidoctor.load('[.greetings]#Hello world#', { attributes: { stylesheet: `${__dirname}/fixtures/custom.css` } })
const $ = cheerio.load(doc.convert({ header_footer: true }))
expect($('head > style').html()).to.have.string('.greetings{color: #fecbcb;}')
})
it('should include MathML when stem is set', () => {
const doc = asciidoctor.load(`= Title
:stem:
== Section`)
const $ = cheerio.load(templates.document(doc))
expect($('script[type=\'text/x-mathjax-config\']').length).to.equal(1)
})
it('should not include MathML when stem is not set', () => {
const doc = asciidoctor.load(`= Title
:stem!:
== Section`)
const $ = cheerio.load(templates.document(doc))
expect($('script[type=\'text/x-mathjax-config\']').length).to.equal(0)
})
it('should not include MathML when stem is not present', () => {
const doc = asciidoctor.load(`= Title
== Section`)
const $ = cheerio.load(templates.document(doc))
expect($('script[type=\'text/x-mathjax-config\']').length).to.equal(0)
})
describe('FontAwesome SVG icons set', () => {
it('should enable SVG icon when icons attribute is equals to font (user experience)', () => {
const doc = asciidoctor.load(`= Title
:icons: font
icon:address-book[]`, { safe: 'safe' })
const $ = cheerio.load(doc.convert())
expect($('svg[data-prefix=\'fa\'][data-icon=\'address-book\']').html()).to.equal('<path fill="currentColor" d="M436 160c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20V48c0-26.5-21.5-48-48-48H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h320c26.5 0 48-21.5 48-48v-48h20c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20v-64h20c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20v-64h20zm-228-32c35.3 0 64 28.7 64 64s-28.7 64-64 64-64-28.7-64-64 28.7-64 64-64zm112 236.8c0 10.6-10 19.2-22.4 19.2H118.4C106 384 96 375.4 96 364.8v-19.2c0-31.8 30.1-57.6 67.2-57.6h5c12.3 5.1 25.7 8 39.8 8s27.6-2.9 39.8-8h5c37.1 0 67.2 25.8 67.2 57.6v19.2z"></path>')
})
it('should render a solid FontAwesome SVG icon (default)', () => {
const doc = asciidoctor.load(`:icontype: svg
icon:address-book[]`)
const $ = cheerio.load(doc.convert())
expect($('svg[data-prefix=\'fa\'][data-icon=\'address-book\']').html()).to.equal('<path fill="currentColor" d="M436 160c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20V48c0-26.5-21.5-48-48-48H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h320c26.5 0 48-21.5 48-48v-48h20c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20v-64h20c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20v-64h20zm-228-32c35.3 0 64 28.7 64 64s-28.7 64-64 64-64-28.7-64-64 28.7-64 64-64zm112 236.8c0 10.6-10 19.2-22.4 19.2H118.4C106 384 96 375.4 96 364.8v-19.2c0-31.8 30.1-57.6 67.2-57.6h5c12.3 5.1 25.7 8 39.8 8s27.6-2.9 39.8-8h5c37.1 0 67.2 25.8 67.2 57.6v19.2z"></path>')
})
it('should render a regular FontAwesome SVG icon (default)', () => {
const doc = asciidoctor.load(`:icontype: svg
icon:address-book[set=far]`)
const $ = cheerio.load(doc.convert())
expect($('svg[data-prefix=\'far\'][data-icon=\'address-book\']').html()).to.equal('<path fill="currentColor" d="M436 160c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20V48c0-26.5-21.5-48-48-48H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h320c26.5 0 48-21.5 48-48v-48h20c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20v-64h20c6.6 0 12-5.4 12-12v-40c0-6.6-5.4-12-12-12h-20v-64h20zm-68 304H48V48h320v416zM208 256c35.3 0 64-28.7 64-64s-28.7-64-64-64-64 28.7-64 64 28.7 64 64 64zm-89.6 128h179.2c12.4 0 22.4-8.6 22.4-19.2v-19.2c0-31.8-30.1-57.6-67.2-57.6-10.8 0-18.7 8-44.8 8-26.9 0-33.4-8-44.8-8-37.1 0-67.2 25.8-67.2 57.6v19.2c0 10.6 10 19.2 22.4 19.2z"></path>')
})
it('should render a brand FontAwesome SVG icon (default)', () => {
const doc = asciidoctor.load(`:icontype: svg
icon:chrome@fab[]`)
const $ = cheerio.load(doc.convert())
expect($('svg[data-prefix=\'fab\'][data-icon=\'chrome\']').html()).to.equal('<path fill="currentColor" d="M131.5 217.5L55.1 100.1c47.6-59.2 119-91.8 192-92.1 42.3-.3 85.5 10.5 124.8 33.2 43.4 25.2 76.4 61.4 97.4 103L264 133.4c-58.1-3.4-113.4 29.3-132.5 84.1zm32.9 38.5c0 46.2 37.4 83.6 83.6 83.6s83.6-37.4 83.6-83.6-37.4-83.6-83.6-83.6-83.6 37.3-83.6 83.6zm314.9-89.2L339.6 174c37.9 44.3 38.5 108.2 6.6 157.2L234.1 503.6c46.5 2.5 94.4-7.7 137.8-32.9 107.4-62 150.9-192 107.4-303.9zM133.7 303.6L40.4 120.1C14.9 159.1 0 205.9 0 256c0 124 90.8 226.7 209.5 244.9l63.7-124.8c-57.6 10.8-113.2-20.8-139.5-72.5z"></path>')
})
it('should render an Octicons SVG icon', () => {
const doc = asciidoctor.load(`:icontype: svg
icon:hubot@octicons[]`)
const $ = cheerio.load(doc.convert())
expect($('svg.octicon.octicon-hubot').html()).to.equal('<path fill-rule="evenodd" d="M3 6c-.55 0-1 .45-1 1v2c0 .55.45 1 1 1h8c.55 0 1-.45 1-1V7c0-.55-.45-1-1-1H3zm8 1.75L9.75 9h-1.5L7 7.75 5.75 9h-1.5L3 7.75V7h.75L5 8.25 6.25 7h1.5L9 8.25 10.25 7H11v.75zM5 11h4v1H5v-1zm2-9C3.14 2 0 4.91 0 8.5V13c0 .55.45 1 1 1h12c.55 0 1-.45 1-1V8.5C14 4.91 10.86 2 7 2zm6 11H1V8.5c0-3.09 2.64-5.59 6-5.59s6 2.5 6 5.59V13z"></path>')
})
})
})