-
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
70 changed files
with
267 additions
and
341 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
title: admonitions | ||
author: nessan | ||
version: 1.0.0 | ||
quarto-required: ">=1.5.0" | ||
contributes: | ||
filters: | ||
- admonitions.lua |
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--[[ | ||
Quarto extension to process AsciiDoc style '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. | ||
local admonitions = { | ||
NOTE = { name = "note", title = "Note"}, | ||
TIP = { name = "tip", title = "Tip" }, | ||
WARNING = { name = "warning", title = "Warning" }, | ||
CAUTION = { name = "caution", title = "Caution" }, | ||
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) | ||
|
||
-- Inject our own CSS for styling admonition content and icons -- we have those CSS rules in a local stylesheet. | ||
quarto.doc.add_html_dependency({ | ||
name = 'admonitions', | ||
version = '1.0.0', | ||
stylesheets = {'assets/admonitions.css'} | ||
}) | ||
|
||
-- Don't need to call this again | ||
need_html_dependencies = false | ||
end | ||
end | ||
|
||
-- Given an admonition style and its content we create an apporiate HTML table to insert in its place. | ||
local function process_admonition(admonition, content) | ||
|
||
-- Add the HTML dependencies if we need to. | ||
if need_html_dependencies then process_admonition_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 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. | ||
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. | ||
local post_html = "</td></tr></table></div>" | ||
|
||
-- The admonition will be the the pre & post HTML with the admonition content in between. | ||
return {pandoc.RawBlock('html', pre_html), content, pandoc.RawBlock('html', post_html)} | ||
|
||
end | ||
|
||
-- Check the passed paragraph to see if we are dealing with an admonition. | ||
local function process_para(el) | ||
-- Grab the first word from the paragraph. | ||
local content = el.content | ||
local first = content[1].text | ||
if first then | ||
-- If that first word is all upper-case and followed by a colon we *may* have an admonition | ||
local possible_admonition = first:match("^(%u*):") | ||
if possible_admonition then | ||
-- Key has the correct form but do we recognize it? | ||
local admonition = admonitions[possible_admonition] | ||
-- Yes it is an admonition | ||
if admonition then | ||
-- Remove the key and a likely space character thereafter to get the admonition content | ||
local start = 2 | ||
if #content > 1 and content[2].t == 'Space' then start = 3 end | ||
local admonition_content = { table.unpack(content, start) } | ||
return process_admonition(admonition, admonition_content) | ||
end | ||
end | ||
end | ||
end | ||
|
||
return { Para = process_para } |
78 changes: 78 additions & 0 deletions
78
docs/_extensions/nessan/admonitions/assets/admonitions.css
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* More or less the same as AsciiDoc admonitions */ | ||
|
||
.admonition > table { | ||
width: 100%; | ||
margin-bottom: 1.25em; | ||
word-wrap: normal; | ||
border-collapse: separate; | ||
border: 0; | ||
background: none; | ||
} | ||
|
||
.admonition > table tr th, | ||
.admonition > table tr td { | ||
padding: 0.5625em 0.625em; | ||
font-size: inherit; | ||
color: rgba(0, 0, 0, 0.8); | ||
} | ||
|
||
.admonition > table tr td { | ||
line-height: 1.6; | ||
} | ||
|
||
.admonition > table td.icon { | ||
text-align: center; | ||
width: 80px; | ||
} | ||
.admonition > table td.icon img { | ||
max-width: none; | ||
} | ||
.admonition > table td.icon .title { | ||
font-weight: bold; | ||
font-family: "Open Sans", "DejaVu Sans", sans-serif; | ||
text-transform: uppercase; | ||
} | ||
|
||
.admonition > table td.content { | ||
padding-left: 1.125em; | ||
padding-right: 1.25em; | ||
border-left: 1px solid #dddddf; | ||
color: rgba(0, 0, 0, 0.6); | ||
word-wrap: anywhere; | ||
} | ||
|
||
.admonition > table td.content > :last-child > :last-child { | ||
margin-bottom: 0; | ||
} | ||
|
||
.admonition td.icon [class^="fa icon-"] { | ||
font-size: 2.5em; | ||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5); | ||
cursor: default; | ||
} | ||
|
||
.admonition td.icon .icon-note::before { | ||
content: "\f05a"; | ||
color: #19407c; | ||
} | ||
|
||
.admonition td.icon .icon-tip::before { | ||
content: "\f0eb"; | ||
text-shadow: 1px 1px 2px rgba(155, 155, 0, 0.8); | ||
color: #111; | ||
} | ||
|
||
.admonition td.icon .icon-warning::before { | ||
content: "\f071"; | ||
color: #bf6900; | ||
} | ||
|
||
.admonition td.icon .icon-caution::before { | ||
content: "\f06d"; | ||
color: #bf3400; | ||
} | ||
|
||
.admonition td.icon .icon-important::before { | ||
content: "\f06a"; | ||
color: #bf0000; | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.