Skip to content

Commit

Permalink
add HighlightJS
Browse files Browse the repository at this point in the history
  • Loading branch information
skywalker512 committed Jul 8, 2018
1 parent 082eea4 commit 5f0c3fd
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 0 deletions.
5 changes: 5 additions & 0 deletions addons/languages/Chinese/definitions.HighlightJS.php
@@ -0,0 +1,5 @@
<?php

$definitions["Enter a custom stylesheet for HighlightJS. (e.g. 'androidstudio' without the quotes)"] = "请键入高亮风格 (例如 'androidstudio' 请不要输入引号)";
$definitions["Do not input the extensions .min.css at the end. Just enter the name."] = "请不要输入后缀 .min.css";
$definitions["If no custom stylesheet is specified, the default will be used."] = "如果留空将会使用 default";
22 changes: 22 additions & 0 deletions addons/plugins/HighlightJS/LICENSE
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Andrew Bagshaw

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Binary file added addons/plugins/HighlightJS/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
57 changes: 57 additions & 0 deletions addons/plugins/HighlightJS/plugin.php
@@ -0,0 +1,57 @@
<?php
// Copyright 2015 Andrew Bagshaw
if (!defined("IN_ESOTALK")) exit;

ET::$pluginInfo["HighlightJS"] = array(
"name" => "代码高亮",
"description" => "添加编辑器代码高亮支持",
"version" => "0.1",
"author" => "Andrew Bagshaw",
"authorEmail" => "",
"authorURL" => "",
"license" => "MIT"
);

class ETPlugin_HighlightJS extends ETPlugin{

public function handler_conversationController_init($sender){
$HighlightJS = C('plugin.HighlightJS.customstyle');

if($HighlightJS)
$CustomHighlightCSS= "<link rel=\"stylesheet\" href=\"//cdn.bootcss.com/highlight.js/9.12.0/styles/".$HighlightJS.".min.css\">";
else
$CustomHighlightCSS= "<link rel=\"stylesheet\" href=\"//cdn.bootcss.com/highlight.js/9.12.0/styles/default.min.css\">";

$JSHeader = "<script src=\"//cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js\"></script>";

$codeToRun = "<script type=\"text/javascript\">$(document).ready(function() { $('pre').each(function(i, block) { hljs.highlightBlock(block); });});</script>";

$sender->addToHead($CustomHighlightCSS);
$sender->addToHead($JSHeader);
$sender->addJSFile($this->resource("highlightactions.js"));
}
public function handler_conversationController_editPostAfter($sender)
{

}

public function settings($sender){
$form = ETFactory::make('form');
$form->action = URL('admin/plugins/settings/HighlightJS');
$form->setValue("customstyle", C("plugin.HighlightJS.customstyle"));

if ($form->validPostBack('HighlightJSSave')){
$config = array();
$config['plugin.HighlightJS.customstyle'] = trim($form->getValue('customstyle'));

ET::writeConfig($config);

$sender->message(T('message.changesSaved'), 'success autoDismiss');
$sender->redirect(URL('admin/plugins'));
}

$sender->data('HighlightJSForm', $form);
return $this->View('settings');
}

}
24 changes: 24 additions & 0 deletions addons/plugins/HighlightJS/readme.md
@@ -0,0 +1,24 @@
## esoTalk HighlightJS Plugin

Easily add code highlighting to conversations.

### Installing the HighlightJS Plugin
---------------------------------------
1. [Download](https://github.com/abagshaw/esoTalk-HighlightJS/archive/master.zip)
2. Extract archive and rename folder to 'HighlightJS' without quotes
3. Upload folder to the plugins folder /addons/plugins
4. Enable plugin in admin panel

#### Changing HighlightJS Style
---------------------------------------
By default the plugin will use the default stylesheet for HighlightJS

To change the stylesheet used follow these steps:

1. Find the stylesheet you want at the highlight.js [demo page](https://highlightjs.org/static/demo/)
2. On the plugin admin panel click 'settings' beside 'HighlightJS Script'
3. Enter the name of the new stylesheet in the form. **NOTE: The name must be lowercase and must not include the .min.css at the end.

If you are unsure of the name for the stylesheet you want, or the name you entered results in no code highlighting, please check with the highlight.js repository


23 changes: 23 additions & 0 deletions addons/plugins/HighlightJS/resources/highlightactions.js
@@ -0,0 +1,23 @@
$(function() {
function activateHighlights() {
$('pre').each(function(i, block) {
hljs.highlightBlock(block);
});
}
var initPost = ETConversation.initPost;
ETConversation.initPost = function(postId, html) {
initPost(postId, html);
activateHighlights();
};

var restorePost = ETConversation.restorePost;
ETConversation.restorePost = function(postId) {
var redisplayAvatars = ETConversation.redisplayAvatars;
ETConversation.redisplayAvatars = function() {
redisplayAvatars();
activateHighlights();
ETConversation.redisplayAvatars = redisplayAvatars;
};
restorePost(postId);
};
});
22 changes: 22 additions & 0 deletions addons/plugins/HighlightJS/views/settings.php
@@ -0,0 +1,22 @@
<?php
// Copyright 2015 Andrew Bagshaw
if (!defined("IN_ESOTALK")) exit;

$form = $data["HighlightJSForm"];
?>
<?php echo $form->open(); ?>
<div class="section">
<ul class="form">
<li>
<label>自定风格</label>
<?php echo $form->input('customstyle', 'text'); ?>
<small><?php echo T("Enter a custom stylesheet for HighlightJS. (e.g. 'androidstudio' without the quotes)"); ?></small>
<small><?php echo T("Do not input the extensions .min.css at the end. Just enter the name."); ?></small>
<small><?php echo T("If no custom stylesheet is specified, the default will be used."); ?></small>
<li>
</ul>
</div>
<div class="buttons">
<?php echo $form->saveButton("HighlightJSSave"); ?>
</div>
<?php echo $form->close(); ?>

0 comments on commit 5f0c3fd

Please sign in to comment.