// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. // import "preact/debug"; // Include this line only when debugging rendering import "./kataViewer.css"; import { render } from "preact"; import { useEffect } from "preact/hooks"; // This viewer uses the html version of the katas bundle and MathJax, as quantum.microsoft.com does import { Exercise, ExplainedSolutionItem, Kata, Lesson, getAllKatas, } from "qsharp-lang/katas"; import { ensureTheme, detectThemeChange, updateStyleSheetTheme, } from "qsharp-lang/ux"; declare global { // The below are added by the MathJax and Highlight.js scripts interface Window { MathJax: any; hljs: any; } } window.MathJax = { loader: { load: ["[tex]/color", "[tex]/braket"], }, tex: { packages: { "[+]": ["color", "braket"] }, inlineMath: [ ["$", "$"], ["\\(", "\\)"], ], formatError: (jax: any, err: any) => { console.log("LaTeX processing error occurred. ", err, jax); const errorNode = document.createElement("div"); errorNode.innerText = `LaTeX processing error: ${err.message}.\nLaTeX: ${jax.latex}\n\n`; errorNode.style.fontSize = "20px"; errorNode.style.color = "red"; document.querySelector("#errors")?.appendChild(errorNode); window.scroll(0, 0); jax.formatError(err); }, }, startup: { pageReady: async () => { await onload(); return window.MathJax.startup.defaultPageReady(); }, }, }; function Nav(props: { katas: Kata[]; onnav: (index: number) => void; selected: number; }) { return (
); } function KataEl(props: { kata: Kata }) { useEffect(() => { window.hljs.highlightAll(); window.MathJax.texReset(); window.MathJax.typesetClear(); window.MathJax.typesetPromise([".content"]); }, [props.kata.id]); window.scrollTo(0, 0); return (
{item.code}
);
}
})}
>
);
}
function ExerciseEl(props: { exercise: Exercise }) {
const item = props.exercise;
return (
<>
{item.placeholderCode}
{item.code}
)}