Files
KaTeX/test/screenshotter/test.html
Erik Demaine 3800dc49c1 [breaking] trust setting to indicate whether input text is trusted (#1794)
* trust option to indicate whether input text is trusted

* Revamp into trust contexts beyond just command

* Document new trust function style

* Fix screenshot testing

* Use trust setting in \url and \href

* Check `isTrusted` in `\url` and `\href` (so now disabled by default)
* Automatically compute `protocol` from `url` in `isTrusted`, so it
  doesn't need to be passed into every context.

* Document untrusted features in support list/table

* Existing tests trust by default

* remove allowedProtocols and fix flow errors

* remove 'allowedProtocols' from documentation

* add a comment about a flow error, rename urlToProtocol to protocolFromUrl

* add tests test that use function version of trust option

* default trust to false in MathML tests

* fix test title, remove 'trust: false' from test settings since it's the default
2019-07-08 21:57:23 -04:00

95 lines
2.9 KiB
HTML

<!doctype html>
<html>
<head>
<title>Screenshotter test</title>
<script src="../../katex.js" type="text/javascript"></script>
<style type="text/css">
#math, #pre, #post {
font-size: 4em;
}
body {
font-family: "DejaVu Serif",serif;
}
@font-face {
font-family: "Mincho";
src: url("/submodules/katex-test-fonts/mincho/font_1_honokamin.ttf") format("truetype");
}
@font-face {
font-family: "Batang";
src: url("/submodules/katex-test-fonts/batang/batang.ttf") format("truetype");
}
.katex .cjk_fallback {
font-family: "Mincho",serif;
}
.katex .hangul_fallback {
font-family: "Batang",serif;
}
</style>
</head>
<body>
<span id="pre"></span>
<span id="math"></span>
<span id="post"></span>
<script type="text/javascript">
function load_fonts(callback) {
if (!document.fonts || !document.fonts.load) {
callback();
return;
}
var results = [];
function load_font(name, style) {
// 10px is arbitrarily selected value
results.push(document.fonts.load((style || "") + " 10px " + name));
}
var fonts = {AMS:1,Caligraphic:3,Fraktur:3,Main:15,Math:12,Script:1,
SansSerif:7,Size1:1,Size2:1,Size3:1,Size4:1,Typewriter:1}; // see below
for (var f in fonts) {
var ff = fonts[f];
var name = "KaTeX_" + f;
if (ff & 1) load_font(name);
if (ff & 2) load_font(name, "bold");
if (ff & 4) load_font(name, "italic");
if (ff & 8) load_font(name, "bold italic");
}
load_font("Mincho");
load_font("Batang");
Promise.all(results).then(callback)
}
function handle_search_string(search) {
var query = {};
var re = /(?:^\?|&)([^&=]+)(?:=([^&]+))?/g;
var match;
while (match = re.exec(search)) {
query[match[1]] = decodeURIComponent(match[2]);
}
var mathNode = document.getElementById("math");
var settings = {
displayMode: !!query["display"],
throwOnError: !query["noThrow"],
trust: true // trust test inputs
};
if (query["errorColor"]) {
settings.errorColor = query["errorColor"];
}
var macros = {};
var macroRegex = /(?:^\?|&)(?:\\|%5[Cc])([A-Za-z]+)=([^&]*)/g;
while ((match = macroRegex.exec(search)) !== null) {
settings.macros = macros;
macros["\\" + match[1]] = decodeURIComponent(match[2]);
}
mathNode.setAttribute("style", query["styles"] || "");
katex.render(query["tex"], mathNode, settings);
document.getElementById("pre").innerHTML = query["pre"] || "";
document.getElementById("post").innerHTML = query["post"] || "";
}
handle_search_string(window.location.search);
</script>
</body>
</html>