mirror of
https://github.com/liriliri/eruda.git
synced 2026-02-02 09:49:00 +08:00
feat: remove luna syntax highlighter
This commit is contained in:
@@ -60,7 +60,6 @@ module.exports = {
|
|||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
include: [
|
include: [
|
||||||
path.resolve(__dirname, '../src'),
|
path.resolve(__dirname, '../src'),
|
||||||
path.resolve(__dirname, '../node_modules/highlight.js'),
|
|
||||||
path.resolve(__dirname, '../node_modules/luna-console'),
|
path.resolve(__dirname, '../node_modules/luna-console'),
|
||||||
path.resolve(__dirname, '../node_modules/luna-modal'),
|
path.resolve(__dirname, '../node_modules/luna-modal'),
|
||||||
path.resolve(__dirname, '../node_modules/luna-tab'),
|
path.resolve(__dirname, '../node_modules/luna-tab'),
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ci": "npm run lint && npm run test && npm run build && npm run es5",
|
"ci": "npm run lint && npm run test && npm run build && npm run es5",
|
||||||
"build": "lsla shx rm -rf dist && webpack --config build/webpack.prod.js && node build/build && lsla shx cp README.md eruda.d.ts dist",
|
"build": "lsla shx rm -rf dist && webpack --config build/webpack.dev.js && node build/build && lsla shx cp README.md eruda.d.ts dist",
|
||||||
"build:analyser": "webpack --config build/webpack.analyser.js",
|
"build:analyser": "webpack --config build/webpack.analyser.js",
|
||||||
"dev": "webpack-dev-server --config build/webpack.dev.js --host 0.0.0.0",
|
"dev": "webpack-dev-server --config build/webpack.dev.js --host 0.0.0.0",
|
||||||
"test": "karma start",
|
"test": "karma start",
|
||||||
@@ -74,7 +74,6 @@
|
|||||||
"luna-modal": "^1.0.0",
|
"luna-modal": "^1.0.0",
|
||||||
"luna-notification": "^0.1.4",
|
"luna-notification": "^0.1.4",
|
||||||
"luna-object-viewer": "^0.2.2",
|
"luna-object-viewer": "^0.2.2",
|
||||||
"luna-syntax-highlighter": "^1.0.0",
|
|
||||||
"luna-tab": "^0.1.2",
|
"luna-tab": "^0.1.2",
|
||||||
"node-sass": "^7.0.1",
|
"node-sass": "^7.0.1",
|
||||||
"postcss-clean": "^1.1.0",
|
"postcss-clean": "^1.1.0",
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import last from 'licia/last'
|
import last from 'licia/last'
|
||||||
import detectOs from 'licia/detectOs'
|
import detectOs from 'licia/detectOs'
|
||||||
|
import arrToMap from 'licia/arrToMap'
|
||||||
|
|
||||||
export function getType(contentType) {
|
export function getType(contentType) {
|
||||||
if (!contentType) return 'unknown'
|
if (!contentType) return 'unknown'
|
||||||
@@ -19,7 +20,7 @@ export function curlStr(request) {
|
|||||||
}
|
}
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
let command = []
|
let command = []
|
||||||
const ignoredHeaders = new Set([
|
const ignoredHeaders = arrToMap([
|
||||||
'accept-encoding',
|
'accept-encoding',
|
||||||
'host',
|
'host',
|
||||||
'method',
|
'method',
|
||||||
@@ -77,7 +78,7 @@ export function curlStr(request) {
|
|||||||
const formData = request.requestFormData()
|
const formData = request.requestFormData()
|
||||||
if (formData) {
|
if (formData) {
|
||||||
data.push('--data-raw ' + escapeString(formData))
|
data.push('--data-raw ' + escapeString(formData))
|
||||||
ignoredHeaders.add('content-length')
|
ignoredHeaders['content-length'] = true
|
||||||
inferredMethod = 'POST'
|
inferredMethod = 'POST'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +90,7 @@ export function curlStr(request) {
|
|||||||
for (let i = 0; i < requestHeaders.length; i++) {
|
for (let i = 0; i < requestHeaders.length; i++) {
|
||||||
const header = requestHeaders[i]
|
const header = requestHeaders[i]
|
||||||
const name = header.name.replace(/^:/, '')
|
const name = header.name.replace(/^:/, '')
|
||||||
if (ignoredHeaders.has(name.toLowerCase())) {
|
if (ignoredHeaders[name.toLowerCase()]) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
command.push('-H ' + escapeString(name + ': ' + header.value))
|
command.push('-H ' + escapeString(name + ': ' + header.value))
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import Settings from '../Settings/Settings'
|
|||||||
import ajax from 'licia/ajax'
|
import ajax from 'licia/ajax'
|
||||||
import isStr from 'licia/isStr'
|
import isStr from 'licia/isStr'
|
||||||
import escape from 'licia/escape'
|
import escape from 'licia/escape'
|
||||||
|
import trim from 'licia/trim'
|
||||||
|
import map from 'licia/map'
|
||||||
|
import highlight from 'licia/highlight'
|
||||||
import evalCss from '../lib/evalCss'
|
import evalCss from '../lib/evalCss'
|
||||||
import LunaSyntaxHighlighter from 'luna-syntax-highlighter'
|
|
||||||
import { classPrefix as c } from '../lib/util'
|
import { classPrefix as c } from '../lib/util'
|
||||||
|
|
||||||
export default class Sources extends Tool {
|
export default class Sources extends Tool {
|
||||||
@@ -170,14 +172,61 @@ export default class Sources extends Tool {
|
|||||||
_renderCode() {
|
_renderCode() {
|
||||||
const data = this._data
|
const data = this._data
|
||||||
|
|
||||||
this._renderHtml(`<div class="${c('code')}"></div>`, false)
|
let code = data.val
|
||||||
const container = this._$el.find(c('.code')).get(0)
|
const len = data.val.length
|
||||||
new LunaSyntaxHighlighter(container, {
|
|
||||||
code: data.val,
|
// If source code too big, don't process it.
|
||||||
language: data.type,
|
if (len < MAX_BEAUTIFY_LEN) {
|
||||||
wrapLongLines: true,
|
const curTheme = evalCss.getCurTheme()
|
||||||
showLineNumbers: data.val.length < MAX_LINE_NUM_LEN && this._showLineNum,
|
code = highlight(code, data.type, {
|
||||||
})
|
keyword: `color:${curTheme.keywordColor}`,
|
||||||
|
number: `color:${curTheme.numberColor}`,
|
||||||
|
operator: `color:${curTheme.operatorColor}`,
|
||||||
|
comment: `color:${curTheme.commentColor}`,
|
||||||
|
string: `color:${curTheme.stringColor}`,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
code = escape(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
const showLineNum = len < MAX_LINE_NUM_LEN && this._showLineNum
|
||||||
|
|
||||||
|
if (showLineNum) {
|
||||||
|
code = code.split('\n').map((line, idx) => {
|
||||||
|
if (trim(line) === '') line = ' '
|
||||||
|
|
||||||
|
return {
|
||||||
|
idx: idx + 1,
|
||||||
|
val: line,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let html
|
||||||
|
if (showLineNum) {
|
||||||
|
const lineNum = map(code, ({ idx }) => {
|
||||||
|
return `<div class="${c('line-num')}">${idx}</div>`
|
||||||
|
}).join('')
|
||||||
|
const codeLine = map(code, ({ val }) => {
|
||||||
|
return `<pre class="${c('code-line')}">${val}</pre>`
|
||||||
|
}).join('')
|
||||||
|
html = `<div class="${c('code-wrapper')}">
|
||||||
|
<table class="${c('code')}">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="${c('gutter')}">${lineNum}</td>
|
||||||
|
<td class="${c('content')}">${codeLine}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>`
|
||||||
|
} else {
|
||||||
|
html = `<div class="${c('code-wrapper')}">
|
||||||
|
<pre class="${c('code')}">${code}</pre>
|
||||||
|
</div>`
|
||||||
|
}
|
||||||
|
|
||||||
|
this._renderHtml(html)
|
||||||
}
|
}
|
||||||
_renderObj() {
|
_renderObj() {
|
||||||
// Using cache will keep binding events to the same elements.
|
// Using cache will keep binding events to the same elements.
|
||||||
@@ -218,4 +267,5 @@ export default class Sources extends Tool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_BEAUTIFY_LEN = 100000
|
||||||
const MAX_LINE_NUM_LEN = 400000
|
const MAX_LINE_NUM_LEN = 400000
|
||||||
|
|||||||
@@ -17,7 +17,29 @@
|
|||||||
padding: $padding;
|
padding: $padding;
|
||||||
}
|
}
|
||||||
.code {
|
.code {
|
||||||
height: 100%;
|
font-size: $font-size-s;
|
||||||
|
.content * {
|
||||||
|
user-select: text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pre.code {
|
||||||
|
padding: $padding;
|
||||||
|
}
|
||||||
|
table.code {
|
||||||
|
border-collapse: collapse;
|
||||||
|
.gutter {
|
||||||
|
background: var(--background);
|
||||||
|
color: var(--primary);
|
||||||
|
}
|
||||||
|
.line-num {
|
||||||
|
border-right: 1px solid var(--border);
|
||||||
|
padding: 0 3px 0 5px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
.code-line {
|
||||||
|
padding: 0 4px;
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.image {
|
.image {
|
||||||
font-size: $font-size-s;
|
font-size: $font-size-s;
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ export default {
|
|||||||
// font-face doesn't work inside shadow dom.
|
// font-face doesn't work inside shadow dom.
|
||||||
evalCss.container = document.head
|
evalCss.container = document.head
|
||||||
evalCss(require('./style/icon.css') +
|
evalCss(require('./style/icon.css') +
|
||||||
require('luna-console/luna-console.css') + require('luna-object-viewer/luna-object-viewer.css') + require('luna-dom-viewer/luna-dom-viewer.css') + require('luna-syntax-highlighter/luna-syntax-highlighter.css'))
|
require('luna-console/luna-console.css') + require('luna-object-viewer/luna-object-viewer.css') + require('luna-dom-viewer/luna-dom-viewer.css'))
|
||||||
|
|
||||||
el = document.createElement('div')
|
el = document.createElement('div')
|
||||||
shadowRoot.appendChild(el)
|
shadowRoot.appendChild(el)
|
||||||
@@ -219,7 +219,6 @@ export default {
|
|||||||
require('luna-dom-viewer/luna-dom-viewer.css') +
|
require('luna-dom-viewer/luna-dom-viewer.css') +
|
||||||
require('luna-modal/luna-modal.css') +
|
require('luna-modal/luna-modal.css') +
|
||||||
require('luna-tab/luna-tab.css') +
|
require('luna-tab/luna-tab.css') +
|
||||||
require('luna-syntax-highlighter/luna-syntax-highlighter.css') +
|
|
||||||
require('./style/style.scss') +
|
require('./style/style.scss') +
|
||||||
require('./style/icon.css')
|
require('./style/icon.css')
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -305,61 +305,3 @@
|
|||||||
.luna-tab-slider {
|
.luna-tab-slider {
|
||||||
background: var(--accent);
|
background: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.luna-syntax-highlighter {
|
|
||||||
color: var(--foreground);
|
|
||||||
border: none;
|
|
||||||
background: var(--background);
|
|
||||||
font-size: $font-size-s;
|
|
||||||
.luna-syntax-highlighter-line-code {
|
|
||||||
user-select: text;
|
|
||||||
* {
|
|
||||||
user-select: text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-copy,
|
|
||||||
.luna-syntax-highlighter-line-number {
|
|
||||||
border-color: var(--border);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-copy .luna-syntax-highlighter-icon-check {
|
|
||||||
color: var(--accent);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-copy {
|
|
||||||
background-color: var(--background);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-string {
|
|
||||||
color: var(--string-color);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-variable,
|
|
||||||
.luna-syntax-highlighter-keyword {
|
|
||||||
color: var(--keyword-color);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-attr,
|
|
||||||
.luna-syntax-highlighter-title {
|
|
||||||
color: var(--attribute-name-color);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-comment {
|
|
||||||
color: var(--comment-color);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-regexp {
|
|
||||||
color: var(--string-color);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-number {
|
|
||||||
color: var(--number-color);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-tag {
|
|
||||||
color: var(--tag-name-color);
|
|
||||||
.luna-syntax-highlighter-attr {
|
|
||||||
color: var(--attribute-name-color);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-string {
|
|
||||||
color: var(--string-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-attribute {
|
|
||||||
color: var(--attribute-name-color);
|
|
||||||
}
|
|
||||||
.luna-syntax-highlighter-selector-class {
|
|
||||||
color: var(--keyword-color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user