发布issue编辑器可以上传代码并高亮显示了

This commit is contained in:
lizanle 2015-09-10 15:45:08 +08:00
parent f892beebc1
commit 756aae0cf2
8 changed files with 1824 additions and 12 deletions

View File

@ -1,4 +1,5 @@
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'prettify','/assets/kindeditor/pasteimg' %>
<%= stylesheet_link_tag 'prettify'%>
<%= labelled_form_for @bid,:html => { :multipart => true } do |f| %>
<%= render :partial => 'new_homework_form', :locals => { :bid => @bid, :bid_id => "edit_bid_#{@bid.id}",:f=>f,:edit_mode => true} %>
<% end %>

View File

@ -12,8 +12,8 @@
<%= favicon %>
<%= javascript_heads %>
<%= heads_for_theme %>
<%= stylesheet_link_tag 'public', 'pleft', 'project','jquery/jquery-ui-1.9.2','header' %>
<%= javascript_include_tag 'cookie','project', 'header','select_list_move' %>
<%= stylesheet_link_tag 'public', 'pleft', 'project','prettify','jquery/jquery-ui-1.9.2','header' %>
<%= javascript_include_tag 'cookie','project', 'header','prettify','select_list_move' %>
<%= call_hook :view_layouts_base_html_head %>
<!-- page specific tags -->
<%= yield :header_tags -%>
@ -21,7 +21,7 @@
</head>
<!--add by huang-->
<body>
<body onload=" ">
<div class="navContainer mb10">
<% if User.current.logged? %>
<%= render :partial => 'layouts/logined_header' %>

View File

@ -9,7 +9,8 @@ module RailsKindeditor
output << text_area_tag(name, content, input_html)
output << javascript_tag(js_replace(id, options.merge(window_onload: 'true',
:autoHeightMode=>true,
afterCreate: 'eval(function(){enablePasteImg(self);this.loadPlugin("autoheight")})')))
afterCreate: 'eval(function(){enablePasteImg(self);this.loadPlugin("autoheight")})'
)))
end
def kindeditor(name, method, options = {})
@ -20,7 +21,8 @@ module RailsKindeditor
output_buffer << build_text_area_tag(name, method, self, options, input_html)
output_buffer << javascript_tag(js_replace(input_html['id'],options.merge(window_onload: 'true',
:autoHeightMode=>true,
afterCreate: 'eval(function(){enablePasteImg(self);this.loadPlugin("autoheight")})')))
afterCreate: 'eval(function(){enablePasteImg(self);this.loadPlugin("autoheight")})'
)))
end
def kindeditor_upload_json_path(*args)

View File

@ -258,13 +258,13 @@ K.options = {
fullscreenShortcut : false,
bodyClass : 'ke-content',
indentChar : '\t',
cssPath : '',
cssPath : K.basePath +'plugins/code/previewcode.css',
cssData : '',
minWidth : 650,
minHeight : 100,
minChangeSize : 50,
zIndex : 811213,
items : [ 'emoticons',
items : ['code', 'emoticons',
'source','plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', '|',
'formatblock', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
'italic', 'underline', 'removeformat', '|','imagedirectupload','table', 'media',"more"
@ -4986,7 +4986,7 @@ KEditor.prototype = {
htmlList.unshift('<div style="display:block" id="define"/>')
htmlList.push('</div>')
var htmlListFull = [];
var fullItems = [
var fullItems = ['code',
'emoticons',
'source','plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', '|',
'formatblock', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
@ -5069,6 +5069,7 @@ KEditor.prototype = {
}
self.updateState();
self.addBookmark();
prettyPrint("",self.edit.doc.body);
if (self.options.afterChange) {
self.options.afterChange.call(self);
}
@ -5550,6 +5551,7 @@ _plugin('core', function(K) {
self.afterSetHtml(function() {
if (self.options.afterChange) {
self.options.afterChange.call(self);
}
});
self.afterCreate(function() {

View File

@ -23,10 +23,9 @@ KindEditor.plugin('code', function(K) {
'<option value="php">PHP</option>',
'<option value="pl">Perl</option>',
'<option value="py">Python</option>',
'<option value="rb">Ruby</option>',
'<option value="java">Java</option>',
'<option value="vb">ASP/VB</option>',
'<option value="cpp">C/C++</option>',
'<option value="c">C/C++</option>',
'<option value="cs">C#</option>',
'<option value="xml">XML</option>',
'<option value="bsh">Shell</option>',
@ -46,7 +45,7 @@ KindEditor.plugin('code', function(K) {
var type = K('.ke-code-type', dialog.div).val(),
code = textarea.val(),
cls = type === '' ? '' : ' lang-' + type,
html = '<pre class="prettyprint' + cls + '">\n' + K.escape(code) + '</pre> ';
html = '<pre class="prettyprint linenums ' + cls + '">\n' + K.escape(code) + '</pre> ';
if (K.trim(code) === '') {
alert(lang.pleaseInput);
textarea[0].focus();

View File

@ -0,0 +1,76 @@
/* Pretty printing styles. Used with prettify.js. */
/* SPAN elements with the classes below are added by prettyprint. */
.pln { color: #000 } /* plain text */
@media screen {
.str { color: #080 } /* string content */
.kwd { color: #008 } /* a keyword */
.com { color: #800 } /* a comment */
.typ { color: #606 } /* a type name */
.lit { color: #066 } /* a literal value */
/* punctuation, lisp open bracket, lisp close bracket */
.pun, .opn, .clo { color: #660 }
.tag { color: #008 } /* a markup tag name */
.atn { color: #606 } /* a markup attribute name */
.atv { color: #080 } /* a markup attribute value */
.dec, .var { color: #606 } /* a declaration; a variable name */
.fun { color: red } /* a function name */
}
/* Use higher contrast and text-weight for printable form. */
@media print, projection {
.str { color: #060 }
.kwd { color: #006; font-weight: bold }
.com { color: #600; font-style: italic }
.typ { color: #404; font-weight: bold }
.lit { color: #044 }
.pun, .opn, .clo { color: #440 }
.tag { color: #006; font-weight: bold }
.atn { color: #404 }
.atv { color: #060 }
}
/* Put a border around prettyprinted code snippets. */
pre.prettyprint { padding: 2px;
border-left:1px solid #ccc;
border-bottom: 1px solid #ccc;
border-right: 1px solid #ccc,
border-top: 1px solid #ccc }
pre li,ul,ol {
list-style-type: none;
}
/* Specify class=linenums on a pre to get line numbering */
ol.linenums { margin-top: 0; margin-bottom: 0 } /* IE indents via margin-left */
li.L0,
li.L1,
li.L2,
li.L3,
li.L5,
li.L6,
li.L7,
li.L8 { list-style-type: none }
/* Alternate shading for lines */
li.L1,
li.L3,
li.L5,
li.L7,
li.L9 { background: #eee }
.prettyprint *{font-family:'courier new',monospace;}
/*.prettyprint .com { color: #93a1a1; }*/
/*.prettyprint .lit { color: #AE81FF; }*/
/*.prettyprint .pun,*/
/*.prettyprint .opn,*/
/*.prettyprint .clo { color: #F8F8F2; }*/
/*.prettyprint .fun { color: #dc322f; }*/
/*.prettyprint .str,*/
/*.prettyprint .atv { color: #E6DB74; }*/
/*.prettyprint .kwd,*/
/*.prettyprint .tag { color: #F92659; }*/
/*.prettyprint .typ,*/
/*.prettyprint .atn,*/
/*.prettyprint .dec,*/
/*.prettyprint .var { color: #A6E22E; }*/
/*.prettyprint .pln { color: #66D9EF; }*/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,77 @@
/* Pretty printing styles. Used with prettify.js. */
/* SPAN elements with the classes below are added by prettyprint. */
.pln { color: #000 } /* plain text */
@media screen {
.str { color: #080 } /* string content */
.kwd { color: #008 } /* a keyword */
.com { color: #800 } /* a comment */
.typ { color: #606 } /* a type name */
.lit { color: #066 } /* a literal value */
/* punctuation, lisp open bracket, lisp close bracket */
.pun, .opn, .clo { color: #660 }
.tag { color: #008 } /* a markup tag name */
.atn { color: #606 } /* a markup attribute name */
.atv { color: #080 } /* a markup attribute value */
.dec, .var { color: #606 } /* a declaration; a variable name */
.fun { color: red } /* a function name */
}
/* Use higher contrast and text-weight for printable form. */
@media print, projection {
.str { color: #060 }
.kwd { color: #006; font-weight: bold }
.com { color: #600; font-style: italic }
.typ { color: #404; font-weight: bold }
.lit { color: #044 }
.pun, .opn, .clo { color: #440 }
.tag { color: #006; font-weight: bold }
.atn { color: #404 }
.atv { color: #060 }
}
/* Put a border around prettyprinted code snippets. */
pre.prettyprint { padding: 2px;
border-left:30px solid #ccc;
border-bottom: 1px solid #ccc;
border-right: 1px solid #ccc,
border-top: 1px solid #ccc }
pre li,ul,ol {
list-style-type: decimal;
}
/* Specify class=linenums on a pre to get line numbering */
ol.linenums { margin-top: 0; margin-bottom: 0;line-height: 3px } /* IE indents via margin-left */
li.L0,
li.L1,
li.L2,
li.L3,
li.L5,
li.L6,
li.L7,
li.L8 { list-style-type: decimal; }
/* Alternate shading for lines */
li.L1,
li.L3,
li.L5,
li.L7,
li.L9 { background: #eee }
.prettyprint *{font-family:'courier new',monospace;}
/*.prettyprint .com { color: #93a1a1; }*/
/*.prettyprint .lit { color: #AE81FF; }*/
/*.prettyprint .pun,*/
/*.prettyprint .opn,*/
/*.prettyprint .clo { color: #F8F8F2; }*/
/*.prettyprint .fun { color: #dc322f; }*/
/*.prettyprint .str,*/
/*.prettyprint .atv { color: #E6DB74; }*/
/*.prettyprint .kwd,*/
/*.prettyprint .tag { color: #F92659; }*/
/*.prettyprint .typ,*/
/*.prettyprint .atn,*/
/*.prettyprint .dec,*/
/*.prettyprint .var { color: #A6E22E; }*/
/*.prettyprint .pln { color: #66D9EF; }*/