integration_test.go (2763B)
1 // Copyright 2022 The Hugo Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package highlight_test 15 16 import ( 17 "testing" 18 19 "github.com/gohugoio/hugo/hugolib" 20 ) 21 22 func TestHighlightInline(t *testing.T) { 23 t.Parallel() 24 25 files := ` 26 -- config.toml -- 27 [markup] 28 [markup.highlight] 29 codeFences = true 30 noClasses = false 31 -- content/p1.md -- 32 --- 33 title: "p1" 34 --- 35 36 ## Inline in Shortcode 37 38 Inline:{{< highlight emacs "hl_inline=true" >}}(message "this highlight shortcode"){{< /highlight >}}:End. 39 Inline Unknown:{{< highlight foo "hl_inline=true" >}}(message "this highlight shortcode"){{< /highlight >}}:End. 40 41 ## Inline in code block 42 43 Not sure if this makes sense, but add a test for it: 44 45 §§§bash {hl_inline=true} 46 (message "highlight me") 47 §§§ 48 49 ## HighlightCodeBlock in hook 50 51 §§§html 52 (message "highlight me 2") 53 §§§ 54 55 ## Unknown lexer 56 57 §§§foo {hl_inline=true} 58 (message "highlight me 3") 59 §§§ 60 61 62 -- layouts/_default/_markup/render-codeblock-html.html -- 63 {{ $opts := dict "hl_inline" true }} 64 {{ $result := transform.HighlightCodeBlock . $opts }} 65 HighlightCodeBlock: Wrapped:{{ $result.Wrapped }}|Inner:{{ $result.Inner }} 66 -- layouts/_default/single.html -- 67 {{ .Content }} 68 ` 69 70 b := hugolib.NewIntegrationTestBuilder( 71 hugolib.IntegrationTestConfig{ 72 T: t, 73 TxtarString: files, 74 NeedsOsFS: false, 75 }, 76 ).Build() 77 78 b.AssertFileContent("public/p1/index.html", 79 "Inline:<code class=\"code-inline language-emacs\"><span class=\"p\">(</span><span class=\"nf\">message</span> <span class=\"s\">"this highlight shortcode"</span><span class=\"p\">)</span></code>:End.", 80 "Inline Unknown:<code class=\"code-inline language-foo\">(message "this highlight shortcode")</code>:End.", 81 "Not sure if this makes sense, but add a test for it:</p>\n<code class=\"code-inline language-bash\"><span class=\"o\">(</span>message <span class=\"s2\">"highlight me"</span><span class=\"o\">)</span>\n</code>", 82 "HighlightCodeBlock: Wrapped:<code class=\"code-inline language-html\">(message "highlight me 2")</code>|Inner:<code class=\"code-inline language-html\">(message "highlight me 2")</code>", 83 "<code class=\"code-inline language-foo\">(message "highlight me 3")\n</code>", 84 ) 85 }