Dev: Log code input highlight

This commit is contained in:
surunzi
2016-05-09 13:16:40 +08:00
parent 173c2823db
commit 3f23b97e83
7 changed files with 18 additions and 10 deletions

View File

@@ -1,4 +1,6 @@
import util from '../lib/util'
import highlight from '../lib/highlight.es6'
import beautify from 'js-beautify'
require('./Log.scss');
@@ -40,7 +42,8 @@ export default class Log extends util.Emitter
this._insert({
type: 'input',
ignoreFilter: true,
val: transCode(jsCode)
isCode: true,
val: jsCode
});
try {
@@ -182,7 +185,13 @@ export default class Log extends util.Emitter
times: 1
});
if (!log.isCode && log.type != 'html') log.val = txtToHtml(log.val);
if (log.isCode)
{
log.val = highlight(beautify(log.val), 'js');
} else if (log.type != 'html')
{
log.val = txtToHtml(log.val);
}
var lastLog = this._lastLog;
@@ -320,11 +329,6 @@ function transMultipleMsg(args)
return ret.join(' ');
}
function transCode(code)
{
return code.replace(/\n/g, '<br/>').replace(/ /g, '&nbsp;');
}
function txtToHtml(str)
{
return str.replace(/\n/g, '<br/>')

View File

@@ -3,7 +3,7 @@
<li class="eruda-{{type}}">
{{#if showTimes}}<span class="eruda-times">{{times}}</span>{{/if}}
{{#if isCode}}
<pre><code>{{{val}}}</code></pre>
<pre>{{{val}}}</pre>
{{else}}
{{{val}}}
{{/if}}

View File

@@ -19,6 +19,9 @@
color: #fff;
border-radius: 4px;
}
&.input {
background: #fff;
}
&.log, &.output, &.info, &.dir {
border-bottom: 1px solid #b4b4b4;
}