diff --git a/README.md b/README.md index 90c23ccb0c3c..329054b3fab3 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ For more details on how to create distill-styled posts using `` tags, pleas #### Full support for math & code -**al-folio** supports fast math typesetting through [MathJax](https://www.mathjax.org/) and code syntax highlighting using [GitHub style](https://github.com/jwarby/jekyll-pygments-themes). Also supports [mermaid diagrams](https://mermaid-js.github.io/mermaid/#/) and [TikZ figures](https://tikzjax.com/). +**al-folio** supports fast math typesetting through [MathJax](https://www.mathjax.org/) and code syntax highlighting using [GitHub style](https://github.com/jwarby/jekyll-pygments-themes). Also supports [chartjs charts](https://www.chartjs.org/), [mermaid diagrams](https://mermaid-js.github.io/mermaid/#/), and [TikZ figures](https://tikzjax.com/).

diff --git a/_includes/scripts/chart.liquid b/_includes/scripts/chart.liquid new file mode 100644 index 000000000000..6240f9b57ccc --- /dev/null +++ b/_includes/scripts/chart.liquid @@ -0,0 +1,19 @@ +{% if page.chart %} + + +{% endif %} diff --git a/_layouts/default.liquid b/_layouts/default.liquid index 1e7ade3749d9..f42bfda8fa0f 100644 --- a/_layouts/default.liquid +++ b/_layouts/default.liquid @@ -48,6 +48,7 @@ {% include scripts/bootstrap.liquid %} {% include scripts/masonry.liquid %} {% include scripts/mermaid.liquid %} + {% include scripts/chart.liquid %} {% include scripts/misc.liquid %} {% include scripts/badges.liquid %} {% include scripts/mathjax.liquid %} diff --git a/_posts/2024-01-26-chartjs.md b/_posts/2024-01-26-chartjs.md new file mode 100644 index 000000000000..49b64f0a9c84 --- /dev/null +++ b/_posts/2024-01-26-chartjs.md @@ -0,0 +1,187 @@ +--- +layout: post +title: a post with chart.js +date: 2024-01-26 01:04:00 +description: this is what included chart.js code could look like +tags: formatting charts +categories: sample-posts +chart: true +--- + +This is an example post with some chart.js code. + +````markdown +```chart +{ + "type": "line", + "data": { + "labels": [ + "January", + "February", + "March", + "April", + "May", + "June", + "July" + ], + "datasets": [ + { + "label": "# of bugs", + "fill": false, + "lineTension": 0.1, + "backgroundColor": "rgba(75,192,192,0.4)", + "borderColor": "rgba(75,192,192,1)", + "borderCapStyle": "butt", + "borderDash": [], + "borderDashOffset": 0, + "borderJoinStyle": "miter", + "pointBorderColor": "rgba(75,192,192,1)", + "pointBackgroundColor": "#fff", + "pointBorderWidth": 1, + "pointHoverRadius": 5, + "pointHoverBackgroundColor": "rgba(75,192,192,1)", + "pointHoverBorderColor": "rgba(220,220,220,1)", + "pointHoverBorderWidth": 2, + "pointRadius": 1, + "pointHitRadius": 10, + "data": [ + 65, + 59, + 80, + 81, + 56, + 55, + 40 + ], + "spanGaps": false + } + ] + }, + "options": {} +} +``` +```` + +This is how it looks like: + +```chart +{ + "type": "line", + "data": { + "labels": [ + "January", + "February", + "March", + "April", + "May", + "June", + "July" + ], + "datasets": [ + { + "label": "# of bugs", + "fill": false, + "lineTension": 0.1, + "backgroundColor": "rgba(75,192,192,0.4)", + "borderColor": "rgba(75,192,192,1)", + "borderCapStyle": "butt", + "borderDash": [], + "borderDashOffset": 0, + "borderJoinStyle": "miter", + "pointBorderColor": "rgba(75,192,192,1)", + "pointBackgroundColor": "#fff", + "pointBorderWidth": 1, + "pointHoverRadius": 5, + "pointHoverBackgroundColor": "rgba(75,192,192,1)", + "pointHoverBorderColor": "rgba(220,220,220,1)", + "pointHoverBorderWidth": 2, + "pointRadius": 1, + "pointHitRadius": 10, + "data": [ + 65, + 59, + 80, + 81, + 56, + 55, + 40 + ], + "spanGaps": false + } + ] + }, + "options": {} +} +``` + +Also another example chart. + +````markdown +```chart +{ + "type": "doughnut", + "data": { + "labels": [ + "Red", + "Blue", + "Yellow" + ], + "datasets": [ + { + "data": [ + 300, + 50, + 100 + ], + "backgroundColor": [ + "#FF6384", + "#36A2EB", + "#FFCE56" + ], + "hoverBackgroundColor": [ + "#FF6384", + "#36A2EB", + "#FFCE56" + ] + } + ] + }, + "options": {} +} +``` +```` + +Which generates: + +```chart +{ + "type": "doughnut", + "data": { + "labels": [ + "Red", + "Blue", + "Yellow" + ], + "datasets": [ + { + "data": [ + 300, + 50, + 100 + ], + "backgroundColor": [ + "#FF6384", + "#36A2EB", + "#FFCE56" + ], + "hoverBackgroundColor": [ + "#FF6384", + "#36A2EB", + "#FFCE56" + ] + } + ] + }, + "options": {} +} +``` diff --git a/assets/js/copy_code.js b/assets/js/copy_code.js index 635ced1702a1..2d107f0bf1a5 100644 --- a/assets/js/copy_code.js +++ b/assets/js/copy_code.js @@ -1,7 +1,11 @@ // create element for copy button in code blocks var codeBlocks = document.querySelectorAll("pre"); codeBlocks.forEach(function (codeBlock) { - if ((codeBlock.querySelector("pre:not(.lineno)") || codeBlock.querySelector("code")) && codeBlock.querySelector("code:not(.language-mermaid)")) { + if ( + (codeBlock.querySelector("pre:not(.lineno)") || codeBlock.querySelector("code")) && + codeBlock.querySelector("code:not(.language-chart)") && + codeBlock.querySelector("code:not(.language-mermaid)") + ) { // create copy button var copyButton = document.createElement("button"); copyButton.className = "copy";