From d2ac214af00eddd53648e14e12cfebb3680b2474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 24 Nov 2020 14:44:16 +0100 Subject: [PATCH] ajout boxes --- README.md | 25 +++++++++++++++++++++++++ boxes.lua | 40 ++++++++++++++++++++++++++++++++++++++++ fixtures/environment.md | 17 +++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 boxes.lua create mode 100644 fixtures/environment.md diff --git a/README.md b/README.md index 3f5242f..99cca69 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,28 @@ Filtres et recommandations pour CL # voir: http://lesfichesabebert.fr/latex/Fran%C3%A7ais.html babel-main: french ``` + +## Filtres + +### `boxes.lua` + +Ajoute des boxes aux documents latex, en utilisant [awesomebox](https://ctan.org/pkg/awesomebox). + +Boxes disponibles: + +* note; +* tip; +* warning; +* caution; +* important; +* info (alias pour "note"); + +Usage: + +``` +::: { .tip } +Ceci est un truc (des trucs et astuces) +::: +``` + + diff --git a/boxes.lua b/boxes.lua new file mode 100644 index 0000000..d5d5957 --- /dev/null +++ b/boxes.lua @@ -0,0 +1,40 @@ +-- list of supported environment classes in package awesomebox +local default_env_available = { 'note', 'tip', 'warning', 'caution', 'important' } +-- list of mappings: environment that are mapped to a supported env in awesomebox +local default_env_mapping = { + ['info'] = 'note', -- example: the div with class .info will be transformed to tip + ['warning'] = 'caution', + ['danger'] = 'important', +} + + +local function get_box(classes) + for l,c in ipairs(classes) do + for k,v in ipairs(default_env_available) do + if c:match(v) then + return v + end + end + for k,v in pairs(default_env_mapping) do + if c:match(k) then + return v + end + end + end + + return nil +end + +if FORMAT:match('latex') then + function Div(div) + box = get_box(div.classes) + if box ~= nil then + blockname = box .. 'block' + return { + pandoc.RawBlock('latex', '\\begin{' .. blockname .. '}'), + div, + pandoc.RawBlock('latex', '\\end{' .. blockname .. '}'), + } + end + end +end diff --git a/fixtures/environment.md b/fixtures/environment.md new file mode 100644 index 0000000..b85a9b7 --- /dev/null +++ b/fixtures/environment.md @@ -0,0 +1,17 @@ + + +::: {.tip } +Environnement tip +::: + +::: {.info} +Environnement info transformed into tip +::: + +::: { .zxy } +Normal, not modified +::: + + + +