mirror of
https://github.com/liriliri/eruda.git
synced 2026-03-20 09:38:37 +08:00
Dev: Log code input highlight
This commit is contained in:
@@ -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, ' ');
|
||||
}
|
||||
|
||||
function txtToHtml(str)
|
||||
{
|
||||
return str.replace(/\n/g, '<br/>')
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
color: #fff;
|
||||
border-radius: 4px;
|
||||
}
|
||||
&.input {
|
||||
background: #fff;
|
||||
}
|
||||
&.log, &.output, &.info, &.dir {
|
||||
border-bottom: 1px solid #b4b4b4;
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ function formatChildNodes(nodes)
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (child.nodeType === 1 || child.id !== 'eruda')
|
||||
if (child.nodeType === 1 && child.id !== 'eruda')
|
||||
{
|
||||
ret.push({
|
||||
text: formatElName(child.tagName, child.id, child.className, child.attributes),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Tool from '../DevTools/Tool.es6'
|
||||
import util from '../lib/util'
|
||||
import beautify from 'js-beautify'
|
||||
import highlight from './highlight.es6'
|
||||
import highlight from '../lib/highlight.es6'
|
||||
|
||||
require('./Sources.scss');
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
overflow-y: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
.code {
|
||||
background: #fff;
|
||||
padding: $common-padding;
|
||||
overflow-x: auto;
|
||||
min-height: 100%;
|
||||
|
||||
Reference in New Issue
Block a user