Skip to content

Commit a692569

Browse files
committed
bump quarto-ojs-runtime again, for better JSX support
1 parent 542dec1 commit a692569

File tree

2 files changed

+96
-13
lines changed

2 files changed

+96
-13
lines changed

src/resources/formats/html/ojs/quarto-ojs-runtime.js

Lines changed: 81 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @quarto/quarto-ojs-runtime v0.0.6 Copyright 2022 undefined
1+
// @quarto/quarto-ojs-runtime v0.0.7 Copyright 2022 undefined
22
var EOL = {},
33
EOF = {},
44
QUOTE = 34,
@@ -17821,37 +17821,107 @@ class OJSConnector {
1782117821
}
1782217822
}
1782317823

17824+
/*!
17825+
* escape-html
17826+
* Copyright(c) 2012-2013 TJ Holowaychuk
17827+
* Copyright(c) 2015 Andreas Lubbe
17828+
* Copyright(c) 2015 Tiancheng "Timothy" Gu
17829+
* Copyright(c) 2022 RStudio, PBC
17830+
*
17831+
* MIT Licensed
17832+
*
17833+
* Minimal changes to make ES6
17834+
*
17835+
*/
17836+
17837+
var matchHtmlRegExp = /["'&<>]/;
17838+
17839+
/**
17840+
* Escape special characters in the given string of text.
17841+
*
17842+
* @param {string} string The string to escape for inserting into HTML
17843+
* @return {string}
17844+
* @public
17845+
*/
17846+
17847+
function escapeHtml (string) {
17848+
var str = '' + string;
17849+
var match = matchHtmlRegExp.exec(str);
17850+
17851+
if (!match) {
17852+
return str
17853+
}
17854+
17855+
var escape;
17856+
var html = '';
17857+
var index = 0;
17858+
var lastIndex = 0;
17859+
17860+
for (index = match.index; index < str.length; index++) {
17861+
switch (str.charCodeAt(index)) {
17862+
case 34: // "
17863+
escape = '&quot;';
17864+
break
17865+
case 38: // &
17866+
escape = '&amp;';
17867+
break
17868+
case 39: // '
17869+
escape = '&#39;';
17870+
break
17871+
case 60: // <
17872+
escape = '&lt;';
17873+
break
17874+
case 62: // >
17875+
escape = '&gt;';
17876+
break
17877+
default:
17878+
continue
17879+
}
17880+
17881+
if (lastIndex !== index) {
17882+
html += str.substring(lastIndex, index);
17883+
}
17884+
17885+
lastIndex = index + 1;
17886+
html += escape;
17887+
}
17888+
17889+
return lastIndex !== index
17890+
? html + str.substring(lastIndex, index)
17891+
: html
17892+
}
17893+
1782417894
function createHtmlElement(tag, attrs, ...children) {
17825-
const el = document.createElement(tag); // we should try to play nice with svg etc a la d3
17895+
const el = document.createElement(tag);
1782617896
for (const [key, val] of Object.entries(attrs || {})) {
1782717897
el.setAttribute(key, val);
1782817898
}
1782917899
while (children.length) {
1783017900
const child = children.shift();
1783117901
if (Array.isArray(child)) {
1783217902
children.unshift(...child);
17833-
} else if (typeof child === "string") {
17834-
el.appendChild(document.createTextNode(child));
17835-
} else {
17903+
} else if (child instanceof HTMLElement) {
1783617904
el.appendChild(child);
17905+
} else {
17906+
el.appendChild(document.createTextNode(escapeHtml(child)));
1783717907
}
1783817908
}
1783917909
return el;
1784017910
}
1784117911

1784217912
function createNamespacedElement(ns, tag, attrs, ...children) {
17843-
const el = document.createElementNS(ns, tag); // we should try to play nice with svg etc a la d3
17913+
const el = document.createElementNS(ns.namespace, tag);
1784417914
for (const [key, val] of Object.entries(attrs || {})) {
1784517915
el.setAttribute(key, val);
1784617916
}
1784717917
while (children.length) {
1784817918
const child = children.shift();
1784917919
if (Array.isArray(child)) {
1785017920
children.unshift(...child);
17851-
} else if (typeof child === "string") {
17852-
el.appendChild(document.createTextNode(child));
17853-
} else {
17921+
} else if (child instanceof HTMLElement || child instanceof ns.class) {
1785417922
el.appendChild(child);
17923+
} else {
17924+
el.appendChild(document.createTextNode(escapeHtml(child)));
1785517925
}
1785617926
}
1785717927
return el;
@@ -17925,7 +17995,7 @@ const resolver = {
1792517995
};
1792617996

1792717997
const nss = {
17928-
"svg": "http://www.w3.org/2000/svg"
17998+
"svg": { namespace: "http://www.w3.org/2000/svg", class: SVGElement }
1792917999
};
1793018000

1793118001
function resolveCreator(tag) {
@@ -17936,7 +18006,7 @@ function resolveCreator(tag) {
1793618006
const namespace = nss[nsKey];
1793718007

1793818008
return function(tag, attrs, ...children) {
17939-
return createNamespacedElement(namespace, tag, attrs, children);
18009+
return createNamespacedElement(namespace, tag, attrs, ...children);
1794018010
}
1794118011
}
1794218012

src/resources/formats/html/ojs/quarto-ojs-runtime.min.js

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)