ajout filtre timesheet

This commit is contained in:
Julien Fastré 2020-12-07 17:33:52 +01:00
parent d2ac214af0
commit ec517decdf
3 changed files with 76 additions and 0 deletions

View File

@ -35,4 +35,28 @@ Ceci est un truc (des trucs et astuces)
::: :::
``` ```
### `timesheet.lua`
Extrait des timesheets d'un fichier markdown.
Usage:
Markdown associé:
---
timesheet: /path/to/file.csv
---
```{.timesheet}
2020-12-15, CL, 1, test
```
Execution:
```
pandoc --to markdown --lua-filter timesheet.lua
```
Le fichier CSV sera enregistré à la place du fichier `/path/to/file.csv`

9
fixtures/timesheet.md Normal file
View File

@ -0,0 +1,9 @@
---
timesheet: /tmp/timesheet.csv
---
```{.timesheet}
2020-01-01, CL, 1, test
```

43
timesheet.lua Normal file
View File

@ -0,0 +1,43 @@
require 'io'
local timesheet_export = nil
local timesheet_content = ""
local function Meta(meta)
timesheet_export = pandoc.utils.stringify(meta['timesheet'])
return nil
end
local function save_timesheet(content)
timesheet_content = timesheet_content .. content
end
local function CodeBlock(elem)
for k,v in ipairs(elem.classes) do
if v == 'timesheet' then
save_timesheet(elem.text)
end
end
-- do not modify elem
return nil
end
local function save()
file = io.open(timesheet_export, 'w+')
file:write(timesheet_content)
file:close()
end
local function Pandoc(pandoc)
save()
return nil
end
return {
{ Meta = Meta },
{ CodeBlock = CodeBlock },
{ Pandoc = Pandoc }
}