added passthrough

This commit is contained in:
mtseng15 2025-05-05 16:11:38 -05:00
parent 9405c4c3d7
commit 29017f6d82
3 changed files with 63 additions and 0 deletions

View File

@ -177,6 +177,12 @@ disableKinds = ['taxonomy', 'taxonomyTerm']
# Can be overwritten by same param in page frontmatter # Can be overwritten by same param in page frontmatter
BookComments = true BookComments = true
# (Optional) Enables a Katex math engine that works with the Goldmark markdown
# pass through. This removes the need for shortcodes for math. Also requires
# defining the pass through delimiters.
# See below.
BookKatexMathPassthrough = true
# /!\ This is an experimental feature, might be removed or changed at any time # /!\ This is an experimental feature, might be removed or changed at any time
# (Optional, experimental, default false) Enables portable links and link checks in markdown pages. # (Optional, experimental, default false) Enables portable links and link checks in markdown pages.
# Portable links meant to work with text editors and let you write markdown without {{< relref >}} shortcode # Portable links meant to work with text editors and let you write markdown without {{< relref >}} shortcode
@ -186,6 +192,7 @@ disableKinds = ['taxonomy', 'taxonomyTerm']
# /!\ This is an experimental feature, might be removed or changed at any time # /!\ This is an experimental feature, might be removed or changed at any time
# (Optional, experimental, default false) Enables service worker that caches visited pages and resources for offline use. # (Optional, experimental, default false) Enables service worker that caches visited pages and resources for offline use.
BookServiceWorker = true BookServiceWorker = true
``` ```
### Multi-Language Support ### Multi-Language Support
@ -296,6 +303,40 @@ By default, Goldmark trims unsafe outputs which might prevent some shortcodes fr
If you are using `config.yaml` or `config.json`, consult the [configuration markup](https://gohugo.io/getting-started/configuration-markup/) If you are using `config.yaml` or `config.json`, consult the [configuration markup](https://gohugo.io/getting-started/configuration-markup/)
## Math
Rendering math equations is enabled by the Katex engine. There are two methods for implementing math support with different benefits.
### Shortcodes
As described in the Shortcodes section, the Katex shortcode will provide inline and block display (see: [Katex Shortcode](https://hugo-book-demo.netlify.app/docs/shortcodes/katex/)). This method is probably the best if rendering math is only required occasionally.
### Goldmark Passthrough
Alternatively, the Goldmark markdown rendering engine can be configured to pass blocks defined by delimiters to the Katex engine (see [Hugo docs](https://gohugo.io/content-management/mathematics/#overview)). Thus, short codes are not required. This method is likely the best if rending math is required frequently.
To enable this feature, add the following to your site configuration.
```toml
# Define the delimiters
[markup]
[markup.goldmark]
[markup.goldmark.extensions]
[markup.goldmark.extensions.passthrough]
enable = true
[markup.goldmark.extensions.passthrough.delimiters]
block = [['\[', '\]'], ['$$', '$$']]
inline = [['\(', '\)'], ['$', '$']]
# Enable the pass through rendering
[params]
# ...
BookKatexMathPassthrough = true
# ...
```
Note: the delimiters above delimiters are examples only. You can chose your own delimiters.
## Versioning ## Versioning
This theme follows a simple incremental versioning. e.g. `v1`, `v2` and so on. There might be breaking changes between versions. This theme follows a simple incremental versioning. e.g. `v1`, `v2` and so on. There might be breaking changes between versions.

View File

@ -25,6 +25,7 @@
<!-- Theme stylesheet, you can customize scss by creating `assets/custom.scss` in your website --> <!-- Theme stylesheet, you can customize scss by creating `assets/custom.scss` in your website -->
{{- $styles := resources.Get "book.scss" | resources.ExecuteAsTemplate "book.scss" . | css.Sass | resources.Minify | resources.Fingerprint }} {{- $styles := resources.Get "book.scss" | resources.ExecuteAsTemplate "book.scss" . | css.Sass | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" {{ template "integrity" $styles }}> <link rel="stylesheet" href="{{ $styles.RelPermalink }}" {{ template "integrity" $styles }}>
{{- if default true .Site.Params.BookSearch -}} {{- if default true .Site.Params.BookSearch -}}
{{- $searchJSFile := printf "%s.search.js" .Language.Lang }} {{- $searchJSFile := printf "%s.search.js" .Language.Lang }}
{{- $searchJS := resources.Get "search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify | resources.Fingerprint }} {{- $searchJS := resources.Get "search.js" | resources.ExecuteAsTemplate $searchJSFile . | resources.Minify | resources.Fingerprint }}
@ -54,3 +55,8 @@ https://github.com/alex-shpak/hugo-book
integrity="{{ .Data.Integrity }}" crossorigin="anonymous" integrity="{{ .Data.Integrity }}" crossorigin="anonymous"
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
<!--Katex Partial Injection-->
{{ if .Param "BookKatexMathPassthrough" }}
{{ partialCached "docs/math.html" . }}
{{ end }}

View File

@ -0,0 +1,16 @@
<!-- Include katex only first time -->
<link rel="stylesheet" href="{{ "katex/katex.min.css" | relURL }}" />
<script defer src="{{ "katex/katex.min.js" | relURL }}"></script>
<script defer src="{{ "katex/auto-render.min.js" | relURL }}" onload="renderMathInElement(document.body, {
// customised options
// • auto-render specific keys, e.g.:
delimiters: [
{left: '$$', right: '$$', display: true},
{left: '$', right: '$', display: false},
{left: '\\(', right: '\\)', display: false},
{left: '\\[', right: '\\]', display: true}
],
// • rendering keys, e.g.:
throwOnError : false
});"></script>