Skip to content

Commit e38f987

Browse files
committed
fix(pat-clone-code): Fix a Content-Security-Policy problem.
Do not use dom.template for the wrapper template to not get caught by the browser's Content-Security-Policy. If set, a unsafe-eval error would be thrown and the pattern refuse to run.
1 parent 78c544b commit e38f987

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/pat/clone-code/clone-code.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { BasePattern } from "../../core/basepattern";
2-
import code_wrapper_template from "./templates/code-wrapper.html";
3-
import dom from "../../core/dom";
42
import Parser from "../../core/parser";
53
import registry from "../../core/registry";
64
import utils from "../../core/utils";
@@ -63,17 +61,24 @@ class Pattern extends BasePattern {
6361
});
6462
}
6563

66-
markup = utils.escape_html(markup);
67-
const pre_code_markup = dom.template(code_wrapper_template, { markup: markup });
68-
6964
// Now we need to wrap the contents in any case in a div.
7065
tmp_wrapper = document.createElement("div");
71-
tmp_wrapper.innerHTML = pre_code_markup;
66+
tmp_wrapper.innerHTML = this.wrapper_template(utils.escape_html(markup));
7267
const pre_code_el = tmp_wrapper.children[0];
7368

7469
this.el.appendChild(pre_code_el);
7570
registry.scan(pre_code_el);
7671
}
72+
73+
wrapper_template(markup) {
74+
return `
75+
<pre class="pat-syntax-highlight">
76+
<code class="language-html">
77+
${markup}
78+
</code>
79+
</pre>
80+
`;
81+
}
7782
}
7883

7984
registry.register(Pattern);

src/pat/clone-code/templates/code-wrapper.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)