Skip to content

Commit 8e80121

Browse files
committed
Add support for font awesome 4
Closes gh-65
1 parent 642b0b2 commit 8e80121

File tree

9 files changed

+125
-4
lines changed

9 files changed

+125
-4
lines changed

README.adoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,25 @@ The package name is constructed by removing all `-` characters from the section
512512

513513

514514

515+
=== Font Awesome Support
516+
Font Awesome support is available in the standard Asciidoctor HTML 5 backend, however, it is not available by default in this backend.
517+
This is to align with https://antora.org[Antora], which https://gitlab.com/antora/antora-ui-default/-/issues/58[doesn't currently support Font Awesome].
518+
519+
If you want to enable Font Awesome 4 support in your documents you can set the `iconfont-fontawesome` attribute.
520+
This will allow you to use `+++icon:<name>[]+++` macros inside your markup, with images being resolved from the locally bundled `fontawesome.css` stylesheet.
521+
522+
For example:
523+
524+
[source,asciidoctor]
525+
----
526+
= Asciidoctor Font Awesome Document
527+
:iconfont-fontawesome:
528+
529+
The folder icon is icon:folder[].
530+
----
531+
532+
533+
515534
== Contributing
516535
If you're looking to contribute to this project, or you're just trying to navigate the code please take a look at the link:CONTRIBUTING.adoc[CONTRIBUTING] file.
517536

gulpfile.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ function css() {
4545
.pipe(connect.reload());
4646
}
4747

48+
function fontawesomeCss() {
49+
return src("node_modules/fontawesome-4.7/css/font-awesome.css").pipe(dest(output + "/css"));
50+
}
51+
52+
function fontawesomeFonts() {
53+
return src("node_modules/fontawesome-4.7/fonts/*").pipe(dest(output + "/fonts"));
54+
}
55+
56+
4857
function img() {
4958
return src("src/main/img/*").pipe(dest(output + "/img"));
5059
}
@@ -101,7 +110,7 @@ function watchFiles(cb) {
101110
cb();
102111
}
103112

104-
const build = series(info, css, img, jsSetup, jsSite);
113+
const build = series(info, css, fontawesomeCss, fontawesomeFonts, img, jsSetup, jsSite);
105114

106115
exports.default = build;
107116
exports.build = build;

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
"dev": "gulp dev",
3838
"format": "prettier --write .",
3939
"checkFormat": "prettier --check ."
40+
},
41+
"dependencies": {
42+
"fontawesome-4.7": "^4.7.0"
4043
}
4144
}

src/main/ruby/lib/spring-asciidoctor-backends/spring-html5-converter.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def initialize(backend, opts = {})
4141
def convert(node, transform = node.node_name, opts = nil)
4242
if transform == "document"
4343
configure_node_attrs node
44-
return postprocess @htmlConverter.convert(node, transform, opts)
44+
return postprocess(node, @htmlConverter.convert(node, transform, opts))
4545
end
4646
if transform == "listing"
4747
return convert_listing node
@@ -68,8 +68,12 @@ def configure_node_attrs(node)
6868
node.remove_attr "copycss"
6969
end
7070

71-
def postprocess(html)
72-
html = html.gsub(/<link\ rel="stylesheet"(?!.*site\.css).*>\R?/, "")
71+
def postprocess(node, html)
72+
if node.attr? 'iconfont-fontawesome'
73+
html = html.gsub(/<link\ rel="stylesheet"(?!.*(site|font-awesome)\.css).*>\R?/, "")
74+
else
75+
html = html.gsub(/<link\ rel="stylesheet"(?!.*site\.css).*>\R?/, "")
76+
end
7377
match = html.match(/^(.*<body.*?>)(.*)(<\/body>.*)$/m)
7478
templateFile = File.join(File.dirname(File.expand_path(__FILE__)), "body_template.html")
7579
body = File.read(templateFile) % { :body => match[2] }

src/test/asciidoc/fontawesome.adoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[[standard]]
2+
= Asciidoctor Font Awesome Document
3+
Carrie Bradshaw; Jessica Fletcher; Diane Nguyen; Paul Sheldon; Jack Torrance
4+
:description: Asciidoctor using only standard markup
5+
:toc: left
6+
:toc-levels: 4
7+
:sectnums:
8+
:iconfont-fontawesome:
9+
10+
This is an example asciidoctor file that uses font-awsome in the document.
11+
You need to set the `iconfont-complete` attribute for this to work.
12+
13+
NOTE: You don't need font awesome for regular admon icons.
14+
15+
The folder icon is icon:folder[].
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.asciidoctor.backend.integrationtest;
18+
19+
import io.spring.asciidoctor.backend.testsupport.AsciidoctorExtension;
20+
import io.spring.asciidoctor.backend.testsupport.ConvertedHtml;
21+
import io.spring.asciidoctor.backend.testsupport.Source;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
25+
import static org.assertj.core.api.Assertions.assertThat;
26+
27+
/**
28+
* Integration tests for tab support.
29+
*
30+
* @author Phillip Webb
31+
*/
32+
@ExtendWith(AsciidoctorExtension.class)
33+
public class FontAwesomeIntegrationTests {
34+
35+
private static final String CSS_LINK = "<link rel=\"stylesheet\" href=\"css/font-awesome.css\">";
36+
37+
private static final String ICON_TEXT = "<i class=\"fa fa-folder\"></i>";
38+
39+
@Test
40+
void fontAwesomeCssIsIncludedWhenAttributeIsSet(@Source("FontAwesome.adoc") ConvertedHtml html) {
41+
assertThat(html.toString()).contains(CSS_LINK);
42+
assertThat(html.toString()).contains(ICON_TEXT);
43+
}
44+
45+
@Test
46+
void fontAwesomeCssIsNotIncludedByDefault(@Source("NoFontAwesome.adoc") ConvertedHtml html) {
47+
assertThat(html.toString()).doesNotContain(CSS_LINK);
48+
assertThat(html.toString()).contains(ICON_TEXT);
49+
}
50+
51+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
= Font Awesome
2+
:iconfont-fontawesome:
3+
4+
icon:folder[].
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
= Font Awesome
2+
3+
icon:folder[].

0 commit comments

Comments
 (0)