Skip to content

Commit

Permalink
extension update
Browse files Browse the repository at this point in the history
  • Loading branch information
nessan committed Aug 26, 2024
1 parent 6241c83 commit 5388cff
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 39 deletions.
2 changes: 1 addition & 1 deletion docs/_extensions/nessan/admonitions/_extension.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title: admonitions
author: nessan
version: 1.0.0
version: 1.1.0
quarto-required: ">=1.5.0"
contributes:
filters:
Expand Down
37 changes: 21 additions & 16 deletions docs/_extensions/nessan/admonitions/admonitions.lua
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" },
Expand All @@ -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({
Expand All @@ -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.
Expand Down
33 changes: 11 additions & 22 deletions docs/_extensions/nessan/admonitions/assets/admonitions.css
Original file line number Diff line number Diff line change
@@ -1,53 +1,43 @@
/* More or less the same as AsciiDoc admonitions */
/* Similar to AsciiDoc admonition styling */

.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 {
line-height: 1.6;
padding: 0.5625em 0.625em;
font-size: inherit;
color: rgba(0, 0, 0, 0.8);
font-size: 1.1em;
}

.admonition > table tr td {
line-height: 1.6;
.admonition > table td.content {
padding-left: 1.125em;
padding-right: 1.25em;
border-left: 1px solid #dddddf;
word-wrap: anywhere;
opacity: 70%;
}

.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;
}

Expand All @@ -58,8 +48,7 @@

.admonition td.icon .icon-tip::before {
content: "\f0eb";
text-shadow: 1px 1px 2px rgba(155, 155, 0, 0.8);
color: #111;
color: #719920;
}

.admonition td.icon .icon-warning::before {
Expand Down

0 comments on commit 5388cff

Please sign in to comment.