ajout boxes

This commit is contained in:
Julien Fastré 2020-11-24 14:44:16 +01:00
parent 57b1a5e293
commit d2ac214af0
3 changed files with 82 additions and 0 deletions

View File

@ -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)
:::
```

40
boxes.lua Normal file
View File

@ -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

17
fixtures/environment.md Normal file
View File

@ -0,0 +1,17 @@
::: {.tip }
Environnement tip
:::
::: {.info}
Environnement info transformed into tip
:::
::: { .zxy }
Normal, not modified
:::