Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter: remove attributes from code blocks (hugo) #168

Merged
merged 6 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions filters/hugo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ function Image(el)
end


-- remove attributes from code blocks as hugo won't do syntax highlighting if attributes are present
function CodeBlock(el)
el.attributes = {}
return el
end


-- remove classes and other attributes from inline code as hugo won't do syntax highlighting if attributes are present
function Code(el)
el.attr = {}
return el
end


-- Replace native Divs with "real" Divs or Shortcodes
function Div(el)
-- Replace "showme" Div with "expand" Shortcode
Expand Down
13 changes: 11 additions & 2 deletions filters/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ LUA_MAKEDEPS = ../hugo_makedeps.lua
LUA_INCLUDEMD = ../include_mdfiles.lua


test: test_rewritelinks test_makedeps test_includemd test_tabs
test: test_rewritelinks test_makedeps test_includemd test_tabs test_code

test_rewritelinks: $(FILES_TRANSFORM)
@$(PANDOC) -L $(LUA_REWRITELINKS) -t native $^ \
Expand Down Expand Up @@ -65,6 +65,10 @@ test_tabs: tabs_plain.md tabs_group.md tabs_title.md
@$(PANDOC) -L ../hugo.lua -t native tabs_title.md \
| $(DIFF) expected_tabs_title.native -

test_code: codeblocks.md
@$(PANDOC) -L ../hugo.lua -t native codeblocks.md \
| $(DIFF) expected_codeblocks.native -


expected: expected_rewritelinks1.native expected_rewritelinks2.native expected_rewritelinks3.native expected_rewritelinks4.native expected_rewritelinks5.native
expected_rewritelinks1.native: $(FILES_TRANSFORM)
Expand Down Expand Up @@ -114,11 +118,16 @@ expected_tabs_group.native: tabs_group.md
expected_tabs_title.native: tabs_title.md
$(PANDOC) -L ../hugo.lua -t native -o $@ $^

expected: expected_codeblocks.native
expected_codeblocks.native: codeblocks.md
$(PANDOC) -L ../hugo.lua -t native -o $@ $^


clean:
rm -rf expected_rewritelinks1.native expected_rewritelinks2.native expected_rewritelinks3.native expected_rewritelinks4.native expected_rewritelinks5.native
rm -rf expected_makedeps1.native expected_makedeps2.native expected_makedeps3.native expected_makedeps4.native expected_makedeps5.native expected_makedeps6.native expected_makedeps7.native expected_makedeps8.native
rm -rf expected_inludemd1.native expected_inludemd2.native expected_inludemd3.native expected_inludemd4.native
rm -rf expected_tabs_plain.native expected_tabs_group.native expected_tabs_title.native
rm -rf expected_codeblocks.native

.PHONY: test test_rewritelinks test_makedeps test_includemd test_tabs expected clean
.PHONY: test test_rewritelinks test_makedeps test_includemd test_tabs test_code expected clean
19 changes: 19 additions & 0 deletions filters/test/codeblocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
wuppie fluppie

```java
class Foo {}
```

foo bar

``` {.haskell size="tiny"}
class Monad m where
(>>=) :: m a -> (a -> m b) -> m b
return :: a -> m a
```

lorem ipsum

`void` is to be expected.

`void`{.c}: same but highlighting.
29 changes: 29 additions & 0 deletions filters/test/expected_codeblocks.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[ Para [ Str "wuppie" , Space , Str "fluppie" ]
, CodeBlock ( "" , [ "java" ] , [] ) "class Foo {}"
, Para [ Str "foo" , Space , Str "bar" ]
, CodeBlock
( "" , [ "haskell" ] , [] )
"class Monad m where\n (>>=) :: m a -> (a -> m b) -> m b\n return :: a -> m a"
, Para [ Str "lorem" , Space , Str "ipsum" ]
, Para
[ Code ( "" , [] , [] ) "void"
, Space
, Str "is"
, Space
, Str "to"
, Space
, Str "be"
, Space
, Str "expected."
]
, Para
[ Code ( "" , [] , [] ) "void"
, Str ":"
, Space
, Str "same"
, Space
, Str "but"
, Space
, Str "highlighting."
]
]