Revert to internal option

pull/21833/head
J. Ryan Stinnett 2021-05-10 17:36:33 +01:00
parent 9c8e89ff79
commit 7821e00bc6
3 changed files with 15 additions and 9 deletions

View File

@ -75,7 +75,6 @@
"glob-to-regexp": "^0.4.1",
"highlight.js": "^10.5.0",
"html-entities": "^1.4.0",
"htmlparser2": "^6.1.0",
"is-ip": "^3.1.0",
"katex": "^0.12.0",
"linkifyjs": "^2.1.9",

View File

@ -31,7 +31,6 @@ import katex from 'katex';
import { AllHtmlEntities } from 'html-entities';
import SettingsStore from './settings/SettingsStore';
import cheerio from 'cheerio';
import * as htmlparser2 from 'htmlparser2';
import {tryTransformPermalinkToLocalHref} from "./utils/permalinks/Permalinks";
import {SHORTCODE_TO_EMOJI, getEmojiFromUnicode} from "./emoji";
@ -423,9 +422,12 @@ export function bodyToHtml(content: IContent, highlights: string[], opts: IOpts
safeBody = sanitizeHtml(formattedBody, sanitizeParams);
if (SettingsStore.getValue("feature_latex_maths")) {
const phtml = cheerio.load(htmlparser2.parseDocument(safeBody, {
const phtml = cheerio.load(safeBody, {
// @ts-ignore: The `_useHtmlParser2` internal option is the
// simplest way to both parse and render using `htmlparser2`.
_useHtmlParser2: true,
decodeEntities: false,
}));
});
// @ts-ignore - The types for `replaceWith` wrongly expect
// Cheerio instance to be returned.
phtml('div, span[data-mx-maths!=""]').replaceWith(function(i, e) {

View File

@ -22,7 +22,6 @@ import { AllHtmlEntities } from 'html-entities';
import SettingsStore from '../settings/SettingsStore';
import SdkConfig from '../SdkConfig';
import cheerio from 'cheerio';
import * as htmlparser2 from 'htmlparser2';
export function mdSerialize(model: EditorModel) {
return model.parts.reduce((html, part) => {
@ -117,16 +116,22 @@ export function htmlSerializeIfNeeded(model: EditorModel, {forceHTML = false} =
const parser = new Markdown(md);
if (!parser.isPlainText() || forceHTML) {
// feed Markdown output to HTML parser
const phtml = cheerio.load(htmlparser2.parseDocument(parser.toHTML(), {
const phtml = cheerio.load(parser.toHTML(), {
// @ts-ignore: The `_useHtmlParser2` internal option is the
// simplest way to both parse and render using `htmlparser2`.
_useHtmlParser2: true,
decodeEntities: false,
}));
});
if (SettingsStore.getValue("feature_latex_maths")) {
// original Markdown without LaTeX replacements
const parserOrig = new Markdown(orig);
const phtmlOrig = cheerio.load(htmlparser2.parseDocument(parserOrig.toHTML(), {
const phtmlOrig = cheerio.load(parserOrig.toHTML(), {
// @ts-ignore: The `_useHtmlParser2` internal option is the
// simplest way to both parse and render using `htmlparser2`.
_useHtmlParser2: true,
decodeEntities: false,
}));
});
// since maths delimiters are handled before Markdown,
// code blocks could contain mangled content.