use crate::tests::prelude::*;
track_file!("ref/asciidoc-lang/docs/modules/macros/pages/icons-font.adoc");
non_normative!(
r#"
= Font Icons Mode
:url-fontawesome-icons: https://fontawesome.com/v4/icons/
Setting the `icons` attribute to `font` instructs the AsciiDoc processor to select icons from an icon font.
CAUTION: Not all converters support this mode.
If a converter does not support this mode, it will fall back to the xref:icons-image.adoc[image mode].
"#
);
#[test]
fn enable_font_based_icons() {
verifies!(
r#"
== Enable font-based icons
To enable image-based icons, you set the `icons` attribute in the document header to the value `font`.
[source]
----
= Document Title
:icons: font
----
This setting has no affect on the parsing of the AsciiDoc document.
It only influences the output generated by the converters.
"#
);
let doc = Parser::default().parse(":icons: font\n\nicon:heart[]");
assert_eq!(
rendered_paragraphs(&doc).join("\n"),
r#"<span class="icon"><i class="fa fa-heart"></i></span>"#
);
let doc = Parser::default().parse("icon:heart[]");
let block = doc.nested_blocks().next().unwrap();
assert_eq!(block.raw_context().as_ref(), "paragraph");
}
non_normative!(
r#"
IMPORTANT: When converting to HTML, the stylesheet is required in order for the font-based icons to work.
== Default icon font
The icon font that is used by default is determined by the processor.
Asciidoctor, for example, uses the Font Awesome icon font.
You can see the available icons in Font Awesome on the {url-fontawesome-icons}[Font Awesome icons page^].
Using the Font Awesome icons in Asciidoctor requires online access by default.
== Default admonition icons
Since the names of admonitions doesn't necessarily match the names of icons in the icon font, the AsciiDoc processor must map admonition CSS classes to icon names.
When using Font Awesome as the icon set, the following mappings are recommended:
* note -> info-circle
* tip -> lightbulb-o
* warning -> warning
* caution -> fire
* important -> exclamation-circle
////
TODO: move to Asciidoctor
== Default font-based admonition icons
When font-based icons are enabled, Asciidoctor will draw the icons for the 5 built-in admonition types using Font Awesome.
To use the default font-based admonition icons for admonitions, set the value of the `icons` document attribute to `font` in the document header.
[source]
----
= Document Title
:icons: font
NOTE: Asciidoctor supports font-based admonition icons, powered by Font Awesome!
----
// We need to explain that the default admonition icons have different names (i.e., `icon-note` instead of `fa-note`, because they're built in to the stylesheet.
Asciidoctor will emit HTML markup that selects the appropriate font character from the Font Awesome font for each admonition block.
For instance, Asciidoctor selects the Font Awesome icon `icon-note` for `NOTE` admonition blocks.
.Result: HTML output when the icons attribute is set to font
[source,html]
----
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Asciidoctor supports font-based admonition icons, powered by Font Awesome!
</td>
</tr>
</table>
</div>
----
This is how the admonition looks rendered.
NOTE: Asciidoctor supports font-based admonition icons, powered by Font Awesome!
The icons chosen are selected by the stylesheet.
The default stylesheet maps icons to the following 5 CSS classes:
* .admonitionblock td.icon .icon-note
* .admonitionblock td.icon .icon-tip
* .admonitionblock td.icon .icon-warning
* .admonitionblock td.icon .icon-caution
* .admonitionblock td.icon .icon-important
If you want to customize the icon or the color that is used, you'll need to provide a custom stylesheet or override the styles using a docinfo file.
Here's an example that shows how to change the icon for the note admonition to sticky note:
[source,css]
----
.admonitionblock td.icon .icon-note::before {
content: "\f24a";
color:black;
}
----
////
== Callout numbers and font icon mode
In the font icon mode, xref:verbatim:callouts.adoc[callout numbers] are displayed as enclosed numbers.
However, the icon font is not used to render these glyphs.
Instead, they are styled this way using CSS.
This is done to allow the range of callout numbers to be open-ended.
"#
);