mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Automatic code highlighting not applied in fullscreen modal (#26710)
This commit is contained in:
parent
dde1132a28
commit
c3fb050988
@ -35,7 +35,7 @@ export default async function highlightSyntax(elem, siteSettings, session) {
|
|||||||
|
|
||||||
let lang;
|
let lang;
|
||||||
for (const className of e.classList) {
|
for (const className of e.classList) {
|
||||||
const m = className.match(/^lang-(.+)$/);
|
const m = className.match(/^lang(?:uage)?-(.+)$/);
|
||||||
if (m) {
|
if (m) {
|
||||||
lang = m[1];
|
lang = m[1];
|
||||||
break;
|
break;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { render } from "@ember/test-helpers";
|
import { render } from "@ember/test-helpers";
|
||||||
import { hbs } from "ember-cli-htmlbars";
|
import { hbs } from "ember-cli-htmlbars";
|
||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
|
import highlightSyntax from "discourse/lib/highlight-syntax";
|
||||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
||||||
import { query } from "discourse/tests/helpers/qunit-helpers";
|
import { query } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
@ -27,4 +28,34 @@ module("Integration | Component | highlighted-code", function (hooks) {
|
|||||||
|
|
||||||
assert.strictEqual(query("code").innerText.trim(), LONG_CODE_BLOCK.trim());
|
assert.strictEqual(query("code").innerText.trim(), LONG_CODE_BLOCK.trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("highlighting code with lang=auto", async function (assert) {
|
||||||
|
this.set("code", "def test; end");
|
||||||
|
|
||||||
|
await render(hbs`<HighlightedCode @lang="auto" @code={{this.code}} />`);
|
||||||
|
|
||||||
|
const codeElement = query("code.hljs");
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
codeElement.classList.contains("lang-auto"),
|
||||||
|
"lang-auto is removed"
|
||||||
|
);
|
||||||
|
assert.ok(
|
||||||
|
Array.from(codeElement.classList).some((className) => {
|
||||||
|
return className.startsWith("language-");
|
||||||
|
}),
|
||||||
|
"language is detected"
|
||||||
|
);
|
||||||
|
|
||||||
|
await highlightSyntax(
|
||||||
|
codeElement.parentElement, // <pre>
|
||||||
|
this.siteSettings,
|
||||||
|
this.session
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
codeElement.dataset.unknownHljsLang,
|
||||||
|
"language is found from language- class"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user