From 63a63d258264317fa9ea0ac9683b85839e9b30c3 Mon Sep 17 00:00:00 2001 From: Carsten Gips Date: Sat, 2 Sep 2023 17:45:01 +0200 Subject: [PATCH 1/6] fix #83: remove attributes from codeblocks --- filters/hugo.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/filters/hugo.lua b/filters/hugo.lua index 6f73b67..2c96ab1 100644 --- a/filters/hugo.lua +++ b/filters/hugo.lua @@ -62,6 +62,13 @@ function Image(el) end +-- remove attributes from code block as hugo won't do syntax highlighting if attributes are present +function CodeBlock(el) + el.attributes = {} + return el +end + + -- Replace native Divs with "real" Divs or Shortcodes function Div(el) -- Replace "showme" Div with "expand" Shortcode From 30f88da2579596b5cc4a2da393feedda0ae105ef Mon Sep 17 00:00:00 2001 From: Carsten Gips Date: Sat, 2 Sep 2023 17:47:44 +0200 Subject: [PATCH 2/6] fix #83: remove classes and attributes from inline code --- filters/hugo.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/filters/hugo.lua b/filters/hugo.lua index 2c96ab1..d8a20b4 100644 --- a/filters/hugo.lua +++ b/filters/hugo.lua @@ -69,6 +69,13 @@ function CodeBlock(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 From 9b193b278b05a787e04980f479c4b942682f9522 Mon Sep 17 00:00:00 2001 From: Carsten Gips Date: Sat, 2 Sep 2023 17:48:40 +0200 Subject: [PATCH 3/6] add testcases --- filters/test/codeblocks.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 filters/test/codeblocks.md 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. From 7ef6ae421910cfc9aa76315fe2661b8be56ec549 Mon Sep 17 00:00:00 2001 From: Carsten Gips Date: Sat, 2 Sep 2023 17:51:10 +0200 Subject: [PATCH 4/6] rig up makefile targets --- filters/test/Makefile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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 From f9a5ec79da539363b6c1d0653c670f70b344d45e Mon Sep 17 00:00:00 2001 From: Carsten Gips Date: Sat, 2 Sep 2023 19:06:41 +0200 Subject: [PATCH 5/6] add expected results --- filters/test/expected_codeblocks.native | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 filters/test/expected_codeblocks.native 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." + ] +] From 5248cf465d4dcacdfd25996fd5e7713b8a1e03ff Mon Sep 17 00:00:00 2001 From: Carsten Gips Date: Sat, 2 Sep 2023 19:12:32 +0200 Subject: [PATCH 6/6] Update filters/hugo.lua --- filters/hugo.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filters/hugo.lua b/filters/hugo.lua index d8a20b4..01608cc 100644 --- a/filters/hugo.lua +++ b/filters/hugo.lua @@ -62,7 +62,7 @@ function Image(el) end --- remove attributes from code block as hugo won't do syntax highlighting if attributes are present +-- remove attributes from code blocks as hugo won't do syntax highlighting if attributes are present function CodeBlock(el) el.attributes = {} return el