From 19eed576eda87f58a804a78a305f359df560b85f Mon Sep 17 00:00:00 2001 From: Zhuochun Date: Tue, 16 Oct 2018 02:48:49 +0800 Subject: [PATCH] Add math and mathblock commands Fixes #254 --- lib/config.cson | 8 +++++ lib/markdown-writer.coffee | 6 ++-- menus/menu.cson | 68 +++++++++++++++++++++++--------------- package.json | 2 ++ 4 files changed, 55 insertions(+), 29 deletions(-) diff --git a/lib/config.cson b/lib/config.cson index 39cbabf3..06ac43d5 100644 --- a/lib/config.cson +++ b/lib/config.cson @@ -112,6 +112,8 @@ textRangeSelectBy: "nearestWord" textStyles: code: before: "`", after: "`", scopeSelector: ".raw" + math: + before: "$$", after: "$$", scopeSelector: ".math" bold: before: "**", after: "**", scopeSelector: ".bold" italic: @@ -126,6 +128,12 @@ textStyles: regexBefore: "```(?:[\\w- ]+)?\\r?\\n" regexAfter: "\\r?\\n```" selectBy: "currentParagraph" + mathblock: + before: "$$\n" + after: "\n$$" + regexBefore: "\\$\\$\\r?\\n" + regexAfter: "\\r?\\n\\$\\$" + selectBy: "currentParagraph" deletion: before: "{--", after: "--}", scopeSelector: "critic." addition: diff --git a/lib/markdown-writer.coffee b/lib/markdown-writer.coffee index 79e34454..23b2a23f 100644 --- a/lib/markdown-writer.coffee +++ b/lib/markdown-writer.coffee @@ -44,13 +44,15 @@ module.exports = editorCommands["markdown-writer:insert-#{media}"] = @registerView("./views/insert-#{media}-view") - ["code", "codeblock", "bold", "italic", "strikethrough", "keystroke", + ["code", "codeblock", "math", "mathblock", + "bold", "italic", "strikethrough", "keystroke", "deletion", "addition", "substitution", "comment", "highlight" ].forEach (style) => editorCommands["markdown-writer:toggle-#{style}-text"] = @registerCommand("./commands/style-text", args: style) - ["h1", "h2", "h3", "h4", "h5", "ul", "ol", "task", "taskdone", "blockquote"].forEach (style) => + ["h1", "h2", "h3", "h4", "h5", "ul", "ol", + "task", "taskdone", "blockquote"].forEach (style) => editorCommands["markdown-writer:toggle-#{style}"] = @registerCommand("./commands/style-line", args: style) diff --git a/menus/menu.cson b/menus/menu.cson index 59d5bb0f..18f84f55 100644 --- a/menus/menu.cson +++ b/menus/menu.cson @@ -46,23 +46,11 @@ 'label': 'Insert Image', 'command': 'markdown-writer:insert-image' } - { - 'label': 'Insert Table', - 'command': 'markdown-writer:insert-table' - } { 'label': 'Insert Footnote', 'command': 'markdown-writer:insert-footnote' } { 'type': 'separator' } - { - 'label': 'Code', - 'command': 'markdown-writer:toggle-code-text' - } - { - 'label': 'Code Block', - 'command': 'markdown-writer:toggle-codeblock-text' - } { 'label': 'Bold', 'command': 'markdown-writer:toggle-bold-text' @@ -81,24 +69,20 @@ } { 'type': 'separator' } { - 'label': 'deletion', - 'command': 'markdown-writer:toggle-deletion-text' - } - { - 'label': 'addition', - 'command': 'markdown-writer:toggle-addition-text' + 'label': 'Code', + 'command': 'markdown-writer:toggle-code-text' } { - 'label': 'substitution', - 'command': 'markdown-writer:toggle-substitution-text' + 'label': 'Code Block', + 'command': 'markdown-writer:toggle-codeblock-text' } { - 'label': 'comment', - 'command': 'markdown-writer:toggle-comment-text' + 'label': 'Math', + 'command': 'markdown-writer:toggle-math-text' } { - 'label': 'highlight', - 'command': 'markdown-writer:toggle-highlight-text' + 'label': 'Math Block', + 'command': 'markdown-writer:toggle-mathblock-text' } { 'type': 'separator' } { @@ -135,7 +119,7 @@ 'command': 'markdown-writer:toggle-task' } { - 'label': 'Task List (Done)' + 'label': 'Toggle Task List' 'command': 'markdown-writer:toggle-taskdone' } { 'type': 'separator' } @@ -145,9 +129,38 @@ } ] } + { + 'label': 'CriticMarkup' + 'submenu': [ + { + 'label': 'Addition', + 'command': 'markdown-writer:toggle-addition-text' + } + { + 'label': 'Deletion', + 'command': 'markdown-writer:toggle-deletion-text' + } + { + 'label': 'Substitution', + 'command': 'markdown-writer:toggle-substitution-text' + } + { + 'label': 'Comment', + 'command': 'markdown-writer:toggle-comment-text' + } + { + 'label': 'Highlight', + 'command': 'markdown-writer:toggle-highlight-text' + } + ] + } { 'label': 'Table' 'submenu': [ + { + 'label': 'Insert Table', + 'command': 'markdown-writer:insert-table' + } { 'label': 'Format Table' 'command': 'markdown-writer:format-table' @@ -166,6 +179,7 @@ 'label': 'Fold All Links' 'command': 'markdown-writer:fold-links' } + { 'type': 'separator' } { 'label': 'Unfold All' 'command': 'editor:unfold-all' @@ -190,8 +204,8 @@ } { 'type': 'separator' } { - 'label': 'Fold All Links' - 'command': 'markdown-writer:fold-links' + 'label': 'Format Ordered List' + 'command': 'markdown-writer:format-order-list' } { 'type': 'separator' } { diff --git a/package.json b/package.json index 7d2d1278..9996589f 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,8 @@ "markdown-writer:insert-table", "markdown-writer:toggle-code-text", "markdown-writer:toggle-codeblock-text", + "markdown-writer:toggle-math-text", + "markdown-writer:toggle-mathblock-text", "markdown-writer:toggle-bold-text", "markdown-writer:toggle-italic-text", "markdown-writer:toggle-keystroke-text",