github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/markup/highlight/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 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\">&#34;this highlight shortcode&#34;</span><span class=\"p\">)</span></code>:End.",
    80  		"Inline Unknown:<code class=\"code-inline language-foo\">(message &#34;this highlight shortcode&#34;)</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\">&#34;highlight me&#34;</span><span class=\"o\">)</span>\n</code>",
    82  		"HighlightCodeBlock: Wrapped:<code class=\"code-inline language-html\">(message &#34;highlight me 2&#34;)</code>|Inner:<code class=\"code-inline language-html\">(message &#34;highlight me 2&#34;)</code>",
    83  		"<code class=\"code-inline language-foo\">(message &#34;highlight me 3&#34;)\n</code>",
    84  	)
    85  }
    86  
    87  // Issue #11311
    88  func TestIssue11311(t *testing.T) {
    89  	t.Parallel()
    90  
    91  	files := `
    92  -- config.toml --
    93  [markup.highlight]
    94  noClasses = false
    95  -- content/_index.md --
    96  ---
    97  title: home
    98  ---
    99  §§§go
   100  xəx := 0
   101  §§§
   102  -- layouts/index.html --
   103  {{ .Content }}
   104  `
   105  
   106  	b := hugolib.NewIntegrationTestBuilder(
   107  		hugolib.IntegrationTestConfig{
   108  			T:           t,
   109  			TxtarString: files,
   110  			NeedsOsFS:   false,
   111  		},
   112  	).Build()
   113  
   114  	b.AssertFileContent("public/index.html", `
   115  		<span class="nx">xəx</span>
   116  	`)
   117  }