Skip to content

Commit

Permalink
Custom Lua filter against # nolint (and others) (#216)
Browse files Browse the repository at this point in the history
As suggested in
quarto-dev/quarto-cli#8760
The current solution creates a red errors in the render process

---------

Signed-off-by: Pawel Rucki <[email protected]>
  • Loading branch information
pawelru authored Mar 1, 2024
1 parent a37ffd0 commit aacb5b8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title: Pattern-strip
author: Pawel Rucki
version: 1.0.0
quarto-required: ">=1.4.0"
contributes:
filters:
- pattern-strip.lua

Original file line number Diff line number Diff line change
@@ -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
}
}
9 changes: 6 additions & 3 deletions book/_quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aacb5b8

Please sign in to comment.