forked from GATEOverflow/mathjax
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathqa-formatter-layer.php
More file actions
69 lines (64 loc) · 2.65 KB
/
qa-formatter-layer.php
File metadata and controls
69 lines (64 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
class qa_html_theme_layer extends qa_html_theme_base
{
function get_pf_version()
{
return '1.1';
}
function getPreviewString()
{
$preview = 'document.addEventListener("DOMContentLoaded", function (f){
if("undefined"!=typeof CKEDITOR&&null!=CKEDITOR)
{
CKEDITOR.on("instanceLoaded", function(e){
var m=document.createElement("div");
m.setAttribute("id","qa-cke-prev");
document.querySelector(".cke").parentNode.appendChild(m);
e.editor.on("change",function(){
var x=document.getElementById("qa-cke-prev");
x.innerHTML=e.editor.getData();';
if (qa_opt('qa-mathjax-enable')) {
$preview .= 'MathJax.Hub.Queue([\'Typeset\', MathJax.Hub, "qa-cke-prev"]);';
}
if (qa_opt('qa-prettify-enable')) {
$preview .= 'x.querySelectorAll(\'pre code\').forEach((block) => { hljs.highlightBlock(block); });';
}
$preview .= '});m.innerHTML=e.editor.getData(true);';
if (qa_opt('qa-mathjax-enable')) {
$preview .= 'MathJax.Hub.Queue([\'Typeset\', MathJax.Hub, "qa-cke-prev"]);';
}
if (qa_opt('qa-prettify-enable')) {
$preview .= 'm.querySelectorAll(\'pre code\').forEach((block) => { hljs.highlightBlock(block); });';
}
$preview .= '});}});';
return $preview;
}
function body_suffix()
{
qa_html_theme_base::body_suffix();
{
if (qa_opt("qa-mathjax-enable") && qa_opt('qa-mathjax-config') && qa_opt('qa-mathjax-url')) {
$this->output('<script type="text/x-mathjax-config">' . qa_opt('qa-mathjax-config') . '</script>');
$this->output('<script async type="text/javascript" src="' . qa_opt('qa-mathjax-url') . '"></script>');
}
if (qa_opt("qa-ckepreview-enable")) {
$this->output('<script type="text/javascript">' . $this->getPreviewString() . '</script>');
}
}
}
function head_custom()
{
qa_html_theme_base::head_custom();
if (qa_opt("qa-prettify-enable")) {
$this->output('<link rel="stylesheet" href="' . qa_opt('qa-formatter-css') . '">');
$this->output('<script type="text/javascript" src="' . qa_opt('qa-prettify-url') . '"></script>');
$this->output('<script>hljs.initHighlightingOnLoad();</script>');
}
if (qa_opt("qa-ckepreview-enable")) {
$this->output('<style type="text/css">
#qa-cke-prev{border-top:2px dashed #def; border-bottom:2px dashed #def; padding-top:10px; margin-top:10px; }
</style>');
}
}
}
?>