From 7c3892302e6d5f5a50a153265dc0331235dd3c50 Mon Sep 17 00:00:00 2001 From: mutoo Date: Thu, 12 Dec 2013 11:34:39 +0800 Subject: [PATCH] upgrade LaTex Plugin: customize ```mark enabled --- GoogleAnalytics/Plugin.php | 2 +- LaTex/Plugin.php | 9 +++++++-- LaTex/latex.js | 40 ++++++++++++++++++++++++++------------ ZenCoding/zen_textarea.js | 2 +- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/GoogleAnalytics/Plugin.php b/GoogleAnalytics/Plugin.php index e52556f..a5da974 100644 --- a/GoogleAnalytics/Plugin.php +++ b/GoogleAnalytics/Plugin.php @@ -41,7 +41,7 @@ class GoogleAnalytics_Plugin implements Typecho_Plugin_Interface public static function config(Typecho_Widget_Helper_Form $form) { /** 分类名称 */ - $account = new Typecho_Widget_Helper_Form_Element_Text('account', NULL, 'UA-XXXXXXX-X', _t('Google Analytics 帐号')); + $account = new Typecho_Widget_Helper_Form_Element_Text('account', NULL, 'UA-XXXXXXX-X', _t('Google Analytics 帐号'), _t('此帐号可在 GA 管理平台查询;格式为 UA-XXXXXXX-X 。')); $form->addInput($account); } diff --git a/LaTex/Plugin.php b/LaTex/Plugin.php index 961d832..0170ed7 100644 --- a/LaTex/Plugin.php +++ b/LaTex/Plugin.php @@ -4,7 +4,7 @@ * * @package LaTex * @author mutoo - * @version 1.0.0 + * @version 1.1.0 * @link http://blog.mutoo.im/LaTex.html */ class LaTex_Plugin implements Typecho_Plugin_Interface @@ -39,7 +39,10 @@ class LaTex_Plugin implements Typecho_Plugin_Interface * @param Typecho_Widget_Helper_Form $form 配置面板 * @return void */ - public static function config(Typecho_Widget_Helper_Form $form){} + public static function config(Typecho_Widget_Helper_Form $form){ + $mark = new Typecho_Widget_Helper_Form_Element_Text('mark', NULL, 'latex', _t('自定义标记'), _t('在 Markdown 语法环境下使用以下代码进行公式转换:
```自定义标记
公式
```
')); + $form->addInput($mark); + } /** * 个人用户的配置面板 @@ -60,5 +63,7 @@ class LaTex_Plugin implements Typecho_Plugin_Interface public static function footer() { $jsUrl = Helper::options()->pluginUrl . '/LaTex/latex.js'; echo ''; + $mark = Typecho_Widget::widget('Widget_Options')->plugin('LaTex')->mark; + echo ''; } } diff --git a/LaTex/latex.js b/LaTex/latex.js index a9ecf44..79b227d 100644 --- a/LaTex/latex.js +++ b/LaTex/latex.js @@ -1,13 +1,29 @@ -(function() { - var $ = document.querySelectorAll.bind(document); - var latex = $('code.lang-LaTex, code.lang-latex, code.lang-tex'); - for (var i = 0, l = latex.length; i < l; i++) { - var node = latex[i]; - var latex_image = document.createElement("img"); - latex_image.src = "http://latex.codecogs.com/png.latex?"+ node.innerHTML; - // replace with image - var parent = node.parentNode; - parent.insertBefore(latex_image, node); - parent.removeChild(node); +(function(global) { + var previousLatex = global.latex; + + global.latex = { + parse: function(mark) { + if (!mark) { + return; + } + + var $ = document.querySelectorAll.bind(document); + var nodes = $('code.lang-' + mark); + for (var i = 0, l = nodes.length; i < l; i++) { + var node = nodes[i]; + var latex_image = document.createElement("img"); + latex_image.src = "http://latex.codecogs.com/png.latex?" + node.innerHTML; + // replace with image + var parent = node.parentNode; + parent.insertBefore(latex_image, node); + parent.removeChild(node); + } + + }, + noConflict: function() { + global.latex = previousLatex; + return this; + } } -})(); \ No newline at end of file + +})(this); \ No newline at end of file diff --git a/ZenCoding/zen_textarea.js b/ZenCoding/zen_textarea.js index 737ce80..95b99d0 100644 --- a/ZenCoding/zen_textarea.js +++ b/ZenCoding/zen_textarea.js @@ -2250,7 +2250,7 @@ var zen_editor = (function(){ * @include "editor.js" * @include "../../aptana/lib/html_matcher.js" * @include "../../aptana/lib/zen_coding.js" - */ + */ /** * Search for abbreviation in editor from current caret position