diff --git a/app/src/constants.ts b/app/src/constants.ts
index ad31f4018..cca6bc1ca 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -541,18 +541,11 @@ export abstract class Constants {
public static readonly INLINE_TYPE: string[] = ["block-ref", "kbd", "text", "file-annotation-ref", "a", "strong", "em", "u", "s", "mark", "sup", "sub", "tag", "code", "inline-math", "inline-memo"];
public static readonly BLOCK_HINT_KEYS: string[] = ["((", "[[", "((", "【【"];
public static readonly BLOCK_HINT_CLOSE_KEYS: IObject = {"((": "))", "[[": "]]", "((": "))", "【【": "】】"};
- public static readonly EXTRA_CODE_LANGUAGES: string[] = [
- // 同名
+ // common: "bash", "c", "csharp", "cpp", "css", "diff", "go", "xml", "json", "java", "javascript", "kotlin", "less", "lua", "makefile", "markdown", "objectivec", "php", "php-template", "perl", "plaintext", "python", "python-repl", "r", "ruby", "rust", "scss", "sql", "shell", "swift", "ini", "typescript", "vbnet", "yaml", "properties", "1c", "armasm", "avrasm", "actionscript", "ada", "angelscript", "accesslog", "apache", "applescript", "arcade", "arduino", "asciidoc", "aspectj", "abnf", "autohotkey", "autoit", "awk", "basic", "bnf", "dos", "brainfuck", "cal", "cmake", "csp", "cos", "capnproto", "ceylon", "clean", "clojure", "clojure-repl", "coffeescript", "coq", "crystal", "d", "dns", "dart", "delphi", "dts", "django", "dockerfile", "dust", "erb", "elixir", "elm", "erlang", "erlang-repl", "excel", "ebnf", "fsharp", "fix", "flix", "fortran", "gcode", "gams", "gauss", "glsl", "gml", "gherkin", "golo", "gradle", "groovy", "haml", "hsp", "http", "handlebars", "haskell", "haxe", "hy", "irpf90", "isbl", "inform7", "x86asm", "jboss-cli", "julia", "julia-repl", "ldif", "llvm", "lsl", "latex", "lasso", "leaf", "lisp", "livecodeserver", "livescript", "mel", "mipsasm", "matlab", "maxima", "mercury", "axapta", "routeros", "mizar", "mojolicious", "monkey", "moonscript", "n1ql", "nsis", "nestedtext", "nginx", "nim", "nix", "node-repl", "ocaml", "openscad", "ruleslanguage", "oxygene", "pf", "parser3", "pony", "pgsql", "powershell", "processing", "prolog", "protobuf", "puppet", "purebasic", "profile", "q", "qml", "reasonml", "rib", "rsl", "roboconf", "sas", "sml", "sqf", "step21", "scala", "scheme", "scilab", "smali", "smalltalk", "stan", "stata", "stylus", "subunit", "tp", "taggerscript", "tcl", "tap", "thrift", "twig", "vbscript", "vbscript-html", "vhdl", "vala", "verilog", "vim", "wasm", "mathematica", "wren", "xl", "xquery", "zephir", "crmsh", "dsconfig", "graphql",
+ // third: "yul", "solidity", "abap", "hlsl"
+ public static readonly ALIAS_CODE_LANGUAGES: string[] = [
"js", "ts", "html", "toml", "c#", "bat",
];
- public static readonly CODE_LANGUAGES: string[] = [
- // 附加
- ...Constants.EXTRA_CODE_LANGUAGES,
- // common
- "bash", "c", "csharp", "cpp", "css", "diff", "go", "xml", "json", "java", "javascript", "kotlin", "less", "lua", "makefile", "markdown", "objectivec", "php", "php-template", "perl", "plaintext", "python", "python-repl", "r", "ruby", "rust", "scss", "sql", "shell", "swift", "ini", "typescript", "vbnet", "yaml", "properties", "1c", "armasm", "avrasm", "actionscript", "ada", "angelscript", "accesslog", "apache", "applescript", "arcade", "arduino", "asciidoc", "aspectj", "abnf", "autohotkey", "autoit", "awk", "basic", "bnf", "dos", "brainfuck", "cal", "cmake", "csp", "cos", "capnproto", "ceylon", "clean", "clojure", "clojure-repl", "coffeescript", "coq", "crystal", "d", "dns", "dart", "delphi", "dts", "django", "dockerfile", "dust", "erb", "elixir", "elm", "erlang", "erlang-repl", "excel", "ebnf", "fsharp", "fix", "flix", "fortran", "gcode", "gams", "gauss", "glsl", "gml", "gherkin", "golo", "gradle", "groovy", "haml", "hsp", "http", "handlebars", "haskell", "haxe", "hy", "irpf90", "isbl", "inform7", "x86asm", "jboss-cli", "julia", "julia-repl", "ldif", "llvm", "lsl", "latex", "lasso", "leaf", "lisp", "livecodeserver", "livescript", "mel", "mipsasm", "matlab", "maxima", "mercury", "axapta", "routeros", "mizar", "mojolicious", "monkey", "moonscript", "n1ql", "nsis", "nestedtext", "nginx", "nim", "nix", "node-repl", "ocaml", "openscad", "ruleslanguage", "oxygene", "pf", "parser3", "pony", "pgsql", "powershell", "processing", "prolog", "protobuf", "puppet", "purebasic", "profile", "q", "qml", "reasonml", "rib", "rsl", "roboconf", "sas", "sml", "sqf", "step21", "scala", "scheme", "scilab", "smali", "smalltalk", "stan", "stata", "stylus", "subunit", "tp", "taggerscript", "tcl", "tap", "thrift", "twig", "vbscript", "vbscript-html", "vhdl", "vala", "verilog", "vim", "wasm", "mathematica", "wren", "xl", "xquery", "zephir", "crmsh", "dsconfig", "graphql",
- // third
- "yul", "solidity", "abap", "hlsl"
- ];
// Google Analytics 事件
public static readonly ANALYTICS_EVT_ON_GET_CONFIG: string = "siyuan.onGetConfig";
diff --git a/app/src/protyle/preview/image.ts b/app/src/protyle/preview/image.ts
index 59b0f2409..66447a3cf 100644
--- a/app/src/protyle/preview/image.ts
+++ b/app/src/protyle/preview/image.ts
@@ -6,7 +6,6 @@ export const previewImage = (src: string) => {
addScript(`${Constants.PROTYLE_CDN}/js/viewerjs/viewer.js?v=1.10.4`, "protyleViewerScript").then(() => {
const imagesElement = document.createElement("ul");
imagesElement.innerHTML = `
`;
- // @ts-ignore
window.siyuan.viewer = new Viewer(imagesElement, {
title: [1, (image: HTMLImageElement, imageData: IObject) => {
let name = image.alt;
@@ -57,8 +56,7 @@ export const previewDocImage = (src: string, id: string) => {
}
});
imagesElement.innerHTML = html;
- // @ts-ignore
- window.siyuan.viewer = new window.Viewer(imagesElement, {
+ window.siyuan.viewer = new Viewer(imagesElement, {
title: [1, (image: HTMLImageElement, imageData: IObject) => {
let name = image.alt;
if (!name) {
diff --git a/app/src/protyle/render/graphvizRender.ts b/app/src/protyle/render/graphvizRender.ts
index cfc8bfb7d..89f2fbc94 100644
--- a/app/src/protyle/render/graphvizRender.ts
+++ b/app/src/protyle/render/graphvizRender.ts
@@ -28,7 +28,7 @@ export const graphvizRender = (element: Element, cdn = Constants.PROTYLE_CDN) =>
const url = window.URL || window.webkitURL;
const blobUrl = url.createObjectURL(blob);
const worker = new Worker(blobUrl);
- new window.Viz({worker})
+ new Viz({worker})
.renderSVGElement(Lute.UnEscapeHTMLStr(e.getAttribute("data-content"))).then((result: HTMLElement) => {
renderElement.innerHTML = result.outerHTML;
renderElement.classList.remove("ft__error");
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index c97b4d92a..6695afb29 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -1146,14 +1146,11 @@ export class Toolbar {
const id = nodeElement.getAttribute("data-node-id");
let oldHtml = nodeElement.outerHTML;
- const languages = Array.from(new Set([
- ...Constants.EXTRA_CODE_LANGUAGES,
- ...(window.hljs?.listLanguages() ?? []),
- ])).sort();
- const html = [
- `${window.siyuan.languages.clear}
`,
- ...languages.map(item => `${item}
`),
- ].join("\n");
+ let html = `${window.siyuan.languages.clear}
`;
+ const hljsLanguages = Constants.ALIAS_CODE_LANGUAGES.concat(window.hljs?.listLanguages() ?? []).sort();
+ hljsLanguages.forEach((item) => {
+ html += `${item}
`;
+ });
this.subElement.style.width = "";
this.subElement.style.padding = "";
@@ -1196,7 +1193,7 @@ export class Toolbar {
});
inputElement.addEventListener("input", (event) => {
const lowerCaseValue = inputElement.value.toLowerCase();
- const matchLanguages = languages.filter(item => item.includes(lowerCaseValue));
+ const matchLanguages = hljsLanguages.filter(item => item.includes(lowerCaseValue));
let html = "";
// sort
let matchInput = false;
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 769d051cc..3e3c6e3e9 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -81,17 +81,45 @@ type TAVFilterOperator =
declare module "blueimp-md5"
interface Window {
- ABCJS?: IABCJS
- Viewer?: Function
- Viz?: IViz
- echarts?: IECharts
- hljs?: IHLJS
- katex?: IKaTeX
- mermaid?: IMermaid
- plantumlEncoder?: IPlantumlEncoder
-
+ echarts: {
+ init(element: HTMLElement, theme?: string, options?: { width: number }): {
+ setOption(option: any): void;
+ getZr(): any;
+ on(name: string, event: (e: any) => void): any;
+ containPixel(name: string, position: number[]): any;
+ resize(): void;
+ };
+ dispose(element: Element): void;
+ getInstanceById(id: string): { resize: () => void };
+ }
+ ABCJS: {
+ renderAbc(element: Element, text: string, options: { responsive: string }): void;
+ }
+ hljs: {
+ listLanguages(): string[];
+ highlight(text: string, options: { language?: string, ignoreIllegals: boolean }): { value: string };
+ getLanguage(text: string): { name: string };
+ };
+ katex: {
+ renderToString(math: string, option: {
+ displayMode: boolean;
+ output: string;
+ macros: IObject;
+ trust: boolean;
+ strict: (errorCode: string) => "ignore" | "warn";
+ }): string;
+ }
+ mermaid: {
+ initialize(options: any): void,
+ init(options: any, element: Element): void
+ };
+ plantumlEncoder: {
+ encode(options: string): string,
+ };
pdfjsLib: any
+
dataLayer: any[]
+
siyuan: ISiyuan
webkit: any
html2canvas: (element: Element, opitons: {
@@ -353,11 +381,7 @@ interface ISiyuan {
bookmarkLabel?: string[]
blockPanels: import("../block/Panel").BlockPanel[],
dialogs: import("../dialog").Dialog[],
- viewer?: {
- destroyed: boolean,
- show: () => void,
- destroy: () => void,
- }
+ viewer?: Viewer
}
interface IScrollAttr {
diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts
index 6720cfc45..edbb710cb 100644
--- a/app/src/types/protyle.d.ts
+++ b/app/src/types/protyle.d.ts
@@ -1,55 +1,3 @@
-interface IABCJS {
- renderAbc(element: Element, text: string, options: { responsive: string }): void;
-}
-
-interface IViz {
- new(worker: { worker: Worker }): IViz;
- renderSVGElement: (code: string) => Promise;
-}
-
-interface IEChartsInstance {
- setOption(option: any): void;
-
- getZr(): any;
-
- on(name: string, event: (e: any) => void): any;
-
- containPixel(name: string, position: number[]): any;
-
- resize(): void;
-}
-
-interface IECharts {
- init(element: HTMLElement, theme?: string, options?: { width: number }): IEChartsInstance;
- dispose(element: Element): void;
- getInstanceById(id: string): { resize: () => void };
-}
-
-interface IHLJS {
- highlight(text: string, options: { language?: string, ignoreIllegals: boolean }): { value: string };
- getLanguage(text: string): { name: string };
- listLanguages(): string[];
-}
-
-interface IKaTeX {
- renderToString(math: string, option: {
- displayMode: boolean;
- output: string;
- macros: IObject;
- trust: boolean;
- strict: (errorCode: string) => "ignore" | "warn";
- }): string;
-}
-
-interface IMermaid {
- initialize(options: any): void;
- init(options: any, element: Element): void;
-}
-
-interface IPlantumlEncoder {
- encode(options: string): string;
-}
-
interface ILuteNode {
TokensStr: () => string;
__internal_object__: {
@@ -149,6 +97,42 @@ interface ILuteOptions extends IMarkdownConfig {
lazyLoadImage?: string;
}
+declare class Viz {
+ constructor(worker: { worker: Worker });
+
+ renderSVGElement: (code: string) => Promise;
+}
+
+declare class Viewer {
+ public destroyed: boolean;
+
+ constructor(element: Element, options: {
+ title: [number, (image: HTMLImageElement, imageData: IObject) => string],
+ button: boolean,
+ initialViewIndex?: number,
+ transition: boolean,
+ hidden: () => void,
+ toolbar: {
+ zoomIn: boolean,
+ zoomOut: boolean,
+ oneToOne: boolean,
+ reset: boolean,
+ prev: boolean,
+ play: boolean,
+ next: boolean,
+ rotateLeft: boolean,
+ rotateRight: boolean,
+ flipHorizontal: boolean,
+ flipVertical: boolean,
+ close: () => void
+ }
+ })
+
+ public destroy(): void
+
+ public show(): void
+}
+
declare class Lute {
public static WalkStop: number;
public static WalkSkipChildren: number;