mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
ui: prism: 支持显示空白符
This commit is contained in:
1 parent
8fede5fc9d
commit
b62b4e58a0
5 files changed
+81
-3
No files matched your search
@@ -11,7 +11,7 @@
|
|||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hydrooj/utils": "^1.0.1",
|
"@hydrooj/utils": "^1.0.3",
|
||||||
"adm-zip": "^0.5.5",
|
"adm-zip": "^0.5.5",
|
||||||
"ansi_up": "^5.0.1",
|
"ansi_up": "^5.0.1",
|
||||||
"cookies": "^0.8.0",
|
"cookies": "^0.8.0",
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ export async function setting(pending: string[], fail: string[], modelSetting: t
|
|||||||
system: modelSetting.SystemSetting,
|
system: modelSetting.SystemSetting,
|
||||||
account: modelSetting.AccountSetting,
|
account: modelSetting.AccountSetting,
|
||||||
preference: modelSetting.PreferenceSetting,
|
preference: modelSetting.PreferenceSetting,
|
||||||
|
domain: modelSetting.DomainSetting,
|
||||||
};
|
};
|
||||||
for (const i of pending) {
|
for (const i of pending) {
|
||||||
let p = path.resolve(i, 'setting.yaml');
|
let p = path.resolve(i, 'setting.yaml');
|
||||||
@@ -105,9 +106,10 @@ export async function setting(pending: string[], fail: string[], modelSetting: t
|
|||||||
.replace(/\$TEMP/g, os.tmpdir())
|
.replace(/\$TEMP/g, os.tmpdir())
|
||||||
.replace(/\$HOME/g, os.homedir());
|
.replace(/\$HOME/g, os.homedir());
|
||||||
}
|
}
|
||||||
map[cfg[key].category || 'system'](
|
const category = cfg[key].category || 'system';
|
||||||
|
map[category](
|
||||||
modelSetting.Setting(
|
modelSetting.Setting(
|
||||||
name, `${name}.${key}`, val, cfg[key].type || 'text',
|
name, category === 'system' ? `${name}.${key}` : key, val, cfg[key].type || 'text',
|
||||||
cfg[key].name || key, cfg[key].desc || '',
|
cfg[key].name || key, cfg[key].desc || '',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -120,3 +120,32 @@ pre > code
|
|||||||
display: block
|
display: block
|
||||||
padding-right: 0.8em
|
padding-right: 0.8em
|
||||||
text-align: right
|
text-align: right
|
||||||
|
|
||||||
|
.token.tab:not(:empty),
|
||||||
|
.token.cr,
|
||||||
|
.token.lf,
|
||||||
|
.token.space
|
||||||
|
position: relative
|
||||||
|
|
||||||
|
.token.tab:not(:empty):before,
|
||||||
|
.token.cr:before,
|
||||||
|
.token.lf:before,
|
||||||
|
.token.space:before
|
||||||
|
color: #808080
|
||||||
|
opacity: 0.6
|
||||||
|
position: absolute
|
||||||
|
|
||||||
|
.token.tab:not(:empty):before
|
||||||
|
content: '\21E5'
|
||||||
|
|
||||||
|
.token.cr:before
|
||||||
|
content: '\240D'
|
||||||
|
|
||||||
|
.token.crlf:before
|
||||||
|
content: '\240D\240A'
|
||||||
|
|
||||||
|
.token.lf:before
|
||||||
|
content: '\240A'
|
||||||
|
|
||||||
|
.token.space:before
|
||||||
|
content: '\00B7'
|
||||||
@@ -51,6 +51,49 @@ try {
|
|||||||
// snowpack
|
// snowpack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const invisibles = {
|
||||||
|
tab: /\t/,
|
||||||
|
crlf: /\r\n/,
|
||||||
|
lf: /\n/,
|
||||||
|
cr: /\r/,
|
||||||
|
space: / /,
|
||||||
|
};
|
||||||
|
|
||||||
|
function addInvisibles(grammar) {
|
||||||
|
if (!grammar || grammar.tab) return;
|
||||||
|
for (const name in invisibles) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(invisibles, name)) {
|
||||||
|
grammar[name] = invisibles[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const name in grammar) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(grammar, name) && !invisibles[name]) {
|
||||||
|
if (name === 'rest') addInvisibles(grammar.rest);
|
||||||
|
else handlerInvisiblesToken(grammar, name); // eslint-disable-line no-use-before-define
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handlerInvisiblesToken(tokens, name) {
|
||||||
|
const value = tokens[name];
|
||||||
|
const type = Prism.util.type(value);
|
||||||
|
if (type === 'RegExp') {
|
||||||
|
const inside = {};
|
||||||
|
tokens[name] = { pattern: value, inside };
|
||||||
|
addInvisibles(inside);
|
||||||
|
} else if (type === 'Array') {
|
||||||
|
for (let i = 0, l = value.length; i < l; i++) handlerInvisiblesToken(value, i);
|
||||||
|
} else {
|
||||||
|
const inside = value.inside || (value.inside = {});
|
||||||
|
addInvisibles(inside);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Prism.hooks.add('before-highlight', (env) => {
|
||||||
|
console.log(UserContext.showInvisibleChar);
|
||||||
|
if (UserContext.showInvisibleChar) addInvisibles(env.grammar);
|
||||||
|
});
|
||||||
|
|
||||||
const prismjsApiWrap = {
|
const prismjsApiWrap = {
|
||||||
highlightBlocks: ($dom) => {
|
highlightBlocks: ($dom) => {
|
||||||
$dom.find('pre code').get().forEach((code) => {
|
$dom.find('pre code').get().forEach((code) => {
|
||||||
|
|||||||
@@ -81,3 +81,7 @@ lang_monaco_modes:
|
|||||||
go: go
|
go: go
|
||||||
rb: ruby
|
rb: ruby
|
||||||
jl: julia
|
jl: julia
|
||||||
|
showInvisibleChar:
|
||||||
|
type: boolean
|
||||||
|
desc: show invisible characters when formatting code
|
||||||
|
category: preference
|
||||||
Reference in new issue
Block a user