-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
33 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
--[[ | ||
Quarto extension to process AsciiDoc style 'admonitions' | ||
Quarto extension to process AsciiDoc type 'admonitions' | ||
See: https://docs.asciidoctor.org/asciidoc/latest/blocks/admonitions/ | ||
For now we only support paragraph syntax for admonitions and only have HTML output. | ||
SPDX-FileCopyrightText: 2024 Nessan Fitzmaurice <[email protected]> | ||
SPDX-License-Identifier: MIT | ||
--]] | ||
|
||
-- Here are the admonition styles we recognize. | ||
-- For example, a paragraph starting with 'NOTE: ' will trigger a NOTE style admonition. | ||
-- Here are the admonition types we recognize. | ||
-- For example, a paragraph starting with 'NOTE: ' will trigger a NOTE type admonition. | ||
local admonitions = { | ||
NOTE = { name = "note", title = "Note"}, | ||
TIP = { name = "tip", title = "Tip" }, | ||
|
@@ -16,14 +16,18 @@ local admonitions = { | |
IMPORTANT = { name = "important", title = "Important" } | ||
} | ||
|
||
-- We process each admonition into an one row, two cell HTML table decorated with CSS classes etc. | ||
-- Need to inject the the appropriate links and CSS for those to get those tables rendered correctly. | ||
local need_html_dependencies = true | ||
local function process_admonition_dependencies() | ||
if need_html_dependencies then | ||
-- Inject a link to the fontawesome stylesheet (we use some of their icons to mark the admonition) | ||
local fontawesome_link = '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>' | ||
quarto.doc.include_text('in-header', fontawesome_link) | ||
-- We process each admonition into a one row, two cell HTML table decorated with CSS classes. | ||
-- Need to inject the the appropriate links and CSS to render those tables. | ||
-- That injection needs to done just once as all admonitions share that styling. | ||
local need_to_inject_dependencies = true | ||
|
||
-- Inject the needed CSS if necessary | ||
local function inject_dependencies() | ||
if need_to_inject_dependencies then | ||
|
||
-- Inject a link to the fontawesome stylesheet (we use some of their icons to mark the admonition). | ||
local fa_link = '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>' | ||
quarto.doc.include_text('in-header', fa_link) | ||
|
||
-- Inject our own CSS for styling admonition content and icons -- we have those CSS rules in a local stylesheet. | ||
quarto.doc.add_html_dependency({ | ||
|
@@ -33,26 +37,27 @@ local function process_admonition_dependencies() | |
}) | ||
|
||
-- Don't need to call this again | ||
need_html_dependencies = false | ||
need_to_inject_dependencies = false | ||
|
||
end | ||
end | ||
|
||
-- Given an admonition style and its content we create an apporiate HTML table to insert in its place. | ||
-- Given an admonition type and its content we return the equiavalent HTML table as a pandoc Block | ||
local function process_admonition(admonition, content) | ||
|
||
-- Add the HTML dependencies if we need to. | ||
if need_html_dependencies then process_admonition_dependencies() end | ||
if need_to_inject_dependencies then inject_dependencies() end | ||
|
||
-- Create an HTML div containing a table with one row and two cells [icon, content]. | ||
-- The div & table cells are decorated with classes that depend on the particular admonition style. | ||
-- The div & table cells are decorated with classes that depend on the particular admonition type. | ||
-- The HTML for that looks like the following where we use placeholders for the class names etc. | ||
local pre_template = [[<div class="admonition {{<name>}}"> | ||
<table><tr> | ||
<td class="icon"> <i class="fa icon-{{<name>}}" title="{{<Title>}}"></i></td> | ||
<td class="content"> | ||
]] | ||
|
||
-- Turn the template into the specific HTML for this admonition style. | ||
-- Turn the template into the specific HTML for this admonition type. | ||
local pre_html = pre_template:gsub('{{<name>}}', admonition.name):gsub('{{<Title>}}', admonition.title) | ||
|
||
-- The cell/row/table/div block needs to get closed out with a bunch of closure tags. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters