| 1 |
// Copyright 2024 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 passthrough_test |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
|
| 19 |
"github.com/gohugoio/hugo/hugolib" |
| 20 |
) |
| 21 |
|
| 22 |
func TestPassthroughRenderHook(t *testing.T) { |
| 23 |
t.Parallel() |
| 24 |
|
| 25 |
files := ` |
| 26 |
-- hugo.toml -- |
| 27 |
[markup.goldmark.extensions.passthrough] |
| 28 |
enable = true |
| 29 |
[markup.goldmark.extensions.passthrough.delimiters] |
| 30 |
block = [['$$', '$$']] |
| 31 |
inline = [['$', '$']] |
| 32 |
-- content/p1.md -- |
| 33 |
--- |
| 34 |
title: "p1" |
| 35 |
--- |
| 36 |
## LaTeX test |
| 37 |
|
| 38 |
Some inline LaTeX 1: $a^*=x-b^*$. |
| 39 |
|
| 40 |
Block equation that would be mangled by default parser: |
| 41 |
|
| 42 |
$$a^*=x-b^*$$ |
| 43 |
|
| 44 |
Some inline LaTeX 2: $a^*=x-b^*$. |
| 45 |
|
| 46 |
-- layouts/single.html -- |
| 47 |
{{ .Content }} |
| 48 |
-- layouts/_markup/render-passthrough-block.html -- |
| 49 |
Passthrough block: {{ .Inner | safeHTML }}|{{ .Type }}|{{ .Ordinal }}:END |
| 50 |
-- layouts/_markup/render-passthrough-inline.html -- |
| 51 |
Passthrough inline: {{ .Inner | safeHTML }}|{{ .Type }}|{{ .Ordinal }}:END |
| 52 |
|
| 53 |
` |
| 54 |
|
| 55 |
b := hugolib.Test(t, files) |
| 56 |
b.AssertFileContent("public/p1/index.html", ` |
| 57 |
Some inline LaTeX 1: Passthrough inline: a^*=x-b^*|inline|0:END |
| 58 |
Passthrough block: a^*=x-b^*|block|1:END |
| 59 |
Some inline LaTeX 2: Passthrough inline: a^*=x-b^*|inline|2:END |
| 60 |
|
| 61 |
`) |
| 62 |
} |