Skip to content

Commit

Permalink
fix #132
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Feb 12, 2020
1 parent ec8a18a commit 87887e2
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* [136](https://github.com/Vanessa219/vditor/issues/136) ⌘ and Ctrl is different at MacOS `修复缺陷`
* [135](https://github.com/Vanessa219/vditor/issues/135) can not delete the first char. at first field of links `改进功能`
* [133](https://github.com/Vanessa219/vditor/issues/133) MathJax 渲染无法修改 `修复缺陷`
* [132](https://github.com/Vanessa219/vditor/issues/132) 添加 md 配置项 `引入特性`

### v2.1.15 / 2020-02-09

Expand Down
2 changes: 1 addition & 1 deletion demo/index-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ VditorPreview.preview(document.getElementById('preview'),
speech: {
enable: true,
},
anchor: true
anchor: true,
})
10 changes: 10 additions & 0 deletions src/assets/index.d.min.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ interface IPreview {
url?: string;
hljs?: IHljs;
math?: IMath;
markdown?: {
autoSpace?: boolean;
fixTermTypo?: boolean;
chinesePunct?: boolean;
};

parse?(element: HTMLElement): void;

Expand All @@ -86,6 +91,11 @@ interface IPreviewOptions {
anchor?: boolean;
math?: IMath;
cdn?: string;
markdown?: {
autoSpace?: boolean;
fixTermTypo?: boolean;
chinesePunct?: boolean;
};

transform?(html: string): string;
}
Expand Down
3 changes: 2 additions & 1 deletion src/js/lute/lute.min.js

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions src/ts/markdown/md2html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {log} from "../util/log";
declare const Lute: ILute;

export const loadLuteJs = async (vditor: IVditor | string) => {
let cdn = `https://cdn.jsdelivr.net/npm/vditor@${VDITOR_VERSION}`;
if (typeof vditor === "string" && vditor) {
cdn = vditor;
} else if (typeof vditor === "object" && vditor.options.cdn) {
cdn = vditor.options.cdn;
}
addScript(`${cdn}/dist/js/lute/lute.min.js`, "vditorLuteScript");
// addScript(`/src/js/lute/lute.min.js`, "vditorLuteScript");
// let cdn = `https://cdn.jsdelivr.net/npm/vditor@${VDITOR_VERSION}`;
// if (typeof vditor === "string" && vditor) {
// cdn = vditor;
// } else if (typeof vditor === "object" && vditor.options.cdn) {
// cdn = vditor.options.cdn;
// }
// addScript(`${cdn}/dist/js/lute/lute.min.js`, "vditorLuteScript");
addScript(`/src/js/lute/lute.min.js`, "vditorLuteScript");
// addScript(`http://192.168.80.35:9090/lute.min.js?${new Date().getTime()}`, "vditorLuteScript");

if (vditor && typeof vditor === "object" && !vditor.lute) {
Expand All @@ -21,6 +21,9 @@ export const loadLuteJs = async (vditor: IVditor | string) => {
vditor.lute.SetEmojiSite(vditor.options.hint.emojiPath);
vditor.lute.SetParallelParsing(false);
vditor.lute.SetInlineMathAllowDigitAfterOpenMarker(vditor.options.preview.math.inlineDigit);
vditor.lute.SetAutoSpace(vditor.options.preview.markdown.autoSpace);
vditor.lute.SetChinesePunct(vditor.options.preview.markdown.chinesePunct);
vditor.lute.SetFixTermTypo(vditor.options.preview.markdown.fixTermTypo);
}
};

Expand All @@ -40,6 +43,9 @@ export const md2htmlByPreview = async (mdText: string, options?: IPreviewOptions
lute.SetHeadingAnchor(options.anchor);
lute.SetParallelParsing(false);
lute.SetInlineMathAllowDigitAfterOpenMarker(options.math.inlineDigit);
lute.SetAutoSpace(options.markdown.autoSpace);
lute.SetChinesePunct(options.markdown.chinesePunct);
lute.SetFixTermTypo(options.markdown.fixTermTypo);
return lute.Md2HTML(mdText);
};

Expand Down
8 changes: 8 additions & 0 deletions src/ts/markdown/previewRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export const previewRender = async (previewElement: HTMLDivElement, markdown: st
style: "github",
},
lang: "zh_CN",
markdown: {
autoSpace: true,
chinesePunct: true,
fixTermTypo: true,
},
math: {
engine: "KaTeX",
inlineDigit: false,
Expand All @@ -43,6 +48,9 @@ export const previewRender = async (previewElement: HTMLDivElement, markdown: st
if (options.math) {
options.math = Object.assign({}, defaultOption.math, options.math);
}
if (options.markdown) {
options.markdown = Object.assign({}, defaultOption.markdown, options.markdown);
}

let html =
await md2htmlByPreview(markdown, options);
Expand Down
16 changes: 16 additions & 0 deletions src/ts/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ interface ILute {

SetInlineMathAllowDigitAfterOpenMarker(enable: boolean): void;

SetAutoSpace(enable: boolean): void;

SetChinesePunct(enable: boolean): void;

SetFixTermTypo(enable: boolean): void;

SetEmojiSite(emojiSite: string): void;

PutEmojis(emojis: { [key: string]: string }): void;
Expand Down Expand Up @@ -150,6 +156,11 @@ interface IPreview {
url?: string;
hljs?: IHljs;
math?: IMath;
markdown?: {
autoSpace?: boolean;
fixTermTypo?: boolean;
chinesePunct?: boolean;
};

parse?(element: HTMLElement): void;

Expand All @@ -168,6 +179,11 @@ interface IPreviewOptions {
anchor?: boolean;
math?: IMath;
cdn?: string;
markdown?: {
autoSpace?: boolean;
fixTermTypo?: boolean;
chinesePunct?: boolean;
};

transform?(html: string): string;
}
Expand Down
9 changes: 9 additions & 0 deletions src/ts/util/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ export class Options {
lineNumber: false,
style: "github",
},
markdown: {
autoSpace: true,
chinesePunct: true,
fixTermTypo: true,
},
math: {
engine: "KaTeX",
inlineDigit: false,
Expand Down Expand Up @@ -238,6 +243,10 @@ export class Options {
this.options.preview.math =
Object.assign({}, this.defaultOptions.preview.math, this.options.preview.math);
}
if (this.options.preview.markdown) {
this.options.preview.markdown =
Object.assign({}, this.defaultOptions.preview.markdown, this.options.preview.markdown);
}
}

if (this.options.hint) {
Expand Down

0 comments on commit 87887e2

Please sign in to comment.