Rewrite Mermaid and KaTeX to be usable both from shorcode and code block, update dependencies
This commit is contained in:
@@ -158,7 +158,6 @@
|
|||||||
direction: ltr;
|
direction: ltr;
|
||||||
unicode-bidi: embed;
|
unicode-bidi: embed;
|
||||||
border-radius: $border-radius;
|
border-radius: $border-radius;
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
table tr {
|
table tr {
|
||||||
td pre code > span {
|
td pre code > span {
|
||||||
@@ -214,7 +213,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.markdown-inner {
|
.markdown-inner {
|
||||||
// Util class to remove extra margin in nested markdown content
|
// Utility class to remove extra margin in nested markdown content
|
||||||
> :first-child {
|
> :first-child {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"delimiters": [
|
||||||
|
{"left": "$$", "right": "$$", "display": true},
|
||||||
|
{"left": "\\(", "right": "\\)", "display": false},
|
||||||
|
{"left": "\\[", "right": "\\]", "display": true}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -5,7 +5,21 @@ title: KaTeX
|
|||||||
|
|
||||||
KaTeX shortcode let you render math typesetting in markdown document. See [KaTeX](https://katex.org/)
|
KaTeX shortcode let you render math typesetting in markdown document. See [KaTeX](https://katex.org/)
|
||||||
|
|
||||||
## Example
|
{{% hint info %}}
|
||||||
|
**Override KaTeX initialization config**
|
||||||
|
To override the [initialization config](https://katex.org/docs/options.html) for KaTeX,
|
||||||
|
create a `katex.json` file in your `assets` folder!
|
||||||
|
{{% /hint %}}
|
||||||
|
|
||||||
|
# Example
|
||||||
|
{{< katex />}}
|
||||||
|
|
||||||
|
|
||||||
|
## Activation
|
||||||
|
KaTeX is activated on the page by first use of the shortcode or render block. you can force activation with empty `{{</* katex /*/>}}` and use delimiters defined in configuration in `assets/katex.json`.
|
||||||
|
|
||||||
|
## Rendering as block
|
||||||
|
|
||||||
{{% columns %}}
|
{{% columns %}}
|
||||||
|
|
||||||
```latex
|
```latex
|
||||||
@@ -14,18 +28,57 @@ f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
|
|||||||
{{< /katex */>}}
|
{{< /katex */>}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
````latex
|
||||||
|
```katex
|
||||||
|
f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
|
||||||
|
```
|
||||||
|
````
|
||||||
|
|
||||||
|
````latex
|
||||||
|
$$
|
||||||
|
f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
|
||||||
|
$$
|
||||||
|
````
|
||||||
|
|
||||||
<--->
|
<--->
|
||||||
|
|
||||||
{{< katex display=true >}}
|
{{< katex display=true >}}
|
||||||
f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
|
f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
|
||||||
{{< /katex >}}
|
{{< /katex >}}
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
```katex
|
||||||
|
f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
$$
|
||||||
|
f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
|
||||||
|
$$
|
||||||
|
|
||||||
{{% /columns %}}
|
{{% /columns %}}
|
||||||
|
|
||||||
## Display Mode Example
|
## Rendering inline
|
||||||
|
When KaTeX is active on the page it is possible to write inline expressions.
|
||||||
|
|
||||||
|
| Code | Output |
|
||||||
|
| -- | -- |
|
||||||
|
| `{{</* katex >}}\pi(x){{< /katex */>}}` | {{< katex >}}\pi(x){{< /katex >}} |
|
||||||
|
| `\\( \pi(x) \\)` | \\( \pi(x) \\) |
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
KaTeX configuration could be adjusted by editing `assets/katex.json` file. For example to enabled inline delimiters `$..$` put content below into the file.
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"delimiters": [
|
||||||
|
{"left": "$$", "right": "$$", "display": true},
|
||||||
|
{"left": "$", "right": "$", "display": false},
|
||||||
|
{"left": "\\(", "right": "\\)", "display": false},
|
||||||
|
{"left": "\\[", "right": "\\]", "display": true}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Here is some inline example: {{< katex >}}\pi(x){{< /katex >}}, rendered in the same line. And below is `display` example, having `display: block`
|
|
||||||
{{< katex display=true >}}
|
|
||||||
f(x) = \int_{-\infty}^\infty\hat f(\xi)\,e^{2 \pi i \xi x}\,d\xi
|
|
||||||
{{< /katex >}}
|
|
||||||
Text continues here.
|
|
||||||
|
|||||||
@@ -10,6 +10,35 @@ create a `mermaid.json` file in your `assets` folder!
|
|||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
{{% columns %}}
|
||||||
|
|
||||||
|
````tpl
|
||||||
|
```mermaid
|
||||||
|
stateDiagram-v2
|
||||||
|
State1: The state with a note
|
||||||
|
note right of State1
|
||||||
|
Important information! You can write
|
||||||
|
notes.
|
||||||
|
end note
|
||||||
|
State1 --> State2
|
||||||
|
note left of State2 : This is the note to the left.
|
||||||
|
```
|
||||||
|
````
|
||||||
|
|
||||||
|
<--->
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
stateDiagram-v2
|
||||||
|
State1: The state with a note
|
||||||
|
note right of State1
|
||||||
|
Important information! You can write
|
||||||
|
notes.
|
||||||
|
end note
|
||||||
|
State1 --> State2
|
||||||
|
note left of State2 : This is the note to the left.
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% /columns %}}
|
||||||
|
|
||||||
{{% columns %}}
|
{{% columns %}}
|
||||||
|
|
||||||
@@ -28,7 +57,7 @@ stateDiagram-v2
|
|||||||
|
|
||||||
<--->
|
<--->
|
||||||
|
|
||||||
{{<mermaid>}}
|
{{< mermaid >}}
|
||||||
stateDiagram-v2
|
stateDiagram-v2
|
||||||
State1: The state with a note
|
State1: The state with a note
|
||||||
note right of State1
|
note right of State1
|
||||||
@@ -37,6 +66,129 @@ stateDiagram-v2
|
|||||||
end note
|
end note
|
||||||
State1 --> State2
|
State1 --> State2
|
||||||
note left of State2 : This is the note to the left.
|
note left of State2 : This is the note to the left.
|
||||||
{{</mermaid>}}
|
{{< /mermaid >}}
|
||||||
|
|
||||||
{{% /columns %}}
|
{{% /columns %}}
|
||||||
|
|
||||||
|
## Diagrams
|
||||||
|
Explore more diagrams and syntax on Mermaid [documentation page](https://mermaid.js.org/syntax/flowchart.html).
|
||||||
|
|
||||||
|
{{% columns %}}
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
stateDiagram-v2
|
||||||
|
State1: The state with a note
|
||||||
|
note right of State1
|
||||||
|
Important information! You can write
|
||||||
|
notes.
|
||||||
|
end note
|
||||||
|
State1 --> State2
|
||||||
|
note left of State2 : This is the note to the left.
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
Alice->>John: Hello John, how are you?
|
||||||
|
John-->>Alice: Great!
|
||||||
|
Alice-)John: See you later!
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
---
|
||||||
|
title: Animal example
|
||||||
|
---
|
||||||
|
classDiagram
|
||||||
|
note "From Duck till Zebra"
|
||||||
|
Animal <|-- Duck
|
||||||
|
note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging"
|
||||||
|
Animal <|-- Fish
|
||||||
|
Animal <|-- Zebra
|
||||||
|
Animal : +int age
|
||||||
|
Animal : +String gender
|
||||||
|
Animal: +isMammal()
|
||||||
|
Animal: +mate()
|
||||||
|
class Duck{
|
||||||
|
+String beakColor
|
||||||
|
+swim()
|
||||||
|
+quack()
|
||||||
|
}
|
||||||
|
class Fish{
|
||||||
|
-int sizeInFeet
|
||||||
|
-canEat()
|
||||||
|
}
|
||||||
|
class Zebra{
|
||||||
|
+bool is_wild
|
||||||
|
+run()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
---
|
||||||
|
title: Simple sample
|
||||||
|
---
|
||||||
|
stateDiagram-v2
|
||||||
|
[*] --> Still
|
||||||
|
Still --> [*]
|
||||||
|
|
||||||
|
Still --> Moving
|
||||||
|
Moving --> Still
|
||||||
|
Moving --> Crash
|
||||||
|
Crash --> [*]
|
||||||
|
```
|
||||||
|
|
||||||
|
<--->
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
---
|
||||||
|
title: Example Git diagram
|
||||||
|
---
|
||||||
|
gitGraph
|
||||||
|
commit
|
||||||
|
commit
|
||||||
|
branch develop
|
||||||
|
checkout develop
|
||||||
|
commit
|
||||||
|
commit
|
||||||
|
checkout main
|
||||||
|
merge develop
|
||||||
|
commit
|
||||||
|
commit
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
gantt
|
||||||
|
title A Gantt Diagram
|
||||||
|
dateFormat YYYY-MM-DD
|
||||||
|
section Section
|
||||||
|
A task :a1, 2014-01-01, 30d
|
||||||
|
Another task :after a1, 20d
|
||||||
|
section Another
|
||||||
|
Task in Another :2014-01-12, 12d
|
||||||
|
another task :24d
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
pie title Pets adopted by volunteers
|
||||||
|
"Dogs" : 386
|
||||||
|
"Cats" : 85
|
||||||
|
"Rats" : 15
|
||||||
|
```
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
quadrantChart
|
||||||
|
title Reach and engagement of campaigns
|
||||||
|
x-axis Low Reach --> High Reach
|
||||||
|
y-axis Low Engagement --> High Engagement
|
||||||
|
quadrant-1 We should expand
|
||||||
|
quadrant-2 Need to promote
|
||||||
|
quadrant-3 Re-evaluate
|
||||||
|
quadrant-4 May be improved
|
||||||
|
Campaign A: [0.3, 0.6]
|
||||||
|
Campaign B: [0.45, 0.23]
|
||||||
|
Campaign C: [0.57, 0.69]
|
||||||
|
Campaign D: [0.78, 0.34]
|
||||||
|
Campaign E: [0.40, 0.34]
|
||||||
|
Campaign F: [0.35, 0.78]
|
||||||
|
```
|
||||||
|
|
||||||
|
{{% /columns %}}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{{- if not (.Page.Store.Get "katex") -}}
|
||||||
|
<!-- Include katex only first time -->
|
||||||
|
<link rel="stylesheet" href="{{ "katex/katex.min.css" | relURL }}" />
|
||||||
|
<script defer src="{{ "katex/katex.min.js" | relURL }}"></script>
|
||||||
|
{{ with resources.Get "katex.json" }}
|
||||||
|
<script defer src="{{ "katex/auto-render.min.js" | relURL }}" onload="renderMathInElement(document.body, {{ .Content | safeJS }});"></script>
|
||||||
|
{{ end }}
|
||||||
|
{{- .Page.Store.Set "katex" true -}}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- with .Inner }}
|
||||||
|
<span>\[ {{ . }} \]</span>
|
||||||
|
{{ end -}}
|
||||||
@@ -1,13 +1,19 @@
|
|||||||
{{- if not (.Page.Scratch.Get "katex") -}}
|
{{- if not (.Page.Store.Get "katex") -}}
|
||||||
<!-- Include katex only first time -->
|
<!-- Include katex only first time -->
|
||||||
<link rel="stylesheet" href="{{ "katex/katex.min.css" | relURL }}" />
|
<link rel="stylesheet" href="{{ "katex/katex.min.css" | relURL }}" />
|
||||||
<script defer src="{{ "katex/katex.min.js" | relURL }}"></script>
|
<script defer src="{{ "katex/katex.min.js" | relURL }}"></script>
|
||||||
<script defer src="{{ "katex/auto-render.min.js" | relURL }}" onload="renderMathInElement(document.body);"></script>
|
{{ with resources.Get "katex.json" }}
|
||||||
{{- .Page.Scratch.Set "katex" true -}}
|
<script defer src="{{ "katex/auto-render.min.js" | relURL }}" onload="renderMathInElement(document.body, {{ .Content | safeJS }});"></script>
|
||||||
|
{{ end }}
|
||||||
|
{{- .Page.Store.Set "katex" true -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
<span {{- with .Get "class" }} class="{{ . }}"{{ end }}>
|
{{ if .Inner }}
|
||||||
{{ with .Get "display" }}\[{{else}}\({{end}}
|
<span>
|
||||||
{{- .InnerDeindent -}}
|
{{- if .Get "display" }}
|
||||||
{{ with .Get "display" }}\]{{else}}\){{end}}
|
\[ {{ .Inner }} \]
|
||||||
|
{{ else }}
|
||||||
|
\( {{ .Inner }} \)
|
||||||
|
{{ end -}}
|
||||||
</span>
|
</span>
|
||||||
|
{{ end }}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1 +1 @@
|
|||||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,(function(e){return function(){"use strict";var t={771:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var o={};return function(){r.d(o,{default:function(){return d}});var e=r(771),t=r.n(e);const n=function(e,t,n){let r=n,o=0;const i=e.length;for(;r<t.length;){const n=t[r];if(o<=0&&t.slice(r,r+i)===e)return r;"\\"===n?r++:"{"===n?o++:"}"===n&&o--,r++}return-1},i=/^\\begin{/;var a=function(e,t){let r;const o=[],a=new RegExp("("+t.map((e=>e.left.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"))).join("|")+")");for(;r=e.search(a),-1!==r;){r>0&&(o.push({type:"text",data:e.slice(0,r)}),e=e.slice(r));const a=t.findIndex((t=>e.startsWith(t.left)));if(r=n(t[a].right,e,t[a].left.length),-1===r)break;const l=e.slice(0,r+t[a].right.length),s=i.test(l)?l:e.slice(t[a].left.length,r);o.push({type:"math",data:s,rawData:l,display:t[a].display}),e=e.slice(r+t[a].right.length)}return""!==e&&o.push({type:"text",data:e}),o};const l=function(e,n){const r=a(e,n.delimiters);if(1===r.length&&"text"===r[0].type)return null;const o=document.createDocumentFragment();for(let e=0;e<r.length;e++)if("text"===r[e].type)o.appendChild(document.createTextNode(r[e].data));else{const i=document.createElement("span");let a=r[e].data;n.displayMode=r[e].display;try{n.preProcess&&(a=n.preProcess(a)),t().render(a,i,n)}catch(i){if(!(i instanceof t().ParseError))throw i;n.errorCallback("KaTeX auto-render: Failed to parse `"+r[e].data+"` with ",i),o.appendChild(document.createTextNode(r[e].rawData));continue}o.appendChild(i)}return o},s=function(e,t){for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(3===r.nodeType){let o=r.textContent,i=r.nextSibling,a=0;for(;i&&i.nodeType===Node.TEXT_NODE;)o+=i.textContent,i=i.nextSibling,a++;const s=l(o,t);if(s){for(let e=0;e<a;e++)r.nextSibling.remove();n+=s.childNodes.length-1,e.replaceChild(s,r)}else n+=a}else if(1===r.nodeType){const e=" "+r.className+" ";-1===t.ignoredTags.indexOf(r.nodeName.toLowerCase())&&t.ignoredClasses.every((t=>-1===e.indexOf(" "+t+" ")))&&s(r,t)}}};var d=function(e,t){if(!e)throw new Error("No element provided to render");const n={};for(const e in t)t.hasOwnProperty(e)&&(n[e]=t[e]);n.delimiters=n.delimiters||[{left:"$$",right:"$$",display:!0},{left:"\\(",right:"\\)",display:!1},{left:"\\begin{equation}",right:"\\end{equation}",display:!0},{left:"\\begin{align}",right:"\\end{align}",display:!0},{left:"\\begin{alignat}",right:"\\end{alignat}",display:!0},{left:"\\begin{gather}",right:"\\end{gather}",display:!0},{left:"\\begin{CD}",right:"\\end{CD}",display:!0},{left:"\\[",right:"\\]",display:!0}],n.ignoredTags=n.ignoredTags||["script","noscript","style","textarea","pre","code","option"],n.ignoredClasses=n.ignoredClasses||[],n.errorCallback=n.errorCallback||console.error,n.macros=n.macros||{},s(e,n)}}(),o=o.default}()}));
|
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("katex")):"function"==typeof define&&define.amd?define(["katex"],t):"object"==typeof exports?exports.renderMathInElement=t(require("katex")):e.renderMathInElement=t(e.katex)}("undefined"!=typeof self?self:this,(function(e){return function(){"use strict";var t={757:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};var o={};r.d(o,{default:function(){return p}});var i=r(757),a=r.n(i);const l=function(e,t,n){let r=n,o=0;const i=e.length;for(;r<t.length;){const n=t[r];if(o<=0&&t.slice(r,r+i)===e)return r;"\\"===n?r++:"{"===n?o++:"}"===n&&o--,r++}return-1},s=/^\\begin{/;var d=function(e,t){let n;const r=[],o=new RegExp("("+t.map((e=>e.left.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"))).join("|")+")");for(;n=e.search(o),-1!==n;){n>0&&(r.push({type:"text",data:e.slice(0,n)}),e=e.slice(n));const o=t.findIndex((t=>e.startsWith(t.left)));if(n=l(t[o].right,e,t[o].left.length),-1===n)break;const i=e.slice(0,n+t[o].right.length),a=s.test(i)?i:e.slice(t[o].left.length,n);r.push({type:"math",data:a,rawData:i,display:t[o].display}),e=e.slice(n+t[o].right.length)}return""!==e&&r.push({type:"text",data:e}),r};const c=function(e,t){const n=d(e,t.delimiters);if(1===n.length&&"text"===n[0].type)return null;const r=document.createDocumentFragment();for(let e=0;e<n.length;e++)if("text"===n[e].type)r.appendChild(document.createTextNode(n[e].data));else{const o=document.createElement("span");let i=n[e].data;t.displayMode=n[e].display;try{t.preProcess&&(i=t.preProcess(i)),a().render(i,o,t)}catch(o){if(!(o instanceof a().ParseError))throw o;t.errorCallback("KaTeX auto-render: Failed to parse `"+n[e].data+"` with ",o),r.appendChild(document.createTextNode(n[e].rawData));continue}r.appendChild(o)}return r},f=function(e,t){for(let n=0;n<e.childNodes.length;n++){const r=e.childNodes[n];if(3===r.nodeType){let o=r.textContent,i=r.nextSibling,a=0;for(;i&&i.nodeType===Node.TEXT_NODE;)o+=i.textContent,i=i.nextSibling,a++;const l=c(o,t);if(l){for(let e=0;e<a;e++)r.nextSibling.remove();n+=l.childNodes.length-1,e.replaceChild(l,r)}else n+=a}else if(1===r.nodeType){const e=" "+r.className+" ";-1===t.ignoredTags.indexOf(r.nodeName.toLowerCase())&&t.ignoredClasses.every((t=>-1===e.indexOf(" "+t+" ")))&&f(r,t)}}};var p=function(e,t){if(!e)throw new Error("No element provided to render");const n={};for(const e in t)t.hasOwnProperty(e)&&(n[e]=t[e]);n.delimiters=n.delimiters||[{left:"$$",right:"$$",display:!0},{left:"\\(",right:"\\)",display:!1},{left:"\\begin{equation}",right:"\\end{equation}",display:!0},{left:"\\begin{align}",right:"\\end{align}",display:!0},{left:"\\begin{alignat}",right:"\\end{alignat}",display:!0},{left:"\\begin{gather}",right:"\\end{gather}",display:!0},{left:"\\begin{CD}",right:"\\end{CD}",display:!0},{left:"\\[",right:"\\]",display:!0}],n.ignoredTags=n.ignoredTags||["script","noscript","style","textarea","pre","code","option"],n.ignoredClasses=n.ignoredClasses||[],n.errorCallback=n.errorCallback||console.error,n.macros=n.macros||{},f(e,n)};return o=o.default}()}));
|
||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+368
-316
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user