forked from google/docsy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add render hook for 'chem' code blocks
Auto activation of `math' and 'chem' blocks Add ability to enable KateX and/or mhchem for individual pages only Upgrade to KaTeX 0.16.3
- Loading branch information
Showing
4 changed files
with
192 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{{ .Page.Store.Set "hasmhchem" true -}} | ||
|
||
{{/* set default delimiters */ -}} | ||
{{ $delimiter_left := "$$" -}} | ||
{{ $delimiter_right := "$$" -}} | ||
|
||
{{/* override delimiters if set in config file */ -}} | ||
{{ with $.Page.Site.Params.katex.options.delimiters -}} | ||
{{ range first 1 ( where . "display" true ) -}} | ||
{{ $delimiter_left = index . "left" -}} | ||
{{ $delimiter_right = index . "right" -}} | ||
{{ end -}} | ||
{{ end -}} | ||
|
||
{{/* output of chemical formulae */}} | ||
<div class="chem">{{ $delimiter_left -}} | ||
{{ .Inner | safeHTML -}} | ||
{{ $delimiter_right -}}</div>{{ "" -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
{{/* set default delimiters */}} | ||
{{ $delimiter_left := "$$" }} | ||
{{ $delimiter_right := "$$" }} | ||
{{ .Page.Store.Set "hasKaTeX" true -}} | ||
|
||
{{/* override delimiters if set in config file */}} | ||
{{ with $.Page.Site.Params.katex.options.delimiters }} | ||
{{ range first 1 ( where . "display" true ) }} | ||
{{ $delimiter_left = index . "left" }} | ||
{{ $delimiter_right = index . "right" }} | ||
{{ end }} | ||
{{end}} | ||
{{/* set default delimiters */ -}} | ||
{{ $delimiter_left := "$$" -}} | ||
{{ $delimiter_right := "$$" -}} | ||
|
||
{{/* override delimiters if set in config file */ -}} | ||
{{ with $.Page.Site.Params.katex.options.delimiters -}} | ||
{{ range first 1 ( where . "display" true ) -}} | ||
{{ $delimiter_left = index . "left" -}} | ||
{{ $delimiter_right = index . "right" -}} | ||
{{ end -}} | ||
{{ end -}} | ||
|
||
{{/* output of equation */}} | ||
<p>{{ $delimiter_left }} | ||
{{ .Inner | safeHTML }} | ||
{{ $delimiter_right }}</p> | ||
<div class="math">{{ $delimiter_left -}} | ||
{{ .Inner | safeHTML -}} | ||
{{ $delimiter_right }}</div>{{ "" -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
{{ $needKaTeX := or .Site.Params.katex.enable .Params.math .Params.chem -}} | ||
{{ $needmhchem := or .Site.Params.katex.mhchem.enable .Params.chem -}} | ||
{{ $needmermaid := .Site.Params.mermaid.enable -}} | ||
{{ if ge hugo.Version "0.93.0" -}} | ||
{{ with .Site.Params.mermaid }} | ||
{{ $needmermaid = true }} | ||
{{ end }} | ||
{{ $needmermaid = or $needmermaid (.Page.Store.Get "hasmermaid") -}} | ||
{{ end }} | ||
{{ $needmermaid = or $needmermaid (.Page.Store.Get "hasmermaid") -}} | ||
{{ else -}} | ||
{{ if or $needKaTeX $needmhchem $needmermaid -}} | ||
{{ warnf "Outdated Hugo version %s, consider upgrading to make full use of all theme features" hugo.Version }} | ||
{{ end -}} | ||
{{ end -}} | ||
|
||
{{ if .Site.Params.markmap.enable -}} | ||
<style> | ||
|
@@ -31,25 +37,27 @@ | |
<script src='{{ "js/deflate.js" | relURL }}'></script> | ||
{{ end -}} | ||
|
||
{{ if .Site.Params.katex.enable -}} | ||
<!-- load stylesheet and scripts for KaTeX support --> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" | ||
integrity="sha512-vJqxkZ+Sugf/6WRlpcxN01qVfX/29hF6qc33eHF1va3NgoV+U+wCi+uTAsQ10sDoGyBxHLdaHvGwDlV3yVYboA==" crossorigin="anonymous"> | ||
<!-- The loading of KaTeX is deferred to speed up page rendering --> | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" | ||
integrity="sha512-5ufNcHqOYgilGEHPfuRIQ5B/vDS1M8+UC+DESZ5CwVgGTg+b2Ol/15rYL/GiCWJ/Sx8oVo0FPFok1dPk8U9INQ==" | ||
crossorigin="anonymous"></script> | ||
<!-- check whether support of mhchem is enabled in config.toml --> | ||
{{ if .Site.Params.katex.mhchem.enable -}} | ||
<!-- To add support for displaying chemical equations and physical units, load the mhchem extension: --> | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/mhchem.min.js" | ||
integrity="sha512-HWb6LyQhO6UkmYLjdSblpgiOvvbdkoMRjln0POPhOVbZu3l4QdqwZnMJ/cuwKScU5pWARejB495TAAAz0WNsXQ==" | ||
crossorigin="anonymous"></script> | ||
{{ end -}} | ||
<!-- To automatically render math in text elements, include the auto-render extension: --> | ||
<script defer src='https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js' | ||
integrity='sha512-ZA/RPrAo88DlwRnnoNVqKINnQNcWERzRK03PDaA4GIJiVZvGFIWQbdWCsUebMZfkWohnfngsDjXzU6PokO4jGw==' crossorigin='anonymous' | ||
{{ printf "onload='renderMathInElement(%s, %s);'" (( .Site.Params.katex.html_dom_element | default "document.body" ) | safeJS ) ( printf "%s" ( $.Site.Params.katex.options | jsonify )) | safeHTMLAttr }}></script> | ||
{{ if $needKaTeX -}} | ||
{{/* load stylesheet and scripts for KaTeX support */ -}} | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" | ||
integrity="sha512-6VMVcy7XQNyarhVuiL50FzpgCFKsyTd6YO93aaQEyET+BNaWvj0IgKR86Bf6+AmWczxAcSnL+JGjo+iStgO1gQ==" crossorigin="anonymous"> | ||
{{/* The loading of KaTeX is deferred to speed up page rendering */ -}} | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" | ||
integrity="sha512-b9IKj4LCNrtCPBhceRcoYOHWW/S2q9fpl7iAJlyxYpykRj1SKM7FE9+E0NEnJ8g8ni47LBr2GuX9qzg/xeuwzQ==" | ||
crossorigin="anonymous"> | ||
</script> | ||
{{ if $needmhchem -}} | ||
{{/* To add support for displaying chemical equations and physical units, load the mhchem extension: */ -}} | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/mhchem.min.js" | ||
integrity="sha512-V1hl0fnOXW6Cdqe5ZVqtw8TBpJVpu3XRDRQti96j/04+tMarPrCdXEUE3UdfvfKYTpOn9DV4zEZBVr0HhDiuiQ==" | ||
crossorigin="anonymous"> | ||
</script> | ||
{{ end -}} | ||
{{/* To automatically render math in text elements, include the auto-render extension: */ -}} | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" | ||
integrity="sha512-iWiuBS5nt6r60fCz26Nd0Zqe0nbk1ZTIQbl3Kv7kYsX+yKMUFHzjaH2+AnM6vp2Xs+gNmaBAVWJjSmuPw76Efg==" crossorigin="anonymous" | ||
{{ printf "onload='renderMathInElement(%s, %s);'" (( $.Page.Site.Params.katex.html_dom_element | default "document.body" ) | safeJS ) ( printf "%s" ( $.Page.Site.Params.katex.options | jsonify )) | safeHTMLAttr }}> | ||
</script> | ||
{{ end -}} | ||
|
||
{{ $jsBs := resources.Get "vendor/bootstrap/dist/js/bootstrap.bundle.js" -}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters