diff --git a/demo/requirejs_packages.js b/demo/requirejs_packages.js index c343ed1..005f0ea 100644 --- a/demo/requirejs_packages.js +++ b/demo/requirejs_packages.js @@ -34,6 +34,11 @@ var requirejs_packages = [ { name: "markdown-it", main: "dist/markdown-it.min.js" }, { name: "markdown-it-footnote", main: "dist/markdown-it-footnote.min.js" }, { name: "markdown-it-emoji", main: "dist/markdown-it-emoji.min.js" }, + { name: "markdown-it-mark", main: "dist/markdown-it-mark.min.js" }, + { name: "markdown-it-ins", main: "dist/markdown-it-ins.min.js" }, + { name: "markdown-it-sub", main: "dist/markdown-it-sub.min.js" }, + { name: "markdown-it-sup", main: "dist/markdown-it-sup.min.js" }, + { name: "markdown-it-task-lists", main: "dist/markdown-it-task-lists.min.js", diff --git a/dev/HyperMD.config.js b/dev/HyperMD.config.js index 67f5c25..2bc34fc 100644 --- a/dev/HyperMD.config.js +++ b/dev/HyperMD.config.js @@ -95,6 +95,10 @@ exports.globalNames = { "markdown-it-footnote": "MarkdownItFootnote", "markdown-it-emoji": "MarkdownItEmoji", "markdown-it-task-lists": "MarkdownItTaskLists", + "markdown-it-mark": "MarkdownItMark", + "markdown-it-ins": "MarkdownItIns", + "markdown-it-sub": "MarkdownItSub", + "markdown-it-sup": "MarkdownItSup", react: "React", "react-dom": "ReactDOM", vega: "vega", diff --git a/mode/hypermd.scss b/mode/hypermd.scss index dac8a44..3374236 100644 --- a/mode/hypermd.scss +++ b/mode/hypermd.scss @@ -15,6 +15,10 @@ span.hmd-hidden-token { &.cm-formatting-em, &.cm-formatting-strong, + &.cm-formatting-mark, + &.cm-formatting-ins, + &.cm-formatting-sub, + &.cm-formatting-sup, &.cm-formatting-strikethrough, &.cm-formatting-code, &.cm-formatting-link { diff --git a/package.json b/package.json index 63d8fb3..3fe7bc8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vickymd", - "version": "0.2.4", + "version": "0.2.5", "description": "An experimental WYSIWYG markdown editor built on top of HyperMD with extended Widgets support", "main": "./everything.js", "types": "./everything.d.ts", @@ -65,6 +65,10 @@ "markdown-it": "^11.0.0", "markdown-it-emoji": "^1.4.0", "markdown-it-footnote": "^3.0.2", + "markdown-it-ins": "^3.0.0", + "markdown-it-mark": "^3.0.0", + "markdown-it-sub": "^1.0.0", + "markdown-it-sup": "^1.0.0", "markdown-it-task-lists": "^2.1.1", "marked": "^1.1.0", "mathjax": "^3.0.5", diff --git a/src/addon/hide-token.ts b/src/addon/hide-token.ts index 5b215a1..d072956 100644 --- a/src/addon/hide-token.ts +++ b/src/addon/hide-token.ts @@ -61,7 +61,9 @@ export interface Options extends Addon.AddonOptions { export const defaultOption: Options = { enabled: false, line: true, - tokenTypes: "em|strong|strikethrough|code|linkText|task".split("|"), + tokenTypes: "em|strong|mark|ins|sub|sup|strikethrough|code|linkText|task".split( + "|" + ), }; export const suggestedOption: Partial = { diff --git a/src/core/line-spans.ts b/src/core/line-spans.ts index 74447ba..43ec041 100644 --- a/src/core/line-spans.ts +++ b/src/core/line-spans.ts @@ -22,6 +22,10 @@ export interface Span { type SpanType = | "em" | "strong" + | "mark" + | "ins" + | "sub" + | "sup" | "strikethrough" | "code" | "linkText" @@ -80,6 +84,34 @@ class LineSpanExtractor { ? SpanAction.LEAVING_THIS_TYPE : SpanAction.NOTHING, + // mark + mark: state.mark + ? SpanAction.IS_THIS_TYPE + : prevState.mark + ? SpanAction.LEAVING_THIS_TYPE + : SpanAction.NOTHING, + + // ins + ins: state.ins + ? SpanAction.IS_THIS_TYPE + : prevState.ins + ? SpanAction.LEAVING_THIS_TYPE + : SpanAction.NOTHING, + + // sub + sub: state.sub + ? SpanAction.IS_THIS_TYPE + : prevState.sub + ? SpanAction.LEAVING_THIS_TYPE + : SpanAction.NOTHING, + + // sup + sup: state.sup + ? SpanAction.IS_THIS_TYPE + : prevState.sup + ? SpanAction.LEAVING_THIS_TYPE + : SpanAction.NOTHING, + // code code: state.code ? SpanAction.IS_THIS_TYPE diff --git a/src/mode/hypermd.ts b/src/mode/hypermd.ts index 92a133d..8a3ffdc 100644 --- a/src/mode/hypermd.ts +++ b/src/mode/hypermd.ts @@ -65,6 +65,10 @@ export interface MarkdownState { code: false | number; em: false | string; strong: false | string; + mark: false | string; + ins: false | string; + sub: false | string; + sup: false | string; header: number; setext: 0 | 1 | 2; // current line is afxHeader before ---- ====== hr: boolean; @@ -595,6 +599,10 @@ CodeMirror.defineMode( //#endregion + //#region mark, ins, sub, sup + // TODO: Implement support + //#endregion + //#region Link, BareLink, Footnote, Wikilink etc if (stream.current() === "[" && stream.eat("[")) { diff --git a/src/powerpack/paste-with-turndown.ts b/src/powerpack/paste-with-turndown.ts index f63a6ea..5e5e18d 100644 --- a/src/powerpack/paste-with-turndown.ts +++ b/src/powerpack/paste-with-turndown.ts @@ -14,7 +14,7 @@ import * as TurndownService from "turndown"; import { PasteConvertor, suggestedOption, defaultOption } from "../addon/paste"; -export const TurndownConvertor: PasteConvertor = html => { +export const TurndownConvertor: PasteConvertor = (html) => { // strip without href html = html.replace(/]*)>(.*?)<\/a>/gi, (s, attrs, content) => { if (!/href=/i.test(attrs)) return content; @@ -23,7 +23,7 @@ export const TurndownConvertor: PasteConvertor = html => { // maybe you don't need to convert, if there is no img/link/header... if ( - !/\<(?:hr|img|h\d|strong|em|strikethrough|table|a|b|i|del)(?:\s.*?|\/)?\>/i.test( + !/\<(?:hr|img|h\d|strong|em|mark|ins|sub|sup|strikethrough|table|a|b|i|del)(?:\s.*?|\/)?\>/i.test( html ) ) @@ -35,10 +35,10 @@ export const TurndownConvertor: PasteConvertor = html => { return null; }; -export const getTurndownService = (function() { +export const getTurndownService = (function () { var service: TurndownService = null; - return function() { + return function () { if (!service && typeof TurndownService === "function") { var opts = { headingStyle: "atx", @@ -49,7 +49,7 @@ export const getTurndownService = (function() { emDelimiter: "*", strongDelimiter: "**", linkStyle: "inlined", - linkReferenceStyle: "collapsed" + linkReferenceStyle: "collapsed", }; service = new (TurndownService as any)(opts); diff --git a/src/preview/index.ts b/src/preview/index.ts index aef06a6..02c9093 100644 --- a/src/preview/index.ts +++ b/src/preview/index.ts @@ -3,6 +3,11 @@ import MarkdownIt from "markdown-it"; import MarkdownItEmoji from "markdown-it-emoji"; import MarkdownItFootnote from "markdown-it-footnote"; import MarkdownItTaskLists from "markdown-it-task-lists"; +import MarkdownItMark from "markdown-it-mark"; +import MarkdownItIns from "markdown-it-ins"; +import MarkdownItSub from "markdown-it-sub"; +import MarkdownItSup from "markdown-it-sup"; + declare var YAML: typeof import("yamljs"); // import * as YAML from "yamljs"; @@ -38,6 +43,10 @@ const md = new MarkdownIt({ md.use(MarkdownItEmoji, { defs: EmojiDefinitions }); md.use(MarkdownItFootnote); md.use(MarkdownItTaskLists); +md.use(MarkdownItMark); +md.use(MarkdownItIns); +md.use(MarkdownItSub); +md.use(MarkdownItSup); TagEnhancer(md); MathEnhancer(md); WidgetEnhancer(md); @@ -644,4 +653,4 @@ function printPreview( }); } -export { renderMarkdown, renderPreview, printPDF, printPreview }; +export { renderMarkdown, renderPreview, printPDF, printPreview, md }; diff --git a/yarn.lock b/yarn.lock index e140521..fa9f8d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1759,6 +1759,26 @@ markdown-it-footnote@^3.0.2: resolved "https://registry.npm.taobao.org/markdown-it-footnote/download/markdown-it-footnote-3.0.2.tgz#1575ee7a093648d4e096aa33386b058d92ac8bc1" integrity sha1-FXXuegk2SNTglqozOGsFjZKsi8E= +markdown-it-ins@^3.0.0: + version "3.0.0" + resolved "https://registry.npm.taobao.org/markdown-it-ins/download/markdown-it-ins-3.0.0.tgz#b1b56824c78dc66e52b0fc97531b317cd78d79d2" + integrity sha1-sbVoJMeNxm5SsPyXUxsxfNeNedI= + +markdown-it-mark@^3.0.0: + version "3.0.0" + resolved "https://registry.npm.taobao.org/markdown-it-mark/download/markdown-it-mark-3.0.0.tgz#27c3e39ef3cc310b2dde5375082c9fa912983cda" + integrity sha1-J8PjnvPMMQst3lN1CCyfqRKYPNo= + +markdown-it-sub@^1.0.0: + version "1.0.0" + resolved "https://registry.npm.taobao.org/markdown-it-sub/download/markdown-it-sub-1.0.0.tgz#375fd6026eae7ddcb012497f6411195ea1e3afe8" + integrity sha1-N1/WAm6ufdywEkl/ZBEZXqHjr+g= + +markdown-it-sup@^1.0.0: + version "1.0.0" + resolved "https://registry.npm.taobao.org/markdown-it-sup/download/markdown-it-sup-1.0.0.tgz#cb9c9ff91a5255ac08f3fd3d63286e15df0a1fc3" + integrity sha1-y5yf+RpSVawI8/09YyhuFd8KH8M= + markdown-it-task-lists@^2.1.1: version "2.1.1" resolved "https://registry.npm.taobao.org/markdown-it-task-lists/download/markdown-it-task-lists-2.1.1.tgz#f68f4d2ac2bad5a2c373ba93081a1a6848417088"