only allow code tags inside math tag

This commit is contained in:
Aleks Kissinger 2020-10-10 09:12:53 +01:00
parent 65c4460abc
commit 919a1a8125

View file

@ -18,14 +18,21 @@ import commonmark from 'commonmark';
import {escape} from "lodash";
import SdkConfig from './SdkConfig';
const ALLOWED_HTML_TAGS = ['sub', 'sup', 'del', 'u', 'code'];
const ALLOWED_HTML_TAGS = ['sub', 'sup', 'del', 'u'];
// These types of node are definitely text
const TEXT_NODES = ['text', 'softbreak', 'linebreak', 'paragraph', 'document'];
function is_math_node(node) {
return node != null &&
node.literal != null &&
node.literal.match(/^<((div|span) data-mx-maths="[^"]*"|\/(div|span))>$/) != null;
}
function is_allowed_html_tag(node) {
if (SdkConfig.get()['latex_maths'] &&
node.literal.match(/^<\/?(div|span)( data-mx-maths="[^"]*")?>$/) != null) {
(is_math_node(node) ||
(node.literal.match(/^<\/?code>$/) && is_math_node(node.parent)))) {
return true;
}