diff --git a/CHANGELOG.md b/CHANGELOG.md
index 67f6bdf9b..c07f7fed9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -98,6 +98,9 @@
### v3.8.5 / 2021-06-xx
+* [1010](https://github.com/Vanessa219/vditor/issues/1010) 多语言分离 `改进功能`
+* [1008](https://github.com/Vanessa219/vditor/pull/1008) 自定义多语言 `引入特性`
+
### v3.8.4 / 2021-05-13
* [1000](https://github.com/Vanessa219/vditor/issues/1000) 升级 hljs 并添加更多的语言支持 `改进功能`
diff --git a/src/index.ts b/src/index.ts
index 97cc9122b..6c82dc1ad 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -3,7 +3,6 @@ import VditorMethod from "./method";
import {Constants, VDITOR_VERSION} from "./ts/constants";
import {DevTools} from "./ts/devtools/index";
import {Hint} from "./ts/hint/index";
-import {i18n} from "./ts/i18n/index";
import {IR} from "./ts/ir/index";
import {input as irInput} from "./ts/ir/input";
import {processAfterRender} from "./ts/ir/process";
@@ -32,8 +31,8 @@ import {getSelectText} from "./ts/util/getSelectText";
import {Options} from "./ts/util/Options";
import {processCodeRender} from "./ts/util/processCode";
import {getCursorPosition, getEditorRange} from "./ts/util/selection";
-import {WYSIWYG} from "./ts/wysiwyg/index";
import {afterRenderEvent} from "./ts/wysiwyg/afterRenderEvent";
+import {WYSIWYG} from "./ts/wysiwyg/index";
import {input} from "./ts/wysiwyg/input";
import {renderDomByMd} from "./ts/wysiwyg/renderDomByMd";
@@ -57,7 +56,7 @@ class Vditor extends VditorMethod {
},
};
} else if (!options.cache) {
- options.cache = { id: `vditor${id}` };
+ options.cache = {id: `vditor${id}`};
} else if (!options.cache.id) {
options.cache.id = `vditor${id}`;
}
@@ -68,93 +67,20 @@ class Vditor extends VditorMethod {
const mergedOptions = getOptions.merge();
// 支持自定义国际化
-
- if (
- !!mergedOptions.lang &&
- !["en_US", "ja_JP", "ko_KR", "ru_RU", "zh_CN"].includes(
- mergedOptions.lang
- )
- ) {
- throw new Error(
- "options.lang error, see https://ld246.com/article/1549638745630#options"
- );
- }
-
- this.vditor = {
- currentMode: mergedOptions.mode,
- element: id,
- hint: new Hint(mergedOptions.hint.extend),
- lute: undefined,
- options: mergedOptions,
- originalInnerHTML: id.innerHTML,
- outline: new Outline(
- !!mergedOptions.lang
- ? i18n[mergedOptions.lang].outline
- : mergedOptions.i18n.outline
- ),
- tip: new Tip(),
- };
-
- this.vditor.sv = new Editor(this.vditor);
- this.vditor.undo = new Undo();
- this.vditor.wysiwyg = new WYSIWYG(this.vditor);
- this.vditor.ir = new IR(this.vditor);
- this.vditor.toolbar = new Toolbar(this.vditor);
-
- if (mergedOptions.resize.enable) {
- this.vditor.resize = new Resize(this.vditor);
- }
-
- if (this.vditor.toolbar.elements.devtools) {
- this.vditor.devtools = new DevTools();
- }
-
- if (mergedOptions.upload.url || mergedOptions.upload.handler) {
- this.vditor.upload = new Upload();
- }
-
- addScript(
- options._lutePath ||
- `${mergedOptions.cdn}/dist/js/lute/lute.min.js`,
- "vditorLuteScript"
- ).then(() => {
- this.vditor.lute = setLute({
- autoSpace: this.vditor.options.preview.markdown.autoSpace,
- codeBlockPreview: this.vditor.options.preview.markdown
- .codeBlockPreview,
- emojiSite: this.vditor.options.hint.emojiPath,
- emojis: this.vditor.options.hint.emoji,
- fixTermTypo: this.vditor.options.preview.markdown.fixTermTypo,
- footnotes: this.vditor.options.preview.markdown.footnotes,
- headingAnchor: false,
- inlineMathDigit: this.vditor.options.preview.math.inlineDigit,
- linkBase: this.vditor.options.preview.markdown.linkBase,
- linkPrefix: this.vditor.options.preview.markdown.linkPrefix,
- listStyle: this.vditor.options.preview.markdown.listStyle,
- mark: this.vditor.options.preview.markdown.mark,
- mathBlockPreview: this.vditor.options.preview.markdown
- .mathBlockPreview,
- paragraphBeginningSpace: this.vditor.options.preview.markdown
- .paragraphBeginningSpace,
- sanitize: this.vditor.options.preview.markdown.sanitize,
- toc: this.vditor.options.preview.markdown.toc,
- });
-
- this.vditor.preview = new Preview(this.vditor);
-
- initUI(this.vditor);
-
- if (mergedOptions.after) {
- mergedOptions.after();
- }
- if (mergedOptions.icon) {
- // 防止初始化 2 个编辑器时加载 2 次
- addScriptSync(
- `${mergedOptions.cdn}/dist/js/icons/${mergedOptions.icon}.js`,
- "vditorIconScript"
+ if (!mergedOptions.i18n) {
+ if (!["en_US", "ja_JP", "ko_KR", "ru_RU", "zh_CN", "zh_TW"].includes(mergedOptions.lang)) {
+ throw new Error(
+ "options.lang error, see https://ld246.com/article/1549638745630#options",
);
+ } else {
+ addScript(`${mergedOptions.cdn}/dist/js/i18n/${mergedOptions.lang}.js`, "vditorI18nScript").then(() => {
+ this.init(id as HTMLElement, mergedOptions);
+ });
}
- });
+ } else {
+ window.VditorI18n = mergedOptions.i18n
+ this.init(id, mergedOptions)
+ }
}
/** 设置主题 */
@@ -162,16 +88,13 @@ class Vditor extends VditorMethod {
theme: "dark" | "classic",
contentTheme?: string,
codeTheme?: string,
- contentThemePath?: string
+ contentThemePath?: string,
) {
this.vditor.options.theme = theme;
setTheme(this.vditor);
if (contentTheme) {
this.vditor.options.preview.theme.current = contentTheme;
- setContentTheme(
- contentTheme,
- contentThemePath || this.vditor.options.preview.theme.path
- );
+ setContentTheme(contentTheme, contentThemePath || this.vditor.options.preview.theme.path,);
}
if (codeTheme) {
this.vditor.options.preview.hljs.style = codeTheme;
@@ -216,16 +139,11 @@ class Vditor extends VditorMethod {
hidePanel(this.vditor, ["subToolbar", "hint", "popover"]);
disableToolbar(
this.vditor.toolbar.elements,
- Constants.EDIT_TOOLBARS.concat([
- "undo",
- "redo",
- "fullscreen",
- "edit-mode",
- ])
+ Constants.EDIT_TOOLBARS.concat(["undo", "redo", "fullscreen", "edit-mode",]),
);
this.vditor[this.vditor.currentMode].element.setAttribute(
"contenteditable",
- "false"
+ "false",
);
}
@@ -233,18 +151,10 @@ class Vditor extends VditorMethod {
public enable() {
enableToolbar(
this.vditor.toolbar.elements,
- Constants.EDIT_TOOLBARS.concat([
- "undo",
- "redo",
- "fullscreen",
- "edit-mode",
- ])
+ Constants.EDIT_TOOLBARS.concat(["undo", "redo", "fullscreen", "edit-mode",]),
);
this.vditor.undo.resetIcon(this.vditor);
- this.vditor[this.vditor.currentMode].element.setAttribute(
- "contenteditable",
- "true"
- );
+ this.vditor[this.vditor.currentMode].element.setAttribute("contenteditable", "true",);
}
/** 返回选中的字符串 */
@@ -287,7 +197,7 @@ class Vditor extends VditorMethod {
public enableCache() {
if (!this.vditor.options.cache.id) {
throw new Error(
- "need options.cache.id, see https://ld246.com/article/1549638745630#options"
+ "need options.cache.id, see https://ld246.com/article/1549638745630#options",
);
}
this.vditor.options.cache.enable = true;
@@ -359,9 +269,7 @@ class Vditor extends VditorMethod {
/** 设置编辑器内容 */
public setValue(markdown: string, clearStack = false) {
if (this.vditor.currentMode === "sv") {
- this.vditor.sv.element.innerHTML = this.vditor.lute.SpinVditorSVDOM(
- markdown
- );
+ this.vditor.sv.element.innerHTML = this.vditor.lute.SpinVditorSVDOM(markdown,);
processSVAfterRender(this.vditor, {
enableAddUndoStack: true,
enableHint: false,
@@ -374,9 +282,7 @@ class Vditor extends VditorMethod {
enableInput: false,
});
} else {
- this.vditor.ir.element.innerHTML = this.vditor.lute.Md2VditorIRDOM(
- markdown
- );
+ this.vditor.ir.element.innerHTML = this.vditor.lute.Md2VditorIRDOM(markdown,);
this.vditor.ir.element
.querySelectorAll(".vditor-ir__preview[data-render='2']")
.forEach((item: HTMLElement) => {
@@ -520,6 +426,80 @@ class Vditor extends VditorMethod {
enableInput: false,
});
}
+
+ private init(id: HTMLElement, mergedOptions: IOptions) {
+ this.vditor = {
+ currentMode: mergedOptions.mode,
+ element: id,
+ hint: new Hint(mergedOptions.hint.extend),
+ lute: undefined,
+ options: mergedOptions,
+ originalInnerHTML: id.innerHTML,
+ outline: new Outline(window.VditorI18n.outline),
+ tip: new Tip(),
+ };
+
+ this.vditor.sv = new Editor(this.vditor);
+ this.vditor.undo = new Undo();
+ this.vditor.wysiwyg = new WYSIWYG(this.vditor);
+ this.vditor.ir = new IR(this.vditor);
+ this.vditor.toolbar = new Toolbar(this.vditor);
+
+ if (mergedOptions.resize.enable) {
+ this.vditor.resize = new Resize(this.vditor);
+ }
+
+ if (this.vditor.toolbar.elements.devtools) {
+ this.vditor.devtools = new DevTools();
+ }
+
+ if (mergedOptions.upload.url || mergedOptions.upload.handler) {
+ this.vditor.upload = new Upload();
+ }
+
+ addScript(
+ mergedOptions._lutePath ||
+ `${mergedOptions.cdn}/dist/js/lute/lute.min.js`,
+ "vditorLuteScript",
+ ).then(() => {
+ this.vditor.lute = setLute({
+ autoSpace: this.vditor.options.preview.markdown.autoSpace,
+ codeBlockPreview: this.vditor.options.preview.markdown
+ .codeBlockPreview,
+ emojiSite: this.vditor.options.hint.emojiPath,
+ emojis: this.vditor.options.hint.emoji,
+ fixTermTypo: this.vditor.options.preview.markdown.fixTermTypo,
+ footnotes: this.vditor.options.preview.markdown.footnotes,
+ headingAnchor: false,
+ inlineMathDigit: this.vditor.options.preview.math.inlineDigit,
+ linkBase: this.vditor.options.preview.markdown.linkBase,
+ linkPrefix: this.vditor.options.preview.markdown.linkPrefix,
+ listStyle: this.vditor.options.preview.markdown.listStyle,
+ mark: this.vditor.options.preview.markdown.mark,
+ mathBlockPreview: this.vditor.options.preview.markdown
+ .mathBlockPreview,
+ paragraphBeginningSpace: this.vditor.options.preview.markdown
+ .paragraphBeginningSpace,
+ sanitize: this.vditor.options.preview.markdown.sanitize,
+ toc: this.vditor.options.preview.markdown.toc,
+ });
+
+ this.vditor.preview = new Preview(this.vditor);
+
+ initUI(this.vditor);
+
+ if (mergedOptions.after) {
+ mergedOptions.after();
+ }
+ if (mergedOptions.icon) {
+ // 防止初始化 2 个编辑器时加载 2 次
+ addScriptSync(
+ `${mergedOptions.cdn}/dist/js/icons/${mergedOptions.icon}.js`,
+ "vditorIconScript",
+ );
+ }
+ });
+ }
}
export default Vditor;
diff --git a/src/js/i18n/en_US.js b/src/js/i18n/en_US.js
new file mode 100644
index 000000000..d660a78ff
--- /dev/null
+++ b/src/js/i18n/en_US.js
@@ -0,0 +1,79 @@
+window.VditorI18n = {
+ "alignCenter": "Center",
+ "alignLeft": "Left",
+ "alignRight": "Right",
+ "alternateText": "Alternate text",
+ "bold": "Blod",
+ "both": "editor & preview",
+ "check": "Task List",
+ "close": "Close",
+ "code": "Code Block",
+ "code-theme": "Code Block Theme Preview",
+ "column": "Column",
+ "comment": "Comment",
+ "confirm": "Confirm",
+ "content-theme": "Content Theme Preview",
+ "copied": "Copied",
+ "copy": "Copy",
+ "delete-column": "Delete Row",
+ "delete-row": "Delete Column",
+ "devtools": "DevTools",
+ "down": "Down",
+ "downloadTip": "The browser does not support the download function",
+ "edit": "Edit",
+ "edit-mode": "Toggle Edit Mode",
+ "emoji": "Emoji",
+ "export": "Export",
+ "fileTypeError": "file type is error",
+ "footnoteRef": "Footnote Ref",
+ "fullscreen": "Toggle Fullscreen",
+ "generate": "Generating",
+ "headings": "Headings",
+ "help": "Help",
+ "imageURL": "image URL",
+ "indent": "Indent",
+ "info": "Info",
+ "inline-code": "Inline Code",
+ "insert-after": "Insert line after",
+ "insert-before": "Insert line Before",
+ "insertColumnLeft": "Insert 1 left",
+ "insertColumnRight": "Insert 1 right",
+ "insertRowAbove": "Insert 1 above",
+ "insertRowBelow": "Insert 1 below",
+ "instantRendering": "Instant Rendering",
+ "italic": "Italic",
+ "language": "Language",
+ "line": "Line",
+ "link": "Link",
+ "linkRef": "Link Ref",
+ "list": "List",
+ "more": "More",
+ "nameEmpty": "Name is empty",
+ "ordered-list": "Order List",
+ "outdent": "Outdent",
+ "outline": "Outline",
+ "over": "over",
+ "performanceTip": "Real-time preview requires ${x}ms, you can close it",
+ "preview": "Preview",
+ "quote": "Quote",
+ "record": "Start Record/End Record",
+ "record-tip": "The device does not support recording",
+ "recording": "recording...",
+ "redo": "Redo",
+ "remove": "Remove",
+ "row": "Row",
+ "spin": "Spin",
+ "splitView": "Split View",
+ "strike": "Strike",
+ "table": "Table",
+ "textIsNotEmpty": "text(no empty)",
+ "title": "Title",
+ "tooltipText": "Tooltip text",
+ "undo": "Undo",
+ "up": "Up",
+ "update": "Update",
+ "upload": "Upload image or file",
+ "uploadError": "upload error",
+ "uploading": "uploading...",
+ "wysiwyg": "WYSIWYG"
+}
diff --git a/src/js/i18n/ja_JP.js b/src/js/i18n/ja_JP.js
new file mode 100644
index 000000000..07794468e
--- /dev/null
+++ b/src/js/i18n/ja_JP.js
@@ -0,0 +1,79 @@
+window.VditorI18n = {
+ "alignCenter": "中央",
+ "alignLeft": "左側",
+ "alignRight": "右側",
+ "alternateText": "イメージタグ",
+ "bold": "太く",
+ "both": "エディター & プレビュー",
+ "check": "チェックリスト",
+ "close": "閉じる",
+ "code": "コードブロック挿入",
+ "code-theme": "コードブロックテーマ",
+ "column": "行列",
+ "comment": "コメント",
+ "confirm": "確認",
+ "content-theme": "コンテンツテーマ",
+ "copied": "コピー完了",
+ "copy": "コピー",
+ "delete-column": "列 消去",
+ "delete-row": "行 消去",
+ "devtools": "開発ツール",
+ "down": "ダウンロード",
+ "downloadTip": "ブラウザがダウンロード機能をサポートしていません。",
+ "edit": "修正",
+ "edit-mode": "編集モード",
+ "emoji": "絵文字",
+ "export": "書き出し",
+ "fileTypeError": "サポートしていません。",
+ "footnoteRef": "脚注参照",
+ "fullscreen": "全体画面",
+ "generate": "作成する",
+ "headings": "タイトル大きさ",
+ "help": "ヘルプ",
+ "imageURL": "イメージ URL",
+ "indent": "字下げ",
+ "info": "情報",
+ "inline-code": "インラインコード",
+ "insert-after": "ブロックの後ろに入力",
+ "insert-before": "ブロックの前に入力",
+ "insertColumnLeft": "左側に列を挿入",
+ "insertColumnRight": "右側に列を挿入",
+ "insertRowAbove": "上に行を挿入",
+ "insertRowBelow": "下に行を挿入",
+ "instantRendering": "インスタントレンダリング",
+ "italic": "斜体",
+ "language": "言語",
+ "line": "段落分割",
+ "link": "リンク",
+ "linkRef": "リンク参照",
+ "list": "リスト",
+ "more": "詳しく見る",
+ "nameEmpty": "名前が入力されていません。",
+ "ordered-list": "順序のあるリスト",
+ "outdent": "ぶら下げインデント",
+ "outline": "概要",
+ "over": "オーバー",
+ "performanceTip": "リアルタイムプレビューには、${x}msが必要でエディター/プレビューボタンをクリックして閉じる事が出来ます。",
+ "preview": "プレビュー",
+ "quote": "引用段落",
+ "record": "録音開始/録音終了",
+ "record-tip": "録音がサポートされていません。",
+ "recording": "録音中...",
+ "redo": "戻る",
+ "remove": "消去",
+ "row": "列",
+ "spin": "スピン",
+ "splitView": "マークダウン",
+ "strike": "取り消し線",
+ "table": "表 挿入",
+ "textIsNotEmpty": "テキスト(no empty)",
+ "title": "題名",
+ "tooltipText": "ツールチップ",
+ "undo": "取り消す",
+ "up": "戻る",
+ "update": "アップデート",
+ "upload": "イメージをダウンロードする",
+ "uploadError": "アップロード失敗",
+ "uploading": "アップロード中",
+ "wysiwyg": "ウィジウィグ",
+}
diff --git a/src/js/i18n/ko_KR.js b/src/js/i18n/ko_KR.js
new file mode 100644
index 000000000..639d23adc
--- /dev/null
+++ b/src/js/i18n/ko_KR.js
@@ -0,0 +1,79 @@
+window.VditorI18n = {
+ "alignCenter": "가운데",
+ "alignLeft": "왼쪽",
+ "alignRight": "오른쪽",
+ "alternateText": "이미지 태그",
+ "bold": "굵게",
+ "both": "에디터 & 미리보기",
+ "check": "체크박스",
+ "close": "닫기",
+ "code": "코드블럭삽입",
+ "code-theme": "코드블럭테마",
+ "column": "행",
+ "comment": "코멘트",
+ "confirm": "확인",
+ "content-theme": "컨텐츠테마",
+ "copied": "복사완료",
+ "copy": "복사",
+ "delete-column": "열 삭제",
+ "delete-row": "행 삭제",
+ "devtools": "개발툴",
+ "down": "다운",
+ "downloadTip": "브라우저가 다운로드 기능을 지원하지 않습니다",
+ "edit": "수정",
+ "edit-mode": "편집모드",
+ "emoji": "이모지",
+ "export": "내보내기",
+ "fileTypeError": "지원하지않습니다.",
+ "footnoteRef": "각주참조",
+ "fullscreen": "전체화면",
+ "generate": "생성",
+ "headings": "제목크기",
+ "help": "도움말",
+ "imageURL": "이미지 URL",
+ "indent": "들여쓰기",
+ "info": "정보",
+ "inline-code": "인라인코드",
+ "insert-after": "블락 뒤로 입력",
+ "insert-before": "블락 앞으로 입력",
+ "insertColumnLeft": "왼쪽에 열 삽입",
+ "insertColumnRight": "오른쪽에 열 삽입",
+ "insertRowAbove": "위에 행 삽입",
+ "insertRowBelow": "아래에 행 삽입",
+ "instantRendering": "타이포라",
+ "italic": "기울임꼴",
+ "language": "언어",
+ "line": "문단나눔",
+ "link": "링크",
+ "linkRef": "링크 참조",
+ "list": "순서없는 목록",
+ "more": "더보기",
+ "nameEmpty": "이름이 비어있습니다.",
+ "ordered-list": "순서있는 목록",
+ "outdent": "내어쓰기",
+ "outline": "개요",
+ "over": "오버",
+ "performanceTip": "실시간 미리보기에는 ${x}ms가 필요하며 에디터/미리보기 버튼을 클릭하여 닫을 수 있습니다.",
+ "preview": "미리보기",
+ "quote": "인용단락",
+ "record": "녹음시작/녹음종료",
+ "record-tip": "녹음을 지원하지 않습니다.",
+ "recording": "녹음중...",
+ "redo": "되돌리기",
+ "remove": "삭제",
+ "row": "열",
+ "spin": "회전",
+ "splitView": "마크다운",
+ "strike": "취소선",
+ "table": "표삽입",
+ "textIsNotEmpty": "텍스트(no empty)",
+ "title": "표제",
+ "tooltipText": "툴팁",
+ "undo": "취소하기",
+ "up": "위로",
+ "update": "업데이트",
+ "upload": "이미지 업로드하기",
+ "uploadError": "업로드 실패",
+ "uploading": "업로드중...",
+ "wysiwyg": "위지위그",
+}
diff --git a/src/js/i18n/ru_RU.js b/src/js/i18n/ru_RU.js
new file mode 100644
index 000000000..5130901ec
--- /dev/null
+++ b/src/js/i18n/ru_RU.js
@@ -0,0 +1,79 @@
+window.VditorI18n = {
+ "alignCenter": "Выровнять по центру",
+ "alignLeft": "Выровнять по левому краю",
+ "alignRight": "Выровнять по правому краю",
+ "alternateText": "Альтернативный текст",
+ "bold": "Полужирный текст",
+ "both": "Редактор с предпросмотром",
+ "check": "Список задач",
+ "close": "Закрыть",
+ "code": "Блок кода",
+ "code-theme": "Тема отображения блока кода",
+ "column": "Количество столбцов",
+ "comment": "Комментарий",
+ "confirm": "Подтвердить",
+ "content-theme": "Тема отображения контента",
+ "copied": "Скопировано",
+ "copy": "Копировать",
+ "delete-column": "Удалить столбец",
+ "delete-row": "Удалить строку",
+ "devtools": "Граф документа",
+ "down": "Переместить вниз",
+ "downloadTip": "Браузер не поддерживает функции загрузки",
+ "edit": "Редактирование",
+ "edit-mode": "Переключить режим редактирования",
+ "emoji": "Смайлы",
+ "export": "Экспорт",
+ "fileTypeError": "Ошибка типа файла",
+ "footnoteRef": "Сноска",
+ "fullscreen": "Переключиться на полный экран",
+ "generate": "Генерация",
+ "headings": "Заголовки",
+ "help": "Помощь",
+ "imageURL": "Ссылка на картинку",
+ "indent": "Отступ",
+ "info": "Информация о редакторе",
+ "inline-code": "Встроенный код ",
+ "insert-after": "Вставить линию после этой строки",
+ "insert-before": "Вставить линию перед этой строкой",
+ "insertColumnLeft": "Вставить столбец слева",
+ "insertColumnRight": "Вставить столбец справа",
+ "insertRowAbove": "Вставить строку сверху",
+ "insertRowBelow": "Вставить строку снизу",
+ "instantRendering": "Мгновенный рендеринг",
+ "italic": "Курсив",
+ "language": "Синтаксис",
+ "line": "Линия",
+ "link": "Ссылка",
+ "linkRef": "Вставить ссылку",
+ "list": "Список",
+ "more": "Дополнительно",
+ "nameEmpty": "Имя пустое",
+ "ordered-list": "Упорядоченный список",
+ "outdent": "Выступ",
+ "outline": "Содержание",
+ "over": "Над",
+ "performanceTip": "Предварительный просмотр в реальном времени требует ${x}мс, вы можете закрыть его",
+ "preview": "Предпросмотр",
+ "quote": "Цитата",
+ "record": "Начать запись/Завершить запись",
+ "record-tip": "Устройство не поддерживает запись",
+ "recording": "Запись...",
+ "redo": "Вернуть",
+ "remove": "Удалить",
+ "row": "Количество строк",
+ "spin": "Прокрутка",
+ "splitView": "Разделенный просмотр",
+ "strike": "Зачеркнутый текст",
+ "table": "Таблица",
+ "textIsNotEmpty": "Текст (непустой)",
+ "title": "Заголовок",
+ "tooltipText": "Текст всплывающей подсказки",
+ "undo": "Отменить",
+ "up": "Переместить вверх",
+ "update": "Обновить",
+ "upload": "Загрузить изображение или файл",
+ "uploadError": "Ошибка загрузки",
+ "uploading": "Загрузка...",
+ "wysiwyg": "Редактор WYSIWYG",
+}
diff --git a/src/js/i18n/zh_CN.js b/src/js/i18n/zh_CN.js
new file mode 100644
index 000000000..dfbcc7682
--- /dev/null
+++ b/src/js/i18n/zh_CN.js
@@ -0,0 +1,79 @@
+window.VditorI18n = {
+ "alignCenter": "居中",
+ "alignLeft": "居左",
+ "alignRight": "居右",
+ "alternateText": "替代文本",
+ "bold": "粗体",
+ "both": "编辑 & 预览",
+ "check": "任务列表",
+ "close": "关闭",
+ "code": "代码块",
+ "code-theme": "代码块主题预览",
+ "column": "列",
+ "comment": "评论",
+ "confirm": "确定",
+ "content-theme": "内容主题预览",
+ "copied": "已复制",
+ "copy": "复制",
+ "delete-column": "删除列",
+ "delete-row": "删除行",
+ "devtools": "开发者工具",
+ "down": "下",
+ "downloadTip": "该浏览器不支持下载功能",
+ "edit": "编辑",
+ "edit-mode": "切换编辑模式",
+ "emoji": "表情",
+ "export": "导出",
+ "fileTypeError": "文件类型不允许上传",
+ "footnoteRef": "脚注标识",
+ "fullscreen": "全屏切换",
+ "generate": "生成中",
+ "headings": "标题",
+ "help": "帮助",
+ "imageURL": "图片地址",
+ "indent": "列表缩进",
+ "info": "关于",
+ "inline-code": "行内代码",
+ "insert-after": "末尾插入行",
+ "insert-before": "起始插入行",
+ "insertColumnLeft": "在左边插入一列",
+ "insertColumnRight": "在右边插入一列",
+ "insertRowAbove": "在上方插入一行",
+ "insertRowBelow": "在下方插入一行",
+ "instantRendering": "即时渲染",
+ "italic": "斜体",
+ "language": "语言",
+ "line": "分隔线",
+ "link": "链接",
+ "linkRef": "引用标识",
+ "list": "无序列表",
+ "more": "更多",
+ "nameEmpty": "文件名不能为空",
+ "ordered-list": "有序列表",
+ "outdent": "列表反向缩进",
+ "outline": "大纲",
+ "over": "超过",
+ "performanceTip": "实时预览需 ${x}ms,可点击编辑 & 预览按钮进行关闭",
+ "preview": "预览",
+ "quote": "引用",
+ "record": "开始录音/结束录音",
+ "record-tip": "该设备不支持录音功能",
+ "recording": "录音中...",
+ "redo": "重做",
+ "remove": "删除",
+ "row": "行",
+ "spin": "旋转",
+ "splitView": "分屏预览",
+ "strike": "删除线",
+ "table": "表格",
+ "textIsNotEmpty": "文本(不能为空)",
+ "title": "标题",
+ "tooltipText": "提示文本",
+ "undo": "撤销",
+ "up": "上",
+ "update": "更新",
+ "upload": "上传图片或文件",
+ "uploadError": "上传错误",
+ "uploading": "上传中...",
+ "wysiwyg": "所见即所得",
+}
diff --git a/src/js/i18n/zh_TW.js b/src/js/i18n/zh_TW.js
new file mode 100644
index 000000000..921bf48fb
--- /dev/null
+++ b/src/js/i18n/zh_TW.js
@@ -0,0 +1,79 @@
+window.VditorI18n = {
+ "alignCenter": "置中",
+ "alignLeft": "置左",
+ "alignRight": "置右",
+ "alternateText": "替代文字",
+ "bold": "粗體",
+ "both": "編輯 & 預覽",
+ "check": "任務列表",
+ "close": "關閉",
+ "code": "代碼塊",
+ "code-theme": "代碼塊主題預覽",
+ "column": "欄",
+ "comment": "評論",
+ "confirm": "確定",
+ "content-theme": "內容主題預覽",
+ "copied": "已複製",
+ "copy": "複製",
+ "delete-column": "刪除欄",
+ "delete-row": "刪除列",
+ "devtools": "開發者工具",
+ "down": "下",
+ "downloadTip": "該瀏覽器不支持下載功能",
+ "edit": "編輯",
+ "edit-mode": "切換編輯模式",
+ "emoji": "表情",
+ "export": "匯出",
+ "fileTypeError": "檔案類型不允許上傳",
+ "footnoteRef": "腳註參考",
+ "fullscreen": "全螢幕切換",
+ "generate": "生成中",
+ "headings": "標題",
+ "help": "幫助",
+ "imageURL": "圖片位址",
+ "indent": "列表縮排",
+ "info": "關於",
+ "inline-code": "行內代碼",
+ "insert-after": "末尾插入列",
+ "insert-before": "起始插入列",
+ "insertColumnLeft": "在左邊插入一欄",
+ "insertColumnRight": "在右邊插入一欄",
+ "insertRowAbove": "在上方插入一行",
+ "insertRowBelow": "在下方插入一行",
+ "instantRendering": "即時渲染",
+ "italic": "斜體",
+ "language": "語言",
+ "line": "分隔線",
+ "link": "連結",
+ "linkRef": "連結參考",
+ "list": "無序列表",
+ "more": "更多",
+ "nameEmpty": "文件名不能為空",
+ "ordered-list": "有序列表",
+ "outdent": "列表反向縮排",
+ "outline": "大綱",
+ "over": "超過",
+ "performanceTip": "即時預覽需 ${x}ms,可點擊編輯 & 預覽按鈕進行關閉",
+ "preview": "預覽",
+ "quote": "引用",
+ "record": "開始錄音/結束錄音",
+ "record-tip": "該設備不支持錄音功能",
+ "recording": "錄音中...",
+ "redo": "重做",
+ "remove": "刪除",
+ "row": "列",
+ "spin": "旋轉",
+ "splitView": "分割預覽",
+ "strike": "刪除縣",
+ "table": "表格",
+ "textIsNotEmpty": "文字(不能為空)",
+ "title": "標題",
+ "tooltipText": "提示文字",
+ "undo": "撤銷",
+ "up": "上",
+ "update": "更新",
+ "upload": "上傳圖片或文件",
+ "uploadError": "上傳錯誤",
+ "uploading": "上傳中...",
+ "wysiwyg": "所見即所得",
+}
diff --git a/src/ts/export/index.ts b/src/ts/export/index.ts
index 187f9d77e..cd5a3863e 100644
--- a/src/ts/export/index.ts
+++ b/src/ts/export/index.ts
@@ -1,4 +1,3 @@
-import {i18n} from "../i18n";
import {getHTML} from "../markdown/getHTML";
import {getMarkdown} from "../markdown/getMarkdown";
@@ -13,7 +12,7 @@ export const download = (vditor: IVditor, content: string, filename: string) =>
aElement.click();
aElement.remove();
} else {
- vditor.tip.show(!!vditor.options.lang ? i18n[vditor.options.lang].downloadTip : vditor.options.i18n.downloadTip, 0);
+ vditor.tip.show(window.VditorI18n.downloadTip, 0);
}
};
@@ -23,7 +22,7 @@ export const exportMarkdown = (vditor: IVditor) => {
};
export const exportPDF = (vditor: IVditor) => {
- vditor.tip.show(!!vditor.options.lang ? i18n[vditor.options.lang].generate : vditor.options.i18n.generate, 3800);
+ vditor.tip.show(window.VditorI18n.generate, 3800);
const iframe = document.querySelector("iframe");
iframe.contentDocument.open();
iframe.contentDocument.write(`
diff --git a/src/ts/i18n/index.ts b/src/ts/i18n/index.ts
deleted file mode 100644
index a7da72306..000000000
--- a/src/ts/i18n/index.ts
+++ /dev/null
@@ -1,476 +0,0 @@
-export const i18n: II18n = {
- en_US: {
- "alignCenter": "Center",
- "alignLeft": "Left",
- "alignRight": "Right",
- "alternateText": "Alternate text",
- "bold": "Blod",
- "both": "editor & preview",
- "check": "Task List",
- "close": "Close",
- "code": "Code Block",
- "code-theme": "Code Block Theme Preview",
- "column": "Column",
- "comment": "Comment",
- "confirm": "Confirm",
- "content-theme": "Content Theme Preview",
- "copied": "Copied",
- "copy": "Copy",
- "delete-column": "Delete Row",
- "delete-row": "Delete Column",
- "devtools": "DevTools",
- "down": "Down",
- "downloadTip": "The browser does not support the download function",
- "edit": "Edit",
- "edit-mode": "Toggle Edit Mode",
- "emoji": "Emoji",
- "export": "Export",
- "fileTypeError": "file type is error",
- "footnoteRef": "Footnote Ref",
- "fullscreen": "Toggle Fullscreen",
- "generate": "Generating",
- "headings": "Headings",
- "help": "Help",
- "imageURL": "image URL",
- "indent": "Indent",
- "info": "Info",
- "inline-code": "Inline Code",
- "insert-after": "Insert line after",
- "insert-before": "Insert line Before",
- "insertColumnLeft": "Insert 1 left",
- "insertColumnRight": "Insert 1 right",
- "insertRowAbove": "Insert 1 above",
- "insertRowBelow": "Insert 1 below",
- "instantRendering": "Instant Rendering",
- "italic": "Italic",
- "language": "Language",
- "line": "Line",
- "link": "Link",
- "linkRef": "Link Ref",
- "list": "List",
- "more": "More",
- "nameEmpty": "Name is empty",
- "ordered-list": "Order List",
- "outdent": "Outdent",
- "outline": "Outline",
- "over": "over",
- "performanceTip": "Real-time preview requires ${x}ms, you can close it",
- "preview": "Preview",
- "quote": "Quote",
- "record": "Start Record/End Record",
- "record-tip": "The device does not support recording",
- "recording": "recording...",
- "redo": "Redo",
- "remove": "Remove",
- "row": "Row",
- "spin": "Spin",
- "splitView": "Split View",
- "strike": "Strike",
- "table": "Table",
- "textIsNotEmpty": "text(no empty)",
- "title": "Title",
- "tooltipText": "Tooltip text",
- "undo": "Undo",
- "up": "Up",
- "update": "Update",
- "upload": "Upload image or file",
- "uploadError": "upload error",
- "uploading": "uploading...",
- "wysiwyg": "WYSIWYG",
- },
- ja_JP: {
- "alignCenter": "中央",
- "alignLeft": "左側",
- "alignRight": "右側",
- "alternateText": "イメージタグ",
- "bold": "太く",
- "both": "エディター & プレビュー",
- "check": "チェックリスト",
- "close": "閉じる",
- "code": "コードブロック挿入",
- "code-theme": "コードブロックテーマ",
- "column": "行列",
- "comment": "コメント",
- "confirm": "確認",
- "content-theme": "コンテンツテーマ",
- "copied": "コピー完了",
- "copy": "コピー",
- "delete-column": "列 消去",
- "delete-row": "行 消去",
- "devtools": "開発ツール",
- "down": "ダウンロード",
- "downloadTip": "ブラウザがダウンロード機能をサポートしていません。",
- "edit": "修正",
- "edit-mode": "編集モード",
- "emoji": "絵文字",
- "export": "書き出し",
- "fileTypeError": "サポートしていません。",
- "footnoteRef": "脚注参照",
- "fullscreen": "全体画面",
- "generate": "作成する",
- "headings": "タイトル大きさ",
- "help": "ヘルプ",
- "imageURL": "イメージ URL",
- "indent": "字下げ",
- "info": "情報",
- "inline-code": "インラインコード",
- "insert-after": "ブロックの後ろに入力",
- "insert-before": "ブロックの前に入力",
- "insertColumnLeft": "左側に列を挿入",
- "insertColumnRight": "右側に列を挿入",
- "insertRowAbove": "上に行を挿入",
- "insertRowBelow": "下に行を挿入",
- "instantRendering": "インスタントレンダリング",
- "italic": "斜体",
- "language": "言語",
- "line": "段落分割",
- "link": "リンク",
- "linkRef": "リンク参照",
- "list": "リスト",
- "more": "詳しく見る",
- "nameEmpty": "名前が入力されていません。",
- "ordered-list": "順序のあるリスト",
- "outdent": "ぶら下げインデント",
- "outline": "概要",
- "over": "オーバー",
- "performanceTip": "リアルタイムプレビューには、${x}msが必要でエディター/プレビューボタンをクリックして閉じる事が出来ます。",
- "preview": "プレビュー",
- "quote": "引用段落",
- "record": "録音開始/録音終了",
- "record-tip": "録音がサポートされていません。",
- "recording": "録音中...",
- "redo": "戻る",
- "remove": "消去",
- "row": "列",
- "spin": "スピン",
- "splitView": "マークダウン",
- "strike": "取り消し線",
- "table": "表 挿入",
- "textIsNotEmpty": "テキスト(no empty)",
- "title": "題名",
- "tooltipText": "ツールチップ",
- "undo": "取り消す",
- "up": "戻る",
- "update": "アップデート",
- "upload": "イメージをダウンロードする",
- "uploadError": "アップロード失敗",
- "uploading": "アップロード中",
- "wysiwyg": "ウィジウィグ",
- },
- ko_KR: {
- "alignCenter": "가운데",
- "alignLeft": "왼쪽",
- "alignRight": "오른쪽",
- "alternateText": "이미지 태그",
- "bold": "굵게",
- "both": "에디터 & 미리보기",
- "check": "체크박스",
- "close": "닫기",
- "code": "코드블럭삽입",
- "code-theme": "코드블럭테마",
- "column": "행",
- "comment": "코멘트",
- "confirm": "확인",
- "content-theme": "컨텐츠테마",
- "copied": "복사완료",
- "copy": "복사",
- "delete-column": "열 삭제",
- "delete-row": "행 삭제",
- "devtools": "개발툴",
- "down": "다운",
- "downloadTip": "브라우저가 다운로드 기능을 지원하지 않습니다",
- "edit": "수정",
- "edit-mode": "편집모드",
- "emoji": "이모지",
- "export": "내보내기",
- "fileTypeError": "지원하지않습니다.",
- "footnoteRef": "각주참조",
- "fullscreen": "전체화면",
- "generate": "생성",
- "headings": "제목크기",
- "help": "도움말",
- "imageURL": "이미지 URL",
- "indent": "들여쓰기",
- "info": "정보",
- "inline-code": "인라인코드",
- "insert-after": "블락 뒤로 입력",
- "insert-before": "블락 앞으로 입력",
- "insertColumnLeft": "왼쪽에 열 삽입",
- "insertColumnRight": "오른쪽에 열 삽입",
- "insertRowAbove": "위에 행 삽입",
- "insertRowBelow": "아래에 행 삽입",
- "instantRendering": "타이포라",
- "italic": "기울임꼴",
- "language": "언어",
- "line": "문단나눔",
- "link": "링크",
- "linkRef": "링크 참조",
- "list": "순서없는 목록",
- "more": "더보기",
- "nameEmpty": "이름이 비어있습니다.",
- "ordered-list": "순서있는 목록",
- "outdent": "내어쓰기",
- "outline": "개요",
- "over": "오버",
- "performanceTip": "실시간 미리보기에는 ${x}ms가 필요하며 에디터/미리보기 버튼을 클릭하여 닫을 수 있습니다.",
- "preview": "미리보기",
- "quote": "인용단락",
- "record": "녹음시작/녹음종료",
- "record-tip": "녹음을 지원하지 않습니다.",
- "recording": "녹음중...",
- "redo": "되돌리기",
- "remove": "삭제",
- "row": "열",
- "spin": "회전",
- "splitView": "마크다운",
- "strike": "취소선",
- "table": "표삽입",
- "textIsNotEmpty": "텍스트(no empty)",
- "title": "표제",
- "tooltipText": "툴팁",
- "undo": "취소하기",
- "up": "위로",
- "update": "업데이트",
- "upload": "이미지 업로드하기",
- "uploadError": "업로드 실패",
- "uploading": "업로드중...",
- "wysiwyg": "위지위그",
- },
- ru_RU: {
- "alignCenter": "Выровнять по центру",
- "alignLeft": "Выровнять по левому краю",
- "alignRight": "Выровнять по правому краю",
- "alternateText": "Альтернативный текст",
- "bold": "Полужирный текст",
- "both": "Редактор с предпросмотром",
- "check": "Список задач",
- "close": "Закрыть",
- "code": "Блок кода",
- "code-theme": "Тема отображения блока кода",
- "column": "Количество столбцов",
- "comment": "Комментарий",
- "confirm": "Подтвердить",
- "content-theme": "Тема отображения контента",
- "copied": "Скопировано",
- "copy": "Копировать",
- "delete-column": "Удалить столбец",
- "delete-row": "Удалить строку",
- "devtools": "Граф документа",
- "down": "Переместить вниз",
- "downloadTip": "Браузер не поддерживает функции загрузки",
- "edit": "Редактирование",
- "edit-mode": "Переключить режим редактирования",
- "emoji": "Смайлы",
- "export": "Экспорт",
- "fileTypeError": "Ошибка типа файла",
- "footnoteRef": "Сноска",
- "fullscreen": "Переключиться на полный экран",
- "generate": "Генерация",
- "headings": "Заголовки",
- "help": "Помощь",
- "imageURL": "Ссылка на картинку",
- "indent": "Отступ",
- "info": "Информация о редакторе",
- "inline-code": "Встроенный код ",
- "insert-after": "Вставить линию после этой строки",
- "insert-before": "Вставить линию перед этой строкой",
- "insertColumnLeft": "Вставить столбец слева",
- "insertColumnRight": "Вставить столбец справа",
- "insertRowAbove": "Вставить строку сверху",
- "insertRowBelow": "Вставить строку снизу",
- "instantRendering": "Мгновенный рендеринг",
- "italic": "Курсив",
- "language": "Синтаксис",
- "line": "Линия",
- "link": "Ссылка",
- "linkRef": "Вставить ссылку",
- "list": "Список",
- "more": "Дополнительно",
- "nameEmpty": "Имя пустое",
- "ordered-list": "Упорядоченный список",
- "outdent": "Выступ",
- "outline": "Содержание",
- "over": "Над",
- "performanceTip": "Предварительный просмотр в реальном времени требует ${x}мс, вы можете закрыть его",
- "preview": "Предпросмотр",
- "quote": "Цитата",
- "record": "Начать запись/Завершить запись",
- "record-tip": "Устройство не поддерживает запись",
- "recording": "Запись...",
- "redo": "Вернуть",
- "remove": "Удалить",
- "row": "Количество строк",
- "spin": "Прокрутка",
- "splitView": "Разделенный просмотр",
- "strike": "Зачеркнутый текст",
- "table": "Таблица",
- "textIsNotEmpty": "Текст (непустой)",
- "title": "Заголовок",
- "tooltipText": "Текст всплывающей подсказки",
- "undo": "Отменить",
- "up": "Переместить вверх",
- "update": "Обновить",
- "upload": "Загрузить изображение или файл",
- "uploadError": "Ошибка загрузки",
- "uploading": "Загрузка...",
- "wysiwyg": "Редактор WYSIWYG",
- },
- zh_CN: {
- "alignCenter": "居中",
- "alignLeft": "居左",
- "alignRight": "居右",
- "alternateText": "替代文本",
- "bold": "粗体",
- "both": "编辑 & 预览",
- "check": "任务列表",
- "close": "关闭",
- "code": "代码块",
- "code-theme": "代码块主题预览",
- "column": "列",
- "comment": "评论",
- "confirm": "确定",
- "content-theme": "内容主题预览",
- "copied": "已复制",
- "copy": "复制",
- "delete-column": "删除列",
- "delete-row": "删除行",
- "devtools": "开发者工具",
- "down": "下",
- "downloadTip": "该浏览器不支持下载功能",
- "edit": "编辑",
- "edit-mode": "切换编辑模式",
- "emoji": "表情",
- "export": "导出",
- "fileTypeError": "文件类型不允许上传",
- "footnoteRef": "脚注标识",
- "fullscreen": "全屏切换",
- "generate": "生成中",
- "headings": "标题",
- "help": "帮助",
- "imageURL": "图片地址",
- "indent": "列表缩进",
- "info": "关于",
- "inline-code": "行内代码",
- "insert-after": "末尾插入行",
- "insert-before": "起始插入行",
- "insertColumnLeft": "在左边插入一列",
- "insertColumnRight": "在右边插入一列",
- "insertRowAbove": "在上方插入一行",
- "insertRowBelow": "在下方插入一行",
- "instantRendering": "即时渲染",
- "italic": "斜体",
- "language": "语言",
- "line": "分隔线",
- "link": "链接",
- "linkRef": "引用标识",
- "list": "无序列表",
- "more": "更多",
- "nameEmpty": "文件名不能为空",
- "ordered-list": "有序列表",
- "outdent": "列表反向缩进",
- "outline": "大纲",
- "over": "超过",
- "performanceTip": "实时预览需 ${x}ms,可点击编辑 & 预览按钮进行关闭",
- "preview": "预览",
- "quote": "引用",
- "record": "开始录音/结束录音",
- "record-tip": "该设备不支持录音功能",
- "recording": "录音中...",
- "redo": "重做",
- "remove": "删除",
- "row": "行",
- "spin": "旋转",
- "splitView": "分屏预览",
- "strike": "删除线",
- "table": "表格",
- "textIsNotEmpty": "文本(不能为空)",
- "title": "标题",
- "tooltipText": "提示文本",
- "undo": "撤销",
- "up": "上",
- "update": "更新",
- "upload": "上传图片或文件",
- "uploadError": "上传错误",
- "uploading": "上传中...",
- "wysiwyg": "所见即所得",
- },
- zh_TW: {
- "alignCenter": "置中",
- "alignLeft": "置左",
- "alignRight": "置右",
- "alternateText": "替代文字",
- "bold": "粗體",
- "both": "編輯 & 預覽",
- "check": "任務列表",
- "close": "關閉",
- "code": "代碼塊",
- "code-theme": "代碼塊主題預覽",
- "column": "欄",
- "comment": "評論",
- "confirm": "確定",
- "content-theme": "內容主題預覽",
- "copied": "已複製",
- "copy": "複製",
- "delete-column": "刪除欄",
- "delete-row": "刪除列",
- "devtools": "開發者工具",
- "down": "下",
- "downloadTip": "該瀏覽器不支持下載功能",
- "edit": "編輯",
- "edit-mode": "切換編輯模式",
- "emoji": "表情",
- "export": "匯出",
- "fileTypeError": "檔案類型不允許上傳",
- "footnoteRef": "腳註參考",
- "fullscreen": "全螢幕切換",
- "generate": "生成中",
- "headings": "標題",
- "help": "幫助",
- "imageURL": "圖片位址",
- "indent": "列表縮排",
- "info": "關於",
- "inline-code": "行內代碼",
- "insert-after": "末尾插入列",
- "insert-before": "起始插入列",
- "insertColumnLeft": "在左邊插入一欄",
- "insertColumnRight": "在右邊插入一欄",
- "insertRowAbove": "在上方插入一行",
- "insertRowBelow": "在下方插入一行",
- "instantRendering": "即時渲染",
- "italic": "斜體",
- "language": "語言",
- "line": "分隔線",
- "link": "連結",
- "linkRef": "連結參考",
- "list": "無序列表",
- "more": "更多",
- "nameEmpty": "文件名不能為空",
- "ordered-list": "有序列表",
- "outdent": "列表反向縮排",
- "outline": "大綱",
- "over": "超過",
- "performanceTip": "即時預覽需 ${x}ms,可點擊編輯 & 預覽按鈕進行關閉",
- "preview": "預覽",
- "quote": "引用",
- "record": "開始錄音/結束錄音",
- "record-tip": "該設備不支持錄音功能",
- "recording": "錄音中...",
- "redo": "重做",
- "remove": "刪除",
- "row": "列",
- "spin": "旋轉",
- "splitView": "分割預覽",
- "strike": "刪除縣",
- "table": "表格",
- "textIsNotEmpty": "文字(不能為空)",
- "title": "標題",
- "tooltipText": "提示文字",
- "undo": "撤銷",
- "up": "上",
- "update": "更新",
- "upload": "上傳圖片或文件",
- "uploadError": "上傳錯誤",
- "uploading": "上傳中...",
- "wysiwyg": "所見即所得",
- }
-};
diff --git a/src/ts/markdown/codeRender.ts b/src/ts/markdown/codeRender.ts
index 97ea8e789..e729d9d39 100644
--- a/src/ts/markdown/codeRender.ts
+++ b/src/ts/markdown/codeRender.ts
@@ -1,7 +1,6 @@
-import {i18n} from "../i18n/index";
import {code160to32} from "../util/code160to32";
-export const codeRender = (element: HTMLElement, options: IOptions | IPreviewOptions, lang: keyof II18n = "zh_CN") => {
+export const codeRender = (element: HTMLElement) => {
element.querySelectorAll("pre > code").forEach((e: HTMLElement, index: number) => {
if (e.parentElement.classList.contains("vditor-wysiwyg__pre") ||
e.parentElement.classList.contains("vditor-ir__marker--pre")) {
@@ -11,7 +10,7 @@ export const codeRender = (element: HTMLElement, options: IOptions | IPreviewOpt
e.classList.contains("language-echarts") || e.classList.contains("language-mindmap") ||
e.classList.contains("language-plantuml") ||
e.classList.contains("language-abc") || e.classList.contains("language-graphviz") ||
- e.classList.contains("language-math") ) {
+ e.classList.contains("language-math")) {
return;
}
@@ -36,11 +35,11 @@ export const codeRender = (element: HTMLElement, options: IOptions | IPreviewOpt
const divElement = document.createElement("div");
divElement.className = "vditor-copy";
- divElement.innerHTML = ``;
+ `this.setAttribute('aria-label', '${window.VditorI18n.copied}')">`;
const textarea = document.createElement("textarea");
textarea.value = code160to32(codeText);
divElement.insertAdjacentElement("afterbegin", textarea);
diff --git a/src/ts/markdown/previewRender.ts b/src/ts/markdown/previewRender.ts
index c1bb51348..6aa09af70 100644
--- a/src/ts/markdown/previewRender.ts
+++ b/src/ts/markdown/previewRender.ts
@@ -1,5 +1,4 @@
import {Constants} from "../constants";
-import { i18n } from "../i18n";
import {setContentTheme} from "../ui/setContentTheme";
import {addScript} from "../util/addScript";
import {hasClosestByClassName, hasClosestByMatchTag} from "../util/hasClosest";
@@ -31,13 +30,11 @@ const mergeOptions = (options?: IPreviewOptions) => {
hljs: Constants.HLJS_OPTIONS,
icon: "ant",
lang: "zh_CN",
- i18n: i18n["zh_CN"],
markdown: Constants.MARKDOWN_OPTIONS,
math: Constants.MATH_OPTIONS,
mode: "light",
speech: {
enable: false,
- lang: "zh_CN"
},
theme: Constants.THEME_OPTIONS,
};
@@ -105,7 +102,7 @@ export const previewRender = async (previewElement: HTMLDivElement, markdown: st
abcRender(previewElement, mergedOptions.cdn);
mediaRender(previewElement);
if (mergedOptions.speech.enable) {
- speechRender(previewElement, mergedOptions.speech.lang, mergedOptions.lang);
+ speechRender(previewElement);
}
if (mergedOptions.anchor !== 0) {
anchorRender(mergedOptions.anchor);
diff --git a/src/ts/markdown/speechRender.ts b/src/ts/markdown/speechRender.ts
index 8ae322ece..7f6630665 100644
--- a/src/ts/markdown/speechRender.ts
+++ b/src/ts/markdown/speechRender.ts
@@ -5,9 +5,7 @@ declare global {
vditorSpeechRange: Range;
}
}
-export const speechRender = (element: HTMLElement, speechLang: string = 'zh_CN', lang: keyof II18n | string = "zh_CN") => {
- // 做一个中文语音兜底
- lang = !!lang ? lang : speechLang
+export const speechRender = (element: HTMLElement, lang: keyof II18n = "zh_CN") => {
if (typeof speechSynthesis === "undefined" || typeof SpeechSynthesisUtterance === "undefined") {
return;
}
diff --git a/src/ts/preview/image.ts b/src/ts/preview/image.ts
index 12e57aa5d..415b8f076 100644
--- a/src/ts/preview/image.ts
+++ b/src/ts/preview/image.ts
@@ -1,5 +1,3 @@
-import {i18n} from "../i18n";
-
export const previewImage = (oldImgElement: HTMLImageElement, options: IOptions , lang: keyof II18n = "zh_CN", theme = "classic") => {
const oldImgRect = oldImgElement.getBoundingClientRect();
const height = 36;
@@ -7,10 +5,10 @@ export const previewImage = (oldImgElement: HTMLImageElement, options: IOptions
- ${!!lang ? i18n[lang].spin : options.i18n.spin}
+ ${window.VditorI18n.spin}
- X ${!!lang ? i18n[lang].close : options.i18n.close}
+ X ${window.VditorI18n.close}
diff --git a/src/ts/preview/index.ts b/src/ts/preview/index.ts
index f2073de50..e20f1ae04 100644
--- a/src/ts/preview/index.ts
+++ b/src/ts/preview/index.ts
@@ -1,4 +1,3 @@
-import {i18n} from "../i18n/index";
import {abcRender} from "../markdown/abcRender";
import {chartRender} from "../markdown/chartRender";
import {codeRender} from "../markdown/codeRender";
@@ -199,17 +198,7 @@ export class Preview {
const time = (new Date().getTime() - startTime);
if ((new Date().getTime() - startTime) > 2600) {
// https://github.com/b3log/vditor/issues/67
- vditor.tip.show(
- !!vditor.options.lang
- ? i18n[vditor.options.lang].performanceTip.replace(
- "${x}",
- time.toString()
- )
- : vditor.options.i18n.performanceTip.replace(
- "${x}",
- time.toString()
- )
- );
+ vditor.tip.show(window.VditorI18n.performanceTip.replace("${x}", time.toString()));
vditor.preview.element.setAttribute("data-type", "renderPerformance");
} else if (vditor.preview.element.getAttribute("data-type") === "renderPerformance") {
vditor.tip.hide();
@@ -219,7 +208,7 @@ export class Preview {
if (cmtFocusElement) {
cmtFocusElement.classList.remove("vditor-comment--focus");
}
- codeRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options, vditor.options.lang);
+ codeRender(vditor.preview.element.lastElementChild as HTMLElement);
highlightRender(vditor.options.preview.hljs, vditor.preview.element.lastElementChild as HTMLElement,
vditor.options.cdn);
mermaidRender(vditor.preview.element.lastElementChild as HTMLElement, vditor.options.cdn, vditor.options.theme);
diff --git a/src/ts/toolbar/EditMode.ts b/src/ts/toolbar/EditMode.ts
index b5907f353..627e51f9e 100644
--- a/src/ts/toolbar/EditMode.ts
+++ b/src/ts/toolbar/EditMode.ts
@@ -1,5 +1,4 @@
import {Constants} from "../constants";
-import {i18n} from "../i18n";
import {processAfterRender} from "../ir/process";
import {getMarkdown} from "../markdown/getMarkdown";
import {mathRender} from "../markdown/mathRender";
@@ -157,9 +156,9 @@ export class EditMode extends MenuItem {
const panelElement = document.createElement("div");
panelElement.className = `vditor-hint${menuItem.level === 2 ? "" : " vditor-panel--arrow"}`;
- panelElement.innerHTML = `
-
-
`;
+ panelElement.innerHTML = `
+
+
`;
this.element.appendChild(panelElement);
diff --git a/src/ts/toolbar/MenuItem.ts b/src/ts/toolbar/MenuItem.ts
index 5bae7e3ed..e9fb4a148 100644
--- a/src/ts/toolbar/MenuItem.ts
+++ b/src/ts/toolbar/MenuItem.ts
@@ -1,5 +1,4 @@
import {Constants} from "../constants";
-import {i18n} from "../i18n/index";
import {processToolbar} from "../ir/process";
import {processToolbar as processToolbarSV} from "../sv/process";
import {getEventName} from "../util/compatibility";
@@ -19,8 +18,7 @@ export class MenuItem {
if (menuItem.level === 2) {
hotkey = menuItem.hotkey ? ` <${updateHotkeyTip(menuItem.hotkey)}>` : "";
}
- const tip = menuItem.tip ?
- menuItem.tip + hotkey : `${!!vditor.options.lang ? i18n[vditor.options.lang][menuItem.name] : vditor.options.i18n[menuItem.name]}${hotkey}`;
+ const tip = menuItem.tip ? menuItem.tip + hotkey : `${window.VditorI18n[menuItem.name]}${hotkey}`;
const tagName = menuItem.name === "upload" ? "div" : "button";
if (menuItem.level === 2) {
this.element.innerHTML = `<${tagName} data-type="${menuItem.name}">${tip}${tagName}>`;
diff --git a/src/ts/toolbar/Record.ts b/src/ts/toolbar/Record.ts
index 25caac53b..e5387d773 100644
--- a/src/ts/toolbar/Record.ts
+++ b/src/ts/toolbar/Record.ts
@@ -1,5 +1,4 @@
import {Constants} from "../constants";
-import {i18n} from "../i18n/index";
import {uploadFiles} from "../upload/index";
import {getEventName} from "../util/compatibility";
import {RecordMedia} from "../util/RecordMedia";
@@ -34,11 +33,11 @@ export class Record extends MenuItem {
mediaRecorder.cloneChannelData(left, right);
};
mediaRecorder.startRecordingNewWavFile();
- vditor.tip.show(!!vditor.options.lang ? i18n[vditor.options.lang].recording : vditor.options.i18n.recording);
+ vditor.tip.show(window.VditorI18n.recording);
editorElement.setAttribute("contenteditable", "false");
this.element.children[0].classList.add("vditor-menu--current");
}).catch(() => {
- vditor.tip.show(!!vditor.options.lang ? i18n[vditor.options.lang]["record-tip"] : vditor.options.i18n["record-tip"]);
+ vditor.tip.show(window.VditorI18n["record-tip"]);
});
return;
}
@@ -51,11 +50,7 @@ export class Record extends MenuItem {
uploadFiles(vditor, [file]);
this.element.children[0].classList.remove("vditor-menu--current");
} else {
- vditor.tip.show(
- !!vditor.options.lang
- ? i18n[vditor.options.lang].recording
- : vditor.options.i18n.recording
- );
+ vditor.tip.show(window.VditorI18n.recording);
editorElement.setAttribute("contenteditable", "false");
mediaRecorder.startRecordingNewWavFile();
this.element.children[0].classList.add("vditor-menu--current");
diff --git a/src/ts/upload/index.ts b/src/ts/upload/index.ts
index 8f663eb89..39fdfca52 100644
--- a/src/ts/upload/index.ts
+++ b/src/ts/upload/index.ts
@@ -1,4 +1,3 @@
-import {i18n} from "../i18n/index";
import {getEditorRange, setSelectionFocus} from "../util/selection";
import {getElement} from "./getElement";
import {setHeaders} from "./setHeaders";
@@ -28,12 +27,12 @@ const validateFile = (vditor: IVditor, files: File[]) => {
let validate = true;
if (!file.name) {
- errorTip += `
${!!lang ? i18n[lang].nameEmpty : options.i18n.nameEmpty}`;
+ errorTip += `
${window.VditorI18n.nameEmpty}`;
validate = false;
}
if (file.size > vditor.options.upload.max) {
- errorTip += `
${file.name} ${!!lang ? i18n[lang].over : options.i18n.over} ${vditor.options.upload.max / 1024 / 1024}M`;
+ errorTip += `
${file.name} ${window.VditorI18n.over} ${vditor.options.upload.max / 1024 / 1024}M`;
validate = false;
}
@@ -57,14 +56,14 @@ const validateFile = (vditor: IVditor, files: File[]) => {
});
if (!isAccept) {
- errorTip += `
${file.name} ${!!lang ? i18n[lang].fileTypeError : options.i18n.fileTypeError}`;
+ errorTip += `
${file.name} ${window.VditorI18n.fileTypeError}`;
validate = false;
}
}
if (validate) {
uploadFileList.push(file);
- uploadingStr += `
${filename} ${!!lang ? i18n[lang].uploading : options.i18n.uploading}`;
+ uploadingStr += `
${filename} ${window.VditorI18n.uploading}`;
}
}
@@ -88,11 +87,7 @@ const genUploadedLabel = (responseText: string, vditor: IVditor) => {
response.data.errFiles.forEach((data: string) => {
const lastIndex = data.lastIndexOf(".");
const filename = vditor.options.upload.filename(data.substr(0, lastIndex)) + data.substr(lastIndex);
- errorTip += `
${filename} ${
- !!vditor.options.lang
- ? i18n[vditor.options.lang].uploadError
- : vditor.options.i18n.uploadError
- }`;
+ errorTip += `
${filename} ${window.VditorI18n.uploadError}`;
});
errorTip += "";
}
diff --git a/src/ts/util/Options.ts b/src/ts/util/Options.ts
index 2f0fcb542..d6d3f52e2 100644
--- a/src/ts/util/Options.ts
+++ b/src/ts/util/Options.ts
@@ -1,5 +1,4 @@
import { Constants } from "../constants";
-import { i18n } from "../i18n";
import { merge } from "./merge";
export class Options {
@@ -30,12 +29,12 @@ export class Options {
emoji: {
"+1": "👍",
"-1": "👎",
- confused: "😕",
- eyes: "👀️",
- heart: "❤️",
- rocket: "🚀️",
- smile: "😄",
- tada: "🎉️",
+ "confused": "😕",
+ "eyes": "👀️",
+ "heart": "❤️",
+ "rocket": "🚀️",
+ "smile": "😄",
+ "tada": "🎉️",
},
emojiPath: `${Constants.CDN}/dist/images/emoji`,
extend: [],
@@ -43,7 +42,6 @@ export class Options {
},
icon: "ant",
lang: "zh_CN",
- i18n: i18n["zh_CN"],
mode: "ir",
outline: {
enable: false,
@@ -139,9 +137,7 @@ export class Options {
if (this.options.toolbar) {
this.options.toolbar = this.mergeToolbar(this.options.toolbar);
} else {
- this.options.toolbar = this.mergeToolbar(
- this.defaultOptions.toolbar
- );
+ this.options.toolbar = this.mergeToolbar(this.defaultOptions.toolbar);
}
if (this.options.preview?.theme?.list) {
this.defaultOptions.preview.theme.list = this.options.preview.theme.list;
@@ -158,7 +154,7 @@ export class Options {
if (mergedOptions.cache.enable && !mergedOptions.cache.id) {
throw new Error(
- "need options.cache.id, see https://ld246.com/article/1549638745630#options"
+ "need options.cache.id, see https://ld246.com/article/1549638745630#options",
);
}
@@ -420,11 +416,7 @@ export class Options {
typeof menuItem === "object" &&
defaultMenuItem.name === menuItem.name
) {
- currentMenuItem = Object.assign(
- {},
- defaultMenuItem,
- menuItem
- );
+ currentMenuItem = Object.assign({}, defaultMenuItem, menuItem,);
}
});
if (menuItem.toolbar) {
diff --git a/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts b/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts
index 7e07ee0ec..1c6dde355 100644
--- a/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts
+++ b/src/ts/wysiwyg/highlightToolbarWYSIWYG.ts
@@ -1,11 +1,10 @@
-import { Constants } from "../constants";
-import { i18n } from "../i18n";
-import { disableToolbar } from "../toolbar/setToolbar";
-import { enableToolbar } from "../toolbar/setToolbar";
-import { removeCurrentToolbar } from "../toolbar/setToolbar";
-import { setCurrentToolbar } from "../toolbar/setToolbar";
-import { isCtrl, updateHotkeyTip } from "../util/compatibility";
-import { scrollCenter } from "../util/editorCommonEvent";
+import {Constants} from "../constants";
+import {disableToolbar} from "../toolbar/setToolbar";
+import {enableToolbar} from "../toolbar/setToolbar";
+import {removeCurrentToolbar} from "../toolbar/setToolbar";
+import {setCurrentToolbar} from "../toolbar/setToolbar";
+import {isCtrl, updateHotkeyTip} from "../util/compatibility";
+import {scrollCenter} from "../util/editorCommonEvent";
import {
deleteColumn,
deleteRow,
@@ -23,15 +22,15 @@ import {
hasClosestByHeadings,
hasClosestByTag,
} from "../util/hasClosestByHeadings";
-import { processCodeRender } from "../util/processCode";
+import {processCodeRender} from "../util/processCode";
import {
getEditorRange,
selectIsEditor,
setRangeByWbr,
setSelectionFocus,
} from "../util/selection";
-import { afterRenderEvent } from "./afterRenderEvent";
-import { removeBlockElement } from "./processKeydown";
+import {afterRenderEvent} from "./afterRenderEvent";
+import {removeBlockElement} from "./processKeydown";
export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
clearTimeout(vditor.wysiwyg.hlToolbarTimeoutId);
@@ -57,14 +56,10 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
range.startOffset >= typeElement.childNodes.length
? typeElement.childNodes.length - 1
: range.startOffset
- ] as HTMLElement;
+ ] as HTMLElement;
}
- const footnotesElement = hasClosestByAttribute(
- typeElement,
- "data-type",
- "footnotes-block"
- );
+ const footnotesElement = hasClosestByAttribute(typeElement, "data-type", "footnotes-block");
if (footnotesElement) {
vditor.wysiwyg.popover.innerHTML = "";
genClose(footnotesElement, vditor);
@@ -118,18 +113,10 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
.forEach((item) => {
item.classList.remove("vditor-comment--focus");
});
- const commentElement = hasClosestByClassName(
- typeElement,
- "vditor-comment"
- );
+ const commentElement = hasClosestByClassName(typeElement, "vditor-comment");
if (commentElement) {
let ids = commentElement.getAttribute("data-cmtids").split(" ");
- if (
- ids.length > 1 &&
- commentElement.nextSibling.isSameNode(
- commentElement.nextElementSibling
- )
- ) {
+ if (ids.length > 1 && commentElement.nextSibling.isSameNode(commentElement.nextElementSibling)) {
const nextIds = commentElement.nextElementSibling
.getAttribute("data-cmtids")
.split(" ");
@@ -153,10 +140,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
if (aElement) {
setCurrentToolbar(vditor.toolbar.elements, ["link"]);
}
- const tableElement = hasClosestByMatchTag(
- typeElement,
- "TABLE"
- ) as HTMLTableElement;
+ const tableElement = hasClosestByMatchTag(typeElement, "TABLE") as HTMLTableElement;
const headingElement = hasClosestByHeadings(typeElement) as HTMLElement;
if (hasClosestByMatchTag(typeElement, "CODE")) {
if (hasClosestByMatchTag(typeElement, "PRE")) {
@@ -205,10 +189,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
}
// toc popover
- const tocElement = hasClosestByClassName(
- typeElement,
- "vditor-toc"
- ) as HTMLElement;
+ const tocElement = hasClosestByClassName(typeElement, "vditor-toc") as HTMLElement;
if (tocElement) {
vditor.wysiwyg.popover.innerHTML = "";
genClose(tocElement, vditor);
@@ -217,10 +198,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
}
// quote popover
- const blockquoteElement = hasClosestByTag(
- typeElement,
- "BLOCKQUOTE"
- ) as HTMLTableElement;
+ const blockquoteElement = hasClosestByTag(typeElement, "BLOCKQUOTE",) as HTMLTableElement;
if (blockquoteElement) {
vditor.wysiwyg.popover.innerHTML = "";
genUp(range, blockquoteElement, vditor);
@@ -261,19 +239,9 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
if (columnDiff > 0) {
for (let j = 0; j < columnDiff; j++) {
if (i === 0) {
- tableElement.rows[
- i
- ].lastElementChild.insertAdjacentHTML(
- "afterend",
- "
| "
- );
+ tableElement.rows[i].lastElementChild.insertAdjacentHTML("afterend", "
| ");
} else {
- tableElement.rows[
- i
- ].lastElementChild.insertAdjacentHTML(
- "afterend",
- "
| "
- );
+ tableElement.rows[i].lastElementChild.insertAdjacentHTML("afterend", "
| ");
}
}
} else {
@@ -299,10 +267,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
} else {
tableElement
.querySelector("thead")
- .insertAdjacentHTML(
- "afterend",
- rowHTML + ""
- );
+ .insertAdjacentHTML("afterend", rowHTML + "",);
}
}
} else {
@@ -346,15 +311,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
const left = document.createElement("button");
left.setAttribute("type", "button");
- left.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].alignLeft
- : options.i18n.alignLeft +
- "<" +
- updateHotkeyTip("⇧⌘L") +
- ">"
- );
+ left.setAttribute("aria-label", window.VditorI18n.alignLeft + "<" + updateHotkeyTip("⇧⌘L") + ">");
left.setAttribute("data-type", "left");
left.innerHTML =
'
';
@@ -367,15 +324,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
const center = document.createElement("button");
center.setAttribute("type", "button");
- center.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].alignCenter
- : options.i18n.alignCenter +
- "<" +
- updateHotkeyTip("⇧⌘C") +
- ">"
- );
+ center.setAttribute("aria-label", window.VditorI18n.alignCenter + "<" + updateHotkeyTip("⇧⌘C") + ">");
center.setAttribute("data-type", "center");
center.innerHTML =
'
';
@@ -388,15 +337,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
const right = document.createElement("button");
right.setAttribute("type", "button");
- right.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].alignRight
- : options.i18n.alignRight +
- "<" +
- updateHotkeyTip("⇧⌘R") +
- ">"
- );
+ right.setAttribute("aria-label", window.VditorI18n.alignRight + "<" + updateHotkeyTip("⇧⌘R") + ">",);
right.setAttribute("data-type", "right");
right.innerHTML =
'
';
@@ -409,15 +350,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
const insertRowElement = document.createElement("button");
insertRowElement.setAttribute("type", "button");
- insertRowElement.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].insertRowBelow
- : options.i18n.insertRowBelow +
- "<" +
- updateHotkeyTip("⌘=") +
- ">"
- );
+ insertRowElement.setAttribute("aria-label", window.VditorI18n.insertRowBelow + "<" + updateHotkeyTip("⌘=") + ">");
insertRowElement.setAttribute("data-type", "insertRow");
insertRowElement.innerHTML =
'
';
@@ -436,15 +369,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
const insertRowBElement = document.createElement("button");
insertRowBElement.setAttribute("type", "button");
- insertRowBElement.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].insertRowAbove
- : options.i18n.insertRowAbove +
- "<" +
- updateHotkeyTip("⇧⌘F") +
- ">"
- );
+ insertRowBElement.setAttribute("aria-label", window.VditorI18n.insertRowAbove + "<" + updateHotkeyTip("⇧⌘F") + ">");
insertRowBElement.setAttribute("data-type", "insertRow");
insertRowBElement.innerHTML =
'
';
@@ -463,15 +388,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
const insertColumnElement = document.createElement("button");
insertColumnElement.setAttribute("type", "button");
- insertColumnElement.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].insertColumnRight
- : options.i18n.insertColumnRight +
- "<" +
- updateHotkeyTip("⇧⌘=") +
- ">"
- );
+ insertColumnElement.setAttribute("aria-label", window.VditorI18n.insertColumnRight + "<" + updateHotkeyTip("⇧⌘=") + ">",);
insertColumnElement.setAttribute("data-type", "insertColumn");
insertColumnElement.innerHTML =
'
';
@@ -490,15 +407,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
const insertColumnBElement = document.createElement("button");
insertColumnBElement.setAttribute("type", "button");
- insertColumnBElement.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].insertColumnLeft
- : options.i18n.insertColumnLeft +
- "<" +
- updateHotkeyTip("⇧⌘G") +
- ">"
- );
+ insertColumnBElement.setAttribute("aria-label", window.VditorI18n.insertColumnLeft + "<" + updateHotkeyTip("⇧⌘G") + ">",);
insertColumnBElement.setAttribute("data-type", "insertColumn");
insertColumnBElement.innerHTML =
'
';
@@ -511,26 +420,13 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
hasClosestByMatchTag(startContainer, "TD") ||
hasClosestByMatchTag(startContainer, "TH");
if (cellElement) {
- insertColumn(
- vditor,
- tableElement,
- cellElement,
- "beforebegin"
- );
+ insertColumn(vditor, tableElement, cellElement, "beforebegin",);
}
};
const deleteRowElement = document.createElement("button");
deleteRowElement.setAttribute("type", "button");
- deleteRowElement.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang]["delete-row"]
- : options.i18n["delete-row"] +
- "<" +
- updateHotkeyTip("⌘-") +
- ">"
- );
+ deleteRowElement.setAttribute("aria-label", window.VditorI18n["delete-row"] + "<" + updateHotkeyTip("⌘-") + ">",);
deleteRowElement.setAttribute("data-type", "deleteRow");
deleteRowElement.innerHTML =
'
';
@@ -549,15 +445,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
const deleteColumnElement = document.createElement("button");
deleteColumnElement.setAttribute("type", "button");
- deleteColumnElement.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang]["delete-column"]
- : options.i18n["delete-column"] +
- "<" +
- updateHotkeyTip("⇧⌘-") +
- ">"
- );
+ deleteColumnElement.setAttribute("aria-label", window.VditorI18n["delete-column"] + "<" + updateHotkeyTip("⇧⌘-") + ">",);
deleteColumnElement.setAttribute("data-type", "deleteColumn");
deleteColumnElement.innerHTML =
'
';
@@ -575,10 +463,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
};
const inputWrap = document.createElement("span");
- inputWrap.setAttribute(
- "aria-label",
- !!lang ? i18n[lang].row : options.i18n.row
- );
+ inputWrap.setAttribute("aria-label", window.VditorI18n.row);
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
const input = document.createElement("input");
inputWrap.appendChild(input);
@@ -587,10 +472,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
input.className = "vditor-input";
input.style.width = "42px";
input.style.textAlign = "center";
- input.setAttribute(
- "placeholder",
- !!lang ? i18n[lang].row : options.i18n.row
- );
+ input.setAttribute("placeholder", window.VditorI18n.row);
input.value = tableElement.rows.length.toString();
input.oninput = () => {
updateTable();
@@ -609,10 +491,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
};
const input2Wrap = document.createElement("span");
- input2Wrap.setAttribute(
- "aria-label",
- !!lang ? i18n[lang].column : options.i18n.column
- );
+ input2Wrap.setAttribute("aria-label", window.VditorI18n.column);
input2Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
const input2 = document.createElement("input");
input2Wrap.appendChild(input2);
@@ -621,10 +500,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
input2.className = "vditor-input";
input2.style.width = "42px";
input2.style.textAlign = "center";
- input2.setAttribute(
- "placeholder",
- !!lang ? i18n[lang].column : options.i18n.column
- );
+ input2.setAttribute("placeholder", window.VditorI18n.column);
input2.value = tableElement.rows[0].cells.length.toString();
input2.oninput = () => {
updateTable();
@@ -648,96 +524,43 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
vditor.wysiwyg.popover.insertAdjacentElement("beforeend", left);
vditor.wysiwyg.popover.insertAdjacentElement("beforeend", center);
vditor.wysiwyg.popover.insertAdjacentElement("beforeend", right);
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- insertRowBElement
- );
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- insertRowElement
- );
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- insertColumnBElement
- );
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- insertColumnElement
- );
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- deleteRowElement
- );
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- deleteColumnElement
- );
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- inputWrap
- );
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", insertRowBElement,);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", insertRowElement,);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", insertColumnBElement,);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", insertColumnElement,);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", deleteRowElement,);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", deleteColumnElement,);
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", inputWrap,);
vditor.wysiwyg.popover.insertAdjacentHTML("beforeend", " x ");
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- input2Wrap
- );
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", input2Wrap,);
setPopoverPosition(vditor, tableElement);
}
// link ref popover
- const linkRefElement = hasClosestByAttribute(
- typeElement,
- "data-type",
- "link-ref"
- );
+ const linkRefElement = hasClosestByAttribute(typeElement, "data-type", "link-ref",);
if (linkRefElement) {
genLinkRefPopover(vditor, linkRefElement);
}
// footnote popover
- const footnotesRefElement = hasClosestByAttribute(
- typeElement,
- "data-type",
- "footnotes-ref"
- );
+ const footnotesRefElement = hasClosestByAttribute(typeElement, "data-type", "footnotes-ref",);
if (footnotesRefElement) {
const lang: keyof II18n | "" = vditor.options.lang;
const options: IOptions = vditor.options;
vditor.wysiwyg.popover.innerHTML = "";
const inputWrap = document.createElement("span");
- inputWrap.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].footnoteRef
- : options.i18n.footnoteRef +
- "<" +
- updateHotkeyTip("⌥Enter") +
- ">"
- );
+ inputWrap.setAttribute("aria-label", window.VditorI18n.footnoteRef + "<" + updateHotkeyTip("⌥Enter") + ">",);
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
const input = document.createElement("input");
inputWrap.appendChild(input);
input.className = "vditor-input";
- input.setAttribute(
- "placeholder",
- !!lang
- ? i18n[lang].footnoteRef
- : options.i18n.footnoteRef +
- "<" +
- updateHotkeyTip("⌥Enter") +
- ">"
- );
+ input.setAttribute("placeholder", window.VditorI18n.footnoteRef + "<" + updateHotkeyTip("⌥Enter") + ">",);
input.style.width = "120px";
- input.value = footnotesRefElement.getAttribute(
- "data-footnotes-label"
- );
+ input.value = footnotesRefElement.getAttribute("data-footnotes-label",);
input.oninput = () => {
if (input.value.trim() !== "") {
- footnotesRefElement.setAttribute(
- "data-footnotes-label",
- input.value
- );
+ footnotesRefElement.setAttribute("data-footnotes-label", input.value,);
}
};
input.onkeydown = (event) => {
@@ -760,17 +583,11 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
};
genClose(footnotesRefElement, vditor);
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- inputWrap
- );
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", inputWrap,);
setPopoverPosition(vditor, footnotesRefElement);
}
- let blockRenderElement = hasClosestByClassName(
- typeElement,
- "vditor-wysiwyg__block"
- ) as HTMLElement;
+ let blockRenderElement = hasClosestByClassName(typeElement, "vditor-wysiwyg__block",) as HTMLElement;
// block popover: math-inline, math-block, html-block, html-inline, code-block, html-entity
if (
blockRenderElement &&
@@ -785,17 +602,8 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
if (blockRenderElement.getAttribute("data-type") === "code-block") {
const languageWrap = document.createElement("span");
- languageWrap.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].language
- : options.i18n.language +
- "<" +
- updateHotkeyTip("⌥Enter") +
- ">"
- );
- languageWrap.className =
- "vditor-tooltipped vditor-tooltipped__n";
+ languageWrap.setAttribute("aria-label", window.VditorI18n.language + "<" + updateHotkeyTip("⌥Enter") + ">",);
+ languageWrap.className = "vditor-tooltipped vditor-tooltipped__n";
const language = document.createElement("input");
languageWrap.appendChild(language);
@@ -803,15 +611,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
blockRenderElement.firstElementChild.firstElementChild;
language.className = "vditor-input";
- language.setAttribute(
- "placeholder",
- !!lang
- ? i18n[lang].language
- : options.i18n.language +
- "<" +
- updateHotkeyTip("⌥Enter") +
- ">"
- );
+ language.setAttribute("placeholder", window.VditorI18n.language + "<" + updateHotkeyTip("⌥Enter") + ">",);
language.value =
codeElement.className.indexOf("language-") > -1
? codeElement.className.split("-")[1].split(" ")[0]
@@ -823,17 +623,10 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
codeElement.className = "";
vditor.hint.recentLanguage = "";
}
- if (
- blockRenderElement.lastElementChild.classList.contains(
- "vditor-wysiwyg__preview"
- )
- ) {
+ if (blockRenderElement.lastElementChild.classList.contains("vditor-wysiwyg__preview",)) {
blockRenderElement.lastElementChild.innerHTML =
blockRenderElement.firstElementChild.innerHTML;
- processCodeRender(
- blockRenderElement.lastElementChild as HTMLElement,
- vditor
- );
+ processCodeRender(blockRenderElement.lastElementChild as HTMLElement, vditor,);
}
afterRenderEvent(vditor);
};
@@ -875,10 +668,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
return;
}
const matchLangData: IHintData[] = [];
- const key = language.value.substring(
- 0,
- language.selectionStart
- );
+ const key = language.value.substring(0, language.selectionStart,);
Constants.CODE_LANGUAGES.forEach((keyName) => {
if (keyName.indexOf(key.toLowerCase()) > -1) {
matchLangData.push({
@@ -890,10 +680,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
vditor.hint.genHTML(matchLangData, key, vditor);
event.preventDefault();
};
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- languageWrap
- );
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", languageWrap,);
}
setPopoverPosition(vditor, blockRenderElement);
} else {
@@ -912,18 +699,12 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
vditor.wysiwyg.popover.innerHTML = "";
const inputWrap = document.createElement("span");
- inputWrap.setAttribute(
- "aria-label",
- "ID" + "<" + updateHotkeyTip("⌥Enter") + ">"
- );
+ inputWrap.setAttribute("aria-label", "ID" + "<" + updateHotkeyTip("⌥Enter") + ">",);
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
const input = document.createElement("input");
inputWrap.appendChild(input);
input.className = "vditor-input";
- input.setAttribute(
- "placeholder",
- "ID" + "<" + updateHotkeyTip("⌥Enter") + ">"
- );
+ input.setAttribute("placeholder", "ID" + "<" + updateHotkeyTip("⌥Enter") + ">",);
input.style.width = "120px";
input.value = headingElement.getAttribute("data-id") || "";
input.oninput = () => {
@@ -951,10 +732,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
genUp(range, headingElement, vditor);
genDown(range, headingElement, vditor);
genClose(headingElement, vditor);
- vditor.wysiwyg.popover.insertAdjacentElement(
- "beforeend",
- inputWrap
- );
+ vditor.wysiwyg.popover.insertAdjacentElement("beforeend", inputWrap,);
setPopoverPosition(vditor, headingElement);
}
@@ -974,11 +752,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
!headingElement &&
!tocElement
) {
- const blockElement = hasClosestByAttribute(
- typeElement,
- "data-block",
- "0"
- );
+ const blockElement = hasClosestByAttribute(typeElement, "data-block", "0",);
if (
blockElement &&
blockElement.parentElement.isEqualNode(vditor.wysiwyg.element)
@@ -1000,11 +774,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
.forEach((item: HTMLElement) => {
item.style.display = "none";
});
- const backslashElement = hasClosestByAttribute(
- range.startContainer,
- "data-type",
- "backslash"
- );
+ const backslashElement = hasClosestByAttribute(range.startContainer, "data-type", "backslash",);
if (backslashElement) {
backslashElement.querySelector("span").style.display = "inline";
}
@@ -1020,28 +790,13 @@ const setPopoverPosition = (vditor: IVditor, element: HTMLElement) => {
vditor.wysiwyg.popover.style.left = "0";
vditor.wysiwyg.popover.style.display = "block";
vditor.wysiwyg.popover.style.top =
- Math.max(
- -8,
- targetElement.offsetTop - 21 - vditor.wysiwyg.element.scrollTop
- ) + "px";
+ Math.max(-8, targetElement.offsetTop - 21 - vditor.wysiwyg.element.scrollTop,) + "px";
vditor.wysiwyg.popover.style.left =
- Math.min(
- targetElement.offsetLeft,
- vditor.wysiwyg.element.clientWidth -
- vditor.wysiwyg.popover.clientWidth
- ) + "px";
- vditor.wysiwyg.popover.setAttribute(
- "data-top",
- (targetElement.offsetTop - 21).toString()
- );
+ Math.min(targetElement.offsetLeft, vditor.wysiwyg.element.clientWidth - vditor.wysiwyg.popover.clientWidth,) + "px";
+ vditor.wysiwyg.popover.setAttribute("data-top", (targetElement.offsetTop - 21).toString(),);
};
-export const genLinkRefPopover = (
- vditor: IVditor,
- linkRefElement: HTMLElement
-) => {
- const lang: keyof II18n | "" = vditor.options.lang;
- const options: IOptions = vditor.options;
+export const genLinkRefPopover = (vditor: IVditor, linkRefElement: HTMLElement,) => {
vditor.wysiwyg.popover.innerHTML = "";
const updateLinkRef = () => {
@@ -1059,18 +814,12 @@ export const genLinkRefPopover = (
};
const inputWrap = document.createElement("span");
- inputWrap.setAttribute(
- "aria-label",
- !!lang ? i18n[lang].textIsNotEmpty : options.i18n.textIsNotEmpty
- );
+ inputWrap.setAttribute("aria-label", window.VditorI18n.textIsNotEmpty,);
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
const input = document.createElement("input");
inputWrap.appendChild(input);
input.className = "vditor-input";
- input.setAttribute(
- "placeholder",
- !!lang ? i18n[lang].textIsNotEmpty : options.i18n.textIsNotEmpty
- );
+ input.setAttribute("placeholder", window.VditorI18n.textIsNotEmpty,);
input.style.width = "120px";
input.value =
linkRefElement.getAttribute("alt") || linkRefElement.textContent;
@@ -1085,18 +834,12 @@ export const genLinkRefPopover = (
};
const input1Wrap = document.createElement("span");
- input1Wrap.setAttribute(
- "aria-label",
- !!lang ? i18n[lang].linkRef : options.i18n.linkRef
- );
+ input1Wrap.setAttribute("aria-label", window.VditorI18n.linkRef,);
input1Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
const input1 = document.createElement("input");
input1Wrap.appendChild(input1);
input1.className = "vditor-input";
- input1.setAttribute(
- "placeholder",
- !!lang ? i18n[lang].linkRef : options.i18n.linkRef
- );
+ input1.setAttribute("placeholder", window.VditorI18n.linkRef,);
input1.value = linkRefElement.getAttribute("data-link-label");
input1.oninput = () => {
updateLinkRef();
@@ -1115,8 +858,6 @@ export const genLinkRefPopover = (
};
const genUp = (range: Range, element: HTMLElement, vditor: IVditor) => {
- const lang: keyof II18n | "" = vditor.options.lang;
- const options: IOptions = vditor.options;
const previousElement = element.previousElementSibling;
if (
!previousElement ||
@@ -1128,12 +869,7 @@ const genUp = (range: Range, element: HTMLElement, vditor: IVditor) => {
const upElement = document.createElement("button");
upElement.setAttribute("type", "button");
upElement.setAttribute("data-type", "up");
- upElement.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].up
- : options.i18n.up + "<" + updateHotkeyTip("⇧⌘U") + ">"
- );
+ upElement.setAttribute("aria-label", window.VditorI18n.up + "<" + updateHotkeyTip("⇧⌘U") + ">",);
upElement.innerHTML = '
';
upElement.className = "vditor-icon vditor-tooltipped vditor-tooltipped__n";
upElement.onclick = () => {
@@ -1148,8 +884,6 @@ const genUp = (range: Range, element: HTMLElement, vditor: IVditor) => {
};
const genDown = (range: Range, element: HTMLElement, vditor: IVditor) => {
- const lang: keyof II18n | "" = vditor.options.lang;
- const options: IOptions = vditor.options;
const nextElement = element.nextElementSibling;
if (
!nextElement ||
@@ -1161,12 +895,7 @@ const genDown = (range: Range, element: HTMLElement, vditor: IVditor) => {
const downElement = document.createElement("button");
downElement.setAttribute("type", "button");
downElement.setAttribute("data-type", "down");
- downElement.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].down
- : options.i18n.down + "<" + updateHotkeyTip("⇧⌘D") + ">"
- );
+ downElement.setAttribute("aria-label", window.VditorI18n.down + "<" + updateHotkeyTip("⇧⌘D") + ">",);
downElement.innerHTML =
'
';
downElement.className =
@@ -1183,17 +912,10 @@ const genDown = (range: Range, element: HTMLElement, vditor: IVditor) => {
};
const genClose = (element: HTMLElement, vditor: IVditor) => {
- const lang: keyof II18n | "" = vditor.options.lang;
- const options: IOptions = vditor.options;
const close = document.createElement("button");
close.setAttribute("type", "button");
close.setAttribute("data-type", "remove");
- close.setAttribute(
- "aria-label",
- !!lang
- ? i18n[lang].remove
- : options.i18n.remove + "<" + updateHotkeyTip("⇧⌘X") + ">"
- );
+ close.setAttribute("aria-label", window.VditorI18n.remove + "<" + updateHotkeyTip("⇧⌘X") + ">",);
close.innerHTML =
'
';
close.className = "vditor-icon vditor-tooltipped vditor-tooltipped__n";
@@ -1212,7 +934,7 @@ const linkHotkey = (
vditor: IVditor,
element: HTMLElement,
event: KeyboardEvent,
- nextInputElement: HTMLInputElement
+ nextInputElement: HTMLInputElement,
) => {
if (event.isComposing) {
return;
@@ -1256,18 +978,12 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
item.removeAttribute("data-marker");
});
const inputWrap = document.createElement("span");
- inputWrap.setAttribute(
- "aria-label",
- !!lang ? i18n[lang].textIsNotEmpty : options.i18n.textIsNotEmpty
- );
+ inputWrap.setAttribute("aria-label", window.VditorI18n.textIsNotEmpty,);
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
const input = document.createElement("input");
inputWrap.appendChild(input);
input.className = "vditor-input";
- input.setAttribute(
- "placeholder",
- !!lang ? i18n[lang].textIsNotEmpty : options.i18n.textIsNotEmpty
- );
+ input.setAttribute("placeholder", window.VditorI18n.textIsNotEmpty,);
input.style.width = "120px";
input.value = aElement.innerHTML || "";
input.oninput = () => {
@@ -1281,18 +997,12 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
};
const input1Wrap = document.createElement("span");
- input1Wrap.setAttribute(
- "aria-label",
- !!lang ? i18n[lang].link : options.i18n.link
- );
+ input1Wrap.setAttribute("aria-label", window.VditorI18n.link,);
input1Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
const input1 = document.createElement("input");
input1Wrap.appendChild(input1);
input1.className = "vditor-input";
- input1.setAttribute(
- "placeholder",
- !!lang ? i18n[lang].link : options.i18n.link
- );
+ input1.setAttribute("placeholder", window.VditorI18n.link,);
input1.value = aElement.getAttribute("href") || "";
input1.oninput = () => {
updateA();
@@ -1305,18 +1015,12 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
};
const input2Wrap = document.createElement("span");
- input2Wrap.setAttribute(
- "aria-label",
- !!lang ? i18n[lang].tooltipText : options.i18n.tooltipText
- );
+ input2Wrap.setAttribute("aria-label", window.VditorI18n.tooltipText);
input2Wrap.className = "vditor-tooltipped vditor-tooltipped__n";
const input2 = document.createElement("input");
input2Wrap.appendChild(input2);
input2.className = "vditor-input";
- input2.setAttribute(
- "placeholder",
- !!lang ? i18n[lang].tooltipText : options.i18n.tooltipText
- );
+ input2.setAttribute("placeholder", window.VditorI18n.tooltipText);
input2.style.width = "60px";
input2.value = aElement.getAttribute("title") || "";
input2.oninput = () => {
@@ -1337,8 +1041,6 @@ export const genAPopover = (vditor: IVditor, aElement: HTMLElement) => {
};
export const genImagePopover = (event: Event, vditor: IVditor) => {
- const lang: keyof II18n | "" = vditor.options.lang;
- const options: IOptions = vditor.options;
const imgElement = event.target as HTMLImageElement;
vditor.wysiwyg.popover.innerHTML = "";
const updateImg = () => {
@@ -1348,18 +1050,12 @@ export const genImagePopover = (event: Event, vditor: IVditor) => {
};
const inputWrap = document.createElement("span");
- inputWrap.setAttribute(
- "aria-label",
- !!lang ? i18n[lang].imageURL : options.i18n.imageURL
- );
+ inputWrap.setAttribute("aria-label", window.VditorI18n.imageURL);
inputWrap.className = "vditor-tooltipped vditor-tooltipped__n";
const inputElement = document.createElement("input");
inputWrap.appendChild(inputElement);
inputElement.className = "vditor-input";
- inputElement.setAttribute(
- "placeholder",
- !!lang ? i18n[lang].imageURL : options.i18n.imageURL
- );
+ inputElement.setAttribute("placeholder", window.VditorI18n.imageURL);
inputElement.value = imgElement.getAttribute("src") || "";
inputElement.oninput = () => {
updateImg();
@@ -1369,18 +1065,12 @@ export const genImagePopover = (event: Event, vditor: IVditor) => {
};
const altWrap = document.createElement("span");
- altWrap.setAttribute(
- "aria-label",
- !!lang ? i18n[lang].alternateText : options.i18n.alternateText
- );
+ altWrap.setAttribute("aria-label", window.VditorI18n.alternateText);
altWrap.className = "vditor-tooltipped vditor-tooltipped__n";
const alt = document.createElement("input");
altWrap.appendChild(alt);
alt.className = "vditor-input";
- alt.setAttribute(
- "placeholder",
- !!lang ? i18n[lang].alternateText : options.i18n.alternateText
- );
+ alt.setAttribute("placeholder", window.VditorI18n.alternateText);
alt.style.width = "52px";
alt.value = imgElement.getAttribute("alt") || "";
alt.oninput = () => {
@@ -1391,18 +1081,12 @@ export const genImagePopover = (event: Event, vditor: IVditor) => {
};
const titleWrap = document.createElement("span");
- titleWrap.setAttribute(
- "aria-label",
- !!lang ? i18n[lang].title : options.i18n.title
- );
+ titleWrap.setAttribute("aria-label", window.VditorI18n.title);
titleWrap.className = "vditor-tooltipped vditor-tooltipped__n";
const title = document.createElement("input");
titleWrap.appendChild(title);
title.className = "vditor-input";
- title.setAttribute(
- "placeholder",
- !!lang ? i18n[lang].title : options.i18n.title
- );
+ title.setAttribute("placeholder", window.VditorI18n.title);
title.value = imgElement.getAttribute("title") || "";
title.oninput = () => {
updateImg();
diff --git a/src/ts/wysiwyg/index.ts b/src/ts/wysiwyg/index.ts
index a6b412abe..5c538f4eb 100644
--- a/src/ts/wysiwyg/index.ts
+++ b/src/ts/wysiwyg/index.ts
@@ -1,5 +1,4 @@
import {Constants} from "../constants";
-import {i18n} from "../i18n";
import {hidePanel} from "../toolbar/setToolbar";
import {isCtrl, isFirefox} from "../util/compatibility";
import {
@@ -49,7 +48,7 @@ class WYSIWYG {
contenteditable="true" spellcheck="false">
-
`;
diff --git a/types/index.d.ts b/types/index.d.ts
index 250096ceb..f894c576d 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -2,6 +2,10 @@ declare module "*.svg";
declare module "*.png";
+interface Window {
+ VditorI18n: ITips
+}
+
interface IObject {
[key: string]: string;
}
@@ -227,84 +231,84 @@ declare const webkitAudioContext: {
};
interface ITips {
- [index: string]: string
- alignCenter: string
- alignLeft: string
- alignRight: string
- alternateText: string
- bold: string
- both: string
- check: string
- close: string
- code: string
- "code-theme": string
- column: string
- comment: string
- confirm: string
- "content-theme": string
- copied: string
- copy: string
- "delete-column": string
- "delete-row": string
- devtools: string
- down: string
- downloadTip: string
- edit: string
- "edit-mode": string
- emoji: string
- export: string
- fileTypeError: string
- footnoteRef: string
- fullscreen: string
- generate: string
- headings: string
- help: string
- imageURL: string
- indent: string
- info: string
- "inline-code": string
- "insert-after": string
- "insert-before": string
- insertColumnLeft: string
- insertColumnRight: string
- insertRowAbove: string
- insertRowBelow: string
- instantRendering: string
- italic: string
- language: string
- line: string
- link: string
- linkRef: string
- list: string
- more: string
- nameEmpty: string
- "ordered-list": string
- outdent: string
- outline: string
- over: string
- performanceTip: string
- preview: string
- quote: string
- record: string
- "record-tip": string
- recording: string
- redo: string
- remove: string
- row: string
- spin: string
- splitView: string
- strike: string
- table: string
- textIsNotEmpty: string
- title: string
- tooltipText: string
- undo: string
- up: string
- update: string
- upload: string
- uploadError: string
- uploading: string
- wysiwyg: string
+ [index: string]: string;
+ alignCenter: string;
+ alignLeft: string;
+ alignRight: string;
+ alternateText: string;
+ bold: string;
+ both: string;
+ check: string;
+ close: string;
+ code: string;
+ "code-theme": string;
+ column: string;
+ comment: string;
+ confirm: string;
+ "content-theme": string;
+ copied: string;
+ copy: string;
+ "delete-column": string;
+ "delete-row": string;
+ devtools: string;
+ down: string;
+ downloadTip: string;
+ edit: string;
+ "edit-mode": string;
+ emoji: string;
+ export: string;
+ fileTypeError: string;
+ footnoteRef: string;
+ fullscreen: string;
+ generate: string;
+ headings: string;
+ help: string;
+ imageURL: string;
+ indent: string;
+ info: string;
+ "inline-code": string;
+ "insert-after": string;
+ "insert-before": string;
+ insertColumnLeft: string;
+ insertColumnRight: string;
+ insertRowAbove: string;
+ insertRowBelow: string;
+ instantRendering: string;
+ italic: string;
+ language: string;
+ line: string;
+ link: string;
+ linkRef: string;
+ list: string;
+ more: string;
+ nameEmpty: string;
+ "ordered-list": string;
+ outdent: string;
+ outline: string;
+ over: string;
+ performanceTip: string;
+ preview: string;
+ quote: string;
+ record: string;
+ "record-tip": string;
+ recording: string;
+ redo: string;
+ remove: string;
+ row: string;
+ spin: string;
+ splitView: string;
+ strike: string;
+ table: string;
+ textIsNotEmpty: string;
+ title: string;
+ tooltipText: string;
+ undo: string;
+ up: string;
+ update: string;
+ upload: string;
+ uploadError: string;
+ uploading: string;
+ wysiwyg: string;
}
interface II18n {
@@ -508,7 +512,6 @@ interface IPreviewOptions {
hljs?: IHljs;
speech?: {
enable?: boolean,
- lang?: string
};
anchor?: number; // 0: no render, 1: render left, 2: render right
math?: IMath;