diff options
Diffstat (limited to 'filters/macros.lua')
| -rw-r--r-- | filters/macros.lua | 57 |
1 files changed, 55 insertions, 2 deletions
diff --git a/filters/macros.lua b/filters/macros.lua index ca0b487..df08676 100644 --- a/filters/macros.lua +++ b/filters/macros.lua | |||
| @@ -1,9 +1,20 @@ | |||
| 1 | function wide(el) | ||
| 2 | local els = pandoc.List() | ||
| 3 | |||
| 4 | els:insert(pandoc.RawBlock("html", "</div>")) | ||
| 5 | els:insert(el) | ||
| 6 | els:insert(pandoc.RawBlock("html", "<div class=\"l-container l-container--narrow u-ml-0\">")) | ||
| 7 | |||
| 8 | return els | ||
| 9 | end | ||
| 10 | |||
| 1 | function alert(el) | 11 | function alert(el) |
| 2 | el.classes = pandoc.List() | 12 | el.classes = pandoc.List() |
| 3 | el.classes:insert("o-alert") | 13 | el.classes:insert("o-alert") |
| 4 | el.classes:insert("o-alert--primary") | 14 | el.classes:insert("o-alert--primary") |
| 5 | el.classes:insert("s-alerts__alert") | 15 | el.classes:insert("s-alerts__alert") |
| 6 | return el | 16 | |
| 17 | return wide(el) | ||
| 7 | end | 18 | end |
| 8 | 19 | ||
| 9 | function figure(el) | 20 | function figure(el) |
| @@ -11,12 +22,14 @@ function figure(el) | |||
| 11 | 22 | ||
| 12 | pandoc.walk_block(el, { Image = function(iel) images:insert(iel) end }) | 23 | pandoc.walk_block(el, { Image = function(iel) images:insert(iel) end }) |
| 13 | 24 | ||
| 14 | return pandoc.RawBlock("html", | 25 | el = pandoc.RawBlock("html", |
| 15 | "<figure class=\"c-figure\">\ | 26 | "<figure class=\"c-figure\">\ |
| 16 | <a class=\"c-figure__link\" href=\"" .. images[1].src .. "\">\ | 27 | <a class=\"c-figure__link\" href=\"" .. images[1].src .. "\">\ |
| 17 | <img class=\"c-figure__image\" src=\"" .. images[1].src .. "\" title=\"" .. images[1].title .. "\" />\ | 28 | <img class=\"c-figure__image\" src=\"" .. images[1].src .. "\" title=\"" .. images[1].title .. "\" />\ |
| 18 | </a>\ | 29 | </a>\ |
| 19 | </figure>") | 30 | </figure>") |
| 31 | |||
| 32 | return wide(el) | ||
| 20 | end | 33 | end |
| 21 | 34 | ||
| 22 | function Div(el) | 35 | function Div(el) |
| @@ -28,3 +41,43 @@ function Div(el) | |||
| 28 | 41 | ||
| 29 | return el | 42 | return el |
| 30 | end | 43 | end |
| 44 | |||
| 45 | function CodeBlock(el) | ||
| 46 | if el.classes[1] == "plain" then | ||
| 47 | el = pandoc.Div({ el }, { class = 's-code' }) | ||
| 48 | elseif el.classes[1] then | ||
| 49 | local formatted = pandoc.pipe('pygmentize', { | ||
| 50 | '-l', el.classes[1], '-f', 'html', '-O', 'cssclass=s-code s-code--highlight', | ||
| 51 | }, el.text) | ||
| 52 | |||
| 53 | if formatted then el = pandoc.RawBlock('html', formatted) end | ||
| 54 | end | ||
| 55 | |||
| 56 | return wide(el) | ||
| 57 | end | ||
| 58 | |||
| 59 | function Header(el) | ||
| 60 | if el.level <= 3 then | ||
| 61 | local newchildren = pandoc.List() | ||
| 62 | newchildren:insert(pandoc.Span(el.content, { class = 's-headings__primary' })) | ||
| 63 | el.content = newchildren | ||
| 64 | end | ||
| 65 | |||
| 66 | return el | ||
| 67 | end | ||
| 68 | |||
| 69 | function Table(el) | ||
| 70 | return wide(el) | ||
| 71 | end | ||
| 72 | |||
| 73 | function Str(el) | ||
| 74 | local icon = el.text:match('^:(.*):$') | ||
| 75 | |||
| 76 | if icon then | ||
| 77 | return pandoc.RawInline('html', | ||
| 78 | '<svg class="o-icon o-icon--inline" width="1em" height="1em" aria-hidden="true"><use href="/icons.svg#' .. | ||
| 79 | icon .. '"></use></svg>') | ||
| 80 | end | ||
| 81 | |||
| 82 | return el | ||
| 83 | end | ||
