Skip to content

Commit ee8efae

Browse files
committed
Add Octicons SVG set
1 parent bc77278 commit ee8efae

File tree

5 files changed

+57
-33
lines changed

5 files changed

+57
-33
lines changed

examples/document/basic-example.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ icon:flag[rotate=270] +
6565
icon:flag[flip=horizontal] +
6666
icon:flag[flip=vertical]
6767

68-
.Roles
69-
icon:heart[role=is-primary] icon:heart[role=is-success] icon:heart[role=is-warning] icon:heart[role=is-danger]
68+
.Octicons
69+
You can icon:repo-forked[set=octicons] me on icon:mark-github[set=octicons]... bip bip bop icon:hubot@octicons[]
7070

71-
.Set
72-
icon:address-book[set=far] icon:address-book[] icon:chrome@fab[]
71+
.FontAwesome solid (default), regular and brand
72+
icon:address-book[] icon:address-book[set=far] icon:chrome@fab[]
7373

7474
== Conclusion
7575

lib/document/templates.js

+36-27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const fs = require('fs')
22
const path = require('path')
33
const stemContent = require('./stem')
44

5+
const octicons = require('@primer/octicons')
56
const faLibrary = require('@fortawesome/fontawesome-svg-core').library
67
const faIcon = require('@fortawesome/fontawesome-svg-core').icon
78
const faDom = require('@fortawesome/fontawesome-svg-core').dom
@@ -185,30 +186,6 @@ ${syntaxHighlighterFooter(node, syntaxHighlighter, { cdn_base_url: cdnBaseUrl, l
185186
},
186187
inline_image: (node, baseConverter) => {
187188
if (node.getType() === 'icon' && isSvgIconEnabled(node)) {
188-
const transform = {}
189-
if (node.hasAttribute('rotate')) {
190-
transform.rotate = node.getAttribute('rotate')
191-
}
192-
if (node.hasAttribute('flip')) {
193-
const flip = node.getAttribute('flip')
194-
if (flip === 'vertical' || flip === 'y' || flip === 'v') {
195-
transform.flipY = true
196-
} else {
197-
transform.flipX = true
198-
}
199-
}
200-
const options = {}
201-
options.transform = transform
202-
if (node.hasAttribute('title')) {
203-
options.title = node.getAttribute('title')
204-
}
205-
options.classes = []
206-
if (node.hasAttribute('size')) {
207-
options.classes.push(`fa-${node.getAttribute('size')}`)
208-
}
209-
if (node.getRoles() && node.getRoles().length > 0) {
210-
options.classes = options.classes.concat(node.getRoles().map(value => value.trim()))
211-
}
212189
const meta = {}
213190
const target = node.getTarget()
214191
let iconName = target
@@ -220,9 +197,41 @@ ${syntaxHighlighterFooter(node, syntaxHighlighter, { cdn_base_url: cdnBaseUrl, l
220197
meta.prefix = parts[1]
221198
}
222199
meta.iconName = iconName
223-
const icon = faIcon(meta, options)
224-
if (icon) {
225-
return icon.html
200+
if (meta.prefix === 'octicons') {
201+
const icon = octicons[meta.iconName]
202+
if (icon) {
203+
return icon.toSVG()
204+
}
205+
} else {
206+
// FontAwesome
207+
const transform = {}
208+
if (node.hasAttribute('rotate')) {
209+
transform.rotate = node.getAttribute('rotate')
210+
}
211+
if (node.hasAttribute('flip')) {
212+
const flip = node.getAttribute('flip')
213+
if (flip === 'vertical' || flip === 'y' || flip === 'v') {
214+
transform.flipY = true
215+
} else {
216+
transform.flipX = true
217+
}
218+
}
219+
const options = {}
220+
options.transform = transform
221+
if (node.hasAttribute('title')) {
222+
options.title = node.getAttribute('title')
223+
}
224+
options.classes = []
225+
if (node.hasAttribute('size')) {
226+
options.classes.push(`fa-${node.getAttribute('size')}`)
227+
}
228+
if (node.getRoles() && node.getRoles().length > 0) {
229+
options.classes = options.classes.concat(node.getRoles().map(value => value.trim()))
230+
}
231+
const icon = faIcon(meta, options)
232+
if (icon) {
233+
return icon.html
234+
}
226235
}
227236
} else {
228237
return baseConverter.$convert_inline_image(node)

package-lock.json

+9-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@fortawesome/free-brands-svg-icons": "5.11.2",
3737
"@fortawesome/free-regular-svg-icons": "5.11.2",
3838
"@fortawesome/free-solid-svg-icons": "5.11.2",
39+
"@primer/octicons": "^9.1.1",
3940
"chokidar": "2.0.4",
4041
"fs-extra": "7.0.1",
4142
"pagedjs": "0.1.34",

test/templates_test.js

+7
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,12 @@ icon:chrome@fab[]`)
113113
const $ = cheerio.load(doc.convert())
114114
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>')
115115
})
116+
it('should render an Octicons SVG icon', () => {
117+
const doc = asciidoctor.load(`:icontype: svg
118+
119+
icon:hubot@octicons[]`)
120+
const $ = cheerio.load(doc.convert())
121+
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>')
122+
})
116123
})
117124
})

0 commit comments

Comments
 (0)