diff --git a/filters/hugo.lua b/filters/hugo.lua index 6f73b67..01608cc 100644 --- a/filters/hugo.lua +++ b/filters/hugo.lua @@ -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 diff --git a/filters/test/Makefile b/filters/test/Makefile index 617f146..5202c39 100644 --- a/filters/test/Makefile +++ b/filters/test/Makefile @@ -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 $^ \ @@ -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) @@ -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 diff --git a/filters/test/codeblocks.md b/filters/test/codeblocks.md new file mode 100644 index 0000000..4c7a79b --- /dev/null +++ b/filters/test/codeblocks.md @@ -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. diff --git a/filters/test/expected_codeblocks.native b/filters/test/expected_codeblocks.native new file mode 100644 index 0000000..9de629d --- /dev/null +++ b/filters/test/expected_codeblocks.native @@ -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." + ] +]