diff --git a/book/_extensions/insightsengineering/pattern-strip/_extension.yml b/book/_extensions/insightsengineering/pattern-strip/_extension.yml new file mode 100644 index 0000000000..31edac97ea --- /dev/null +++ b/book/_extensions/insightsengineering/pattern-strip/_extension.yml @@ -0,0 +1,8 @@ +title: Pattern-strip +author: Pawel Rucki +version: 1.0.0 +quarto-required: ">=1.4.0" +contributes: + filters: + - pattern-strip.lua + diff --git a/book/_extensions/insightsengineering/pattern-strip/pattern-strip.lua b/book/_extensions/insightsengineering/pattern-strip/pattern-strip.lua new file mode 100644 index 0000000000..90f1e0cb44 --- /dev/null +++ b/book/_extensions/insightsengineering/pattern-strip/pattern-strip.lua @@ -0,0 +1,32 @@ +local patterns = {} + +return { + { + Meta = function(meta) + if meta['pattern-strip-patterns'] ~= nil then + for _, pattern in ipairs(meta['pattern-strip-patterns']) do + table.insert(patterns, pandoc.utils.stringify(pattern)) + end + end + end + }, + { + CodeBlock = function (el) + quarto.log.debug(el) + if not el.classes:includes("cell-code") then + return el + end + + local lines = pandoc.List() + local code = el.text .. "\n" + for line in code:gmatch("([^\n]*)\n") do + for _, pattern in ipairs(patterns) do + line = line:gsub(pattern, "") + end + lines:insert(line) + end + el.text = table.concat(lines, "\n") + return el + end + } +} \ No newline at end of file diff --git a/book/_quarto.yml b/book/_quarto.yml index c864277cda..bfb1d99bfd 100644 --- a/book/_quarto.yml +++ b/book/_quarto.yml @@ -38,10 +38,13 @@ execute: freeze: auto cache: true code-line-numbers: true + echo: true -knitr: - opts_chunk: - echo: true +filters: + - insightsengineering/pattern-strip +pattern-strip-patterns: + - "#%s?nolint.*" + - "#%s?styler:.*" editor: visual highlight-style: github