github.com/kovansky/hugo@v0.92.3-0.20220224232819-63076e4ff19f/markup/goldmark/codeblocks/integration_test.go (about) 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 codeblocks_test 15 16 import ( 17 "strings" 18 "testing" 19 20 "github.com/gohugoio/hugo/hugolib" 21 ) 22 23 func TestCodeblocks(t *testing.T) { 24 t.Parallel() 25 26 files := ` 27 -- config.toml -- 28 [markup] 29 [markup.highlight] 30 anchorLineNos = false 31 codeFences = true 32 guessSyntax = false 33 hl_Lines = '' 34 lineAnchors = '' 35 lineNoStart = 1 36 lineNos = false 37 lineNumbersInTable = true 38 noClasses = false 39 style = 'monokai' 40 tabWidth = 4 41 -- layouts/_default/_markup/render-codeblock-goat.html -- 42 {{ $diagram := diagrams.Goat .Code }} 43 Goat SVG:{{ substr $diagram.SVG 0 100 | safeHTML }} }}| 44 Goat Attribute: {{ .Attributes.width}}| 45 -- layouts/_default/_markup/render-codeblock-go.html -- 46 Go Code: {{ .Code | safeHTML }}| 47 Go Language: {{ .Lang }}| 48 -- layouts/_default/single.html -- 49 {{ .Content }} 50 -- content/p1.md -- 51 --- 52 title: "p1" 53 --- 54 55 ## Ascii Diagram 56 57 CODE_FENCEgoat { width="600" } 58 ---> 59 CODE_FENCE 60 61 ## Go Code 62 63 CODE_FENCEgo 64 fmt.Println("Hello, World!"); 65 CODE_FENCE 66 67 ## Golang Code 68 69 CODE_FENCEgolang 70 fmt.Println("Hello, Golang!"); 71 CODE_FENCE 72 73 ## Bash Code 74 75 CODE_FENCEbash { linenos=inline,hl_lines=[2,"5-6"],linenostart=32 class=blue } 76 echo "l1"; 77 echo "l2"; 78 echo "l3"; 79 echo "l4"; 80 echo "l5"; 81 echo "l6"; 82 echo "l7"; 83 echo "l8"; 84 CODE_FENCE 85 ` 86 87 files = strings.ReplaceAll(files, "CODE_FENCE", "```") 88 89 b := hugolib.NewIntegrationTestBuilder( 90 hugolib.IntegrationTestConfig{ 91 T: t, 92 TxtarString: files, 93 NeedsOsFS: false, 94 }, 95 ).Build() 96 97 b.AssertFileContent("public/p1/index.html", ` 98 Goat SVG:<svg class='diagram' 99 Goat Attribute: 600| 100 101 Go Language: go| 102 Go Code: fmt.Println("Hello, World!"); 103 104 Go Code: fmt.Println("Hello, Golang!"); 105 Go Language: golang| 106 107 108 `, 109 "Goat SVG:<svg class='diagram' xmlns='http://www.w3.org/2000/svg' version='1.1' height='25' width='40'", 110 "Goat Attribute: 600|", 111 "<h2 id=\"go-code\">Go Code</h2>\nGo Code: fmt.Println(\"Hello, World!\");\n|\nGo Language: go|", 112 "<h2 id=\"golang-code\">Golang Code</h2>\nGo Code: fmt.Println(\"Hello, Golang!\");\n|\nGo Language: golang|", 113 "<h2 id=\"bash-code\">Bash Code</h2>\n<div class=\"highlight blue\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\"><span class=\"line\"><span class=\"ln\">32</span><span class=\"cl\"><span class=\"nb\">echo</span> <span class=\"s2\">"l1"</span><span class=\"p\">;</span>\n</span></span><span class=\"line hl\"><span class=\"ln\">33</span>", 114 ) 115 }