-
Notifications
You must be signed in to change notification settings - Fork 3
/
Plugin.php
90 lines (84 loc) · 3.2 KB
/
Plugin.php
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* KaTeX for Typecho
*
* @package KaTeX4Typecho
* @author vc12345679
* @version 0.0.1
* @link https://blog.chensiwei.net.cn/archives/6.html
*/
class KaTeX4Typecho_Plugin implements Typecho_Plugin_Interface {
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate() {
Typecho_Plugin::factory('Widget_Archive')->header = array('KaTeX4Typecho_Plugin', 'header');
Typecho_Plugin::factory('Widget_Archive')->footer = array('KaTeX4Typecho_Plugin', 'footer');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate() {
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form) {
$delimiter = new Typecho_Widget_Helper_Form_Element_Text('delimiter', NULL, _t('{left: "$$", right: "$$", display: false},{left: "\\\\[", right: "\\\\]", display: true}'), _t('公式标识符 Delimiters for equations:'), _t('输入识别公式所用的标识符,每个{}内为一组,left 后为左标识符,right 后为右标识符,display 后 true 表示段落模式,false 表示行内模式。Input the DELIMITERS for recognizing equations. Each {} for a set. "left" means left delimiter. "right" means right delimiter. In "display", "true" means standalone mode; “false” means inline mode.'));
$form->addInput($delimiter);
$ignoredtag = new Typecho_Widget_Helper_Form_Element_Text('ignoredtag', NULL, _t('"script", "noscript", "style", "textarea", "pre", "code"'), _t('忽略的标签 Ignored Tags:'), _t('输入禁止公式渲染的标签。Input the IGNORED TAGS for KaTeX rendering.'));
$form->addInput($ignoredtag);
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form) {
}
/**
* 输出头部js和css
*
* @access public
* @param unknown $header
* @return void
*/
public static function header() {
$settings = Helper::options()->plugin('KaTeX4Typecho');
echo<<<EOF
<script type="text/javascript" src="https://cdn.bootcss.com/KaTeX/0.6.0/katex.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/KaTeX/0.6.0/katex.min.css" />
<script type="text/javascript" src="https://cdn.bootcss.com/KaTeX/0.6.0/contrib/auto-render.min.js"></script>
EOF;
}
/**
* 输出尾部js
*
* @access public
* @param unknown $footer
* @return void
*/
public static function footer() {
$settings = Helper::options()->plugin('KaTeX4Typecho');
echo '<script type="text/javascript">renderMathInElement(document.body,{delimiters:[';
echo $settings->delimiter;
echo '],ignoredTags:[';
echo $settings->ignoredtag;
echo ']});</script>';
}
}