Selaa lähdekoodia

:sparkles: fix https://github.com/Vanessa219/vditor/issues/1459

Vanessa 2 vuotta sitten
vanhempi
sitoutus
88a17a0c6d
6 muutettua tiedostoa jossa 7 lisäystä ja 2 poistoa
  1. 1 0
      CHANGELOG.md
  2. 1 0
      README.md
  3. 1 0
      README_en_US.md
  4. 1 1
      src/ts/ir/process.ts
  5. 1 1
      src/ts/wysiwyg/highlightToolbarWYSIWYG.ts
  6. 2 0
      types/index.d.ts

+ 1 - 0
CHANGELOG.md

@@ -109,6 +109,7 @@
 
 ### v3.9.5 / 2023-08
 
+* [自定义代码块语言](https://github.com/Vanessa219/vditor/issues/1459) `引入特性`
 * [编辑器全票后双击图片无法放大](https://github.com/Vanessa219/vditor/issues/1437) `修复缺陷`
 * [⬆️ Bump word-wrap from 1.2.3 to 1.2.4](https://github.com/Vanessa219/vditor/pull/1436) `dependencies`
 * [IR 模式下输入 `<!--` 后报错](https://github.com/Vanessa219/vditor/issues/1431) `修复缺陷`

+ 1 - 0
README.md

@@ -307,6 +307,7 @@ new Vditor('vditor', {
 | enable | 是否启用代码高亮 | true |
 | style | 可选值参见[Chroma](https://xyproto.github.io/splash/docs/longer/all.html) | `github` |
 | lineNumber | 是否启用行号 | false |
+| langs | 自定义指定语言 | [CODE_LANGUAGES](https://github.com/Vanessa219/vditor/blob/53ca8f9a0e511b37b5dae7c6b15eb933e9e02ccd/src/ts/constants.ts#L20) |
 
 #### options.preview.markdown
 

+ 1 - 0
README_en_US.md

@@ -291,6 +291,7 @@ new Vditor('vditor', {
 | enable | Whether to enable code syntax highlighting | true |
 | style | For optional values, see [Chroma](https://xyproto.github.io/splash/docs/longer/all.html) | `github` |
 | lineNumber | Whether to enable line number | false |
+| langs | Custom languages | [CODE_LANGUAGES](https://github.com/Vanessa219/vditor/blob/53ca8f9a0e511b37b5dae7c6b15eb933e9e02ccd/src/ts/constants.ts#L20) |
 
 #### options.preview.markdown
 

+ 1 - 1
src/ts/ir/process.ts

@@ -23,7 +23,7 @@ export const processHint = (vditor: IVditor) => {
             const key =
                 preBeforeElement.textContent.substring(0, getSelectPosition(preBeforeElement, vditor.ir.element).start)
                     .replace(Constants.ZWSP, "");
-            Constants.CODE_LANGUAGES.forEach((keyName) => {
+            (vditor.options.preview.hljs.langs || Constants.CODE_LANGUAGES).forEach((keyName) => {
                 if (keyName.indexOf(key.toLowerCase()) > -1) {
                     matchLangData.push({
                         html: keyName,

+ 1 - 1
src/ts/wysiwyg/highlightToolbarWYSIWYG.ts

@@ -677,7 +677,7 @@ export const highlightToolbarWYSIWYG = (vditor: IVditor) => {
                     }
                     const matchLangData: IHintData[] = [];
                     const key = language.value.substring(0, language.selectionStart);
-                    Constants.CODE_LANGUAGES.forEach((keyName) => {
+                    (vditor.options.preview.hljs.langs || Constants.CODE_LANGUAGES).forEach((keyName) => {
                         if (keyName.indexOf(key.toLowerCase()) > -1) {
                             matchLangData.push({
                                 html: keyName,

+ 2 - 0
types/index.d.ts

@@ -433,6 +433,8 @@ interface IHljs {
     style?: string;
     /** 是否启用代码高亮。默认值: true */
     enable?: boolean;
+    /** 自定义指定语言: CODE_LANGUAGES */
+    langs?: string[];
 }
 
 /** @link https://ld246.com/article/1549638745630#options-preview-math */