Skip to content

Commit

Permalink
chore: small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
surunzi committed Jan 27, 2023
1 parent 2b6f766 commit 20001f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Sources/Sources.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import Tool from '../DevTools/Tool'
import LunaObjectViewer from 'luna-object-viewer'
import Settings from '../Settings/Settings'
import ajax from 'licia/ajax'
import each from 'licia/each'
import isStr from 'licia/isStr'
import escape from 'licia/escape'
import truncate from 'licia/truncate'
import replaceAll from 'licia/replaceAll'
import highlight from 'licia/highlight'
import LunaTextViewer from 'luna-text-viewer'
import evalCss from '../lib/evalCss'
Expand Down Expand Up @@ -172,7 +174,10 @@ export default class Sources extends Tool {
_renderCode() {
const data = this._data

this._renderHtml(`<div class="${c('code')}"></div>`, false)
this._renderHtml(
`<div class="${c('code')}" data-type="${data.type}"></div>`,
false
)

let code = data.val
const len = data.val.length
Expand All @@ -183,13 +188,15 @@ export default class Sources extends Tool {

// If source code too big, don't process it.
if (len < MAX_BEAUTIFY_LEN) {
const curTheme = evalCss.getCurTheme()
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}`,
comment: '',
string: '',
number: '',
keyword: '',
operator: '',
})
each(['comment', 'string', 'number', 'keyword', 'operator'], (type) => {
code = replaceAll(code, `class="${type}"`, `class="${c(type)}"`)
})
} else {
code = escape(code)
Expand Down
20 changes: 20 additions & 0 deletions src/Sources/Sources.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@
.raw,
.code {
height: 100%;
.keyword {
color: var(--keyword-color);
}
.comment {
color: var(--comment-color);
}
.number {
color: var(--number-color);
}
.string {
color: var(--string-color);
}
.operator {
color: var(--operator-color);
}
&[data-type='html'] {
.keyword {
color: var(--tag-name-color);
}
}
}
.image {
font-size: $font-size-s;
Expand Down

0 comments on commit 20001f2

Please sign in to comment.