From ec517decdfec8a033bf8e0c6449f460bbb99f1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 7 Dec 2020 17:33:52 +0100 Subject: [PATCH] ajout filtre timesheet --- README.md | 24 ++++++++++++++++++++++++ fixtures/timesheet.md | 9 +++++++++ timesheet.lua | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 fixtures/timesheet.md create mode 100644 timesheet.lua diff --git a/README.md b/README.md index 99cca69..d525698 100644 --- a/README.md +++ b/README.md @@ -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` + diff --git a/fixtures/timesheet.md b/fixtures/timesheet.md new file mode 100644 index 0000000..bb827ae --- /dev/null +++ b/fixtures/timesheet.md @@ -0,0 +1,9 @@ +--- +timesheet: /tmp/timesheet.csv +--- + +```{.timesheet} + +2020-01-01, CL, 1, test + +``` diff --git a/timesheet.lua b/timesheet.lua new file mode 100644 index 0000000..ed726eb --- /dev/null +++ b/timesheet.lua @@ -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 } +}