diff --git a/src/core/global.h b/src/core/global.h index 50888941..b3d1ef95 100644 --- a/src/core/global.h +++ b/src/core/global.h @@ -139,6 +139,15 @@ namespace vnotex CRLF, CR }; + + enum Role + { + // Qt::UserRole = 0x0100 + UserRole2 = 0x0101, + HighlightsRole = 0x0102, + // Used for comparison. + ComparisonRole = 0x0103 + }; } // ns vnotex Q_DECLARE_OPERATORS_FOR_FLAGS(vnotex::FindOptions); diff --git a/src/core/htmltemplatehelper.cpp b/src/core/htmltemplatehelper.cpp index 817af3b4..6321b3ee 100644 --- a/src/core/htmltemplatehelper.cpp +++ b/src/core/htmltemplatehelper.cpp @@ -21,6 +21,7 @@ QString WebGlobalOptions::toJavascriptObject() const return QStringLiteral("window.vxOptions = {\n") + QString("webPlantUml: %1,\n").arg(Utils::boolToString(m_webPlantUml)) + QString("webGraphviz: %1,\n").arg(Utils::boolToString(m_webGraphviz)) + + QString("mathJaxScript: '%1',\n").arg(m_mathJaxScript) + QString("constrainImageWidthEnabled: %1,\n").arg(Utils::boolToString(m_constrainImageWidthEnabled)) + QString("imageAlignCenterEnabled: %1,\n").arg(Utils::boolToString(m_imageAlignCenterEnabled)) + QString("protectFromXss: %1,\n").arg(Utils::boolToString(m_protectFromXss)) @@ -28,6 +29,7 @@ QString WebGlobalOptions::toJavascriptObject() const + QString("autoBreakEnabled: %1,\n").arg(Utils::boolToString(m_autoBreakEnabled)) + QString("linkifyEnabled: %1,\n").arg(Utils::boolToString(m_linkifyEnabled)) + QString("indentFirstLineEnabled: %1,\n").arg(Utils::boolToString(m_indentFirstLineEnabled)) + + QString("codeBlockLineNumberEnabled: %1,\n").arg(Utils::boolToString(m_codeBlockLineNumberEnabled)) + QString("sectionNumberEnabled: %1,\n").arg(Utils::boolToString(m_sectionNumberEnabled)) + QString("transparentBackgroundEnabled: %1,\n").arg(Utils::boolToString(m_transparentBackgroundEnabled)) + QString("scrollable: %1,\n").arg(Utils::boolToString(m_scrollable)) @@ -212,6 +214,7 @@ QString HtmlTemplateHelper::generateMarkdownViewerTemplate(const MarkdownEditorC WebGlobalOptions opts; opts.m_webPlantUml = p_config.getWebPlantUml(); opts.m_webGraphviz = p_config.getWebGraphviz(); + opts.m_mathJaxScript = p_config.getMathJaxScript(); opts.m_sectionNumberEnabled = p_config.getSectionNumberMode() == MarkdownEditorConfig::SectionNumberMode::Read; opts.m_sectionNumberBaseLevel = p_config.getSectionNumberBaseLevel(); opts.m_constrainImageWidthEnabled = p_config.getConstrainImageWidthEnabled(); @@ -221,6 +224,7 @@ QString HtmlTemplateHelper::generateMarkdownViewerTemplate(const MarkdownEditorC opts.m_autoBreakEnabled = p_config.getAutoBreakEnabled(); opts.m_linkifyEnabled = p_config.getLinkifyEnabled(); opts.m_indentFirstLineEnabled = p_config.getIndentFirstLineEnabled(); + opts.m_codeBlockLineNumberEnabled = p_config.getCodeBlockLineNumberEnabled(); opts.m_transparentBackgroundEnabled = p_paras.m_transparentBackgroundEnabled; opts.m_scrollable = p_paras.m_scrollable; opts.m_bodyWidth = p_paras.m_bodyWidth; diff --git a/src/core/htmltemplatehelper.h b/src/core/htmltemplatehelper.h index b785d2aa..b725812f 100644 --- a/src/core/htmltemplatehelper.h +++ b/src/core/htmltemplatehelper.h @@ -15,6 +15,8 @@ namespace vnotex bool m_webGraphviz = true; + QString m_mathJaxScript; + bool m_sectionNumberEnabled = true; int m_sectionNumberBaseLevel = 2; @@ -33,6 +35,8 @@ namespace vnotex bool m_indentFirstLineEnabled = false; + bool m_codeBlockLineNumberEnabled = true; + // Force to use transparent background. bool m_transparentBackgroundEnabled = false; diff --git a/src/core/markdowneditorconfig.cpp b/src/core/markdowneditorconfig.cpp index ed11181d..c1091da4 100644 --- a/src/core/markdowneditorconfig.cpp +++ b/src/core/markdowneditorconfig.cpp @@ -39,6 +39,8 @@ void MarkdownEditorConfig::init(const QJsonObject &p_app, const QJsonObject &p_u m_graphvizExe = READSTR(QStringLiteral("graphviz_exe")); + m_mathJaxScript = READSTR(QStringLiteral("mathjax_script")); + m_prependDotInRelativeLink = READBOOL(QStringLiteral("prepend_dot_in_relative_link")); m_confirmBeforeClearObsoleteImages = READBOOL(QStringLiteral("confirm_before_clear_obsolete_images")); m_insertFileNameAsTitle = READBOOL(QStringLiteral("insert_file_name_as_title")); @@ -58,6 +60,7 @@ void MarkdownEditorConfig::init(const QJsonObject &p_app, const QJsonObject &p_u m_autoBreakEnabled = READBOOL(QStringLiteral("auto_break")); m_linkifyEnabled = READBOOL(QStringLiteral("linkify")); m_indentFirstLineEnabled = READBOOL(QStringLiteral("indent_first_line")); + m_codeBlockLineNumberEnabled = READBOOL(QStringLiteral("code_block_line_number")); m_smartTableEnabled = READBOOL(QStringLiteral("smart_table")); m_smartTableInterval = READINT(QStringLiteral("smart_table_interval")); @@ -87,6 +90,7 @@ QJsonObject MarkdownEditorConfig::toJson() const obj[QStringLiteral("plantuml_command")] = m_plantUmlCommand; obj[QStringLiteral("web_graphviz")] = m_webGraphviz; obj[QStringLiteral("graphviz_exe")] = m_graphvizExe; + obj[QStringLiteral("mathjax_script")] = m_mathJaxScript; obj[QStringLiteral("prepend_dot_in_relative_link")] = m_prependDotInRelativeLink; obj[QStringLiteral("confirm_before_clear_obsolete_images")] = m_confirmBeforeClearObsoleteImages; obj[QStringLiteral("insert_file_name_as_title")] = m_insertFileNameAsTitle; @@ -105,6 +109,7 @@ QJsonObject MarkdownEditorConfig::toJson() const obj[QStringLiteral("auto_break")] = m_autoBreakEnabled; obj[QStringLiteral("linkify")] = m_linkifyEnabled; obj[QStringLiteral("indent_first_line")] = m_indentFirstLineEnabled; + obj[QStringLiteral("code_block_line_number")] = m_codeBlockLineNumberEnabled; obj[QStringLiteral("smart_table")] = m_smartTableEnabled; obj[QStringLiteral("smart_table_interval")] = m_smartTableInterval; obj[QStringLiteral("spell_check")] = m_spellCheckEnabled; @@ -249,6 +254,16 @@ void MarkdownEditorConfig::setGraphvizExe(const QString &p_exe) updateConfig(m_graphvizExe, p_exe, this); } +const QString &MarkdownEditorConfig::getMathJaxScript() const +{ + return m_mathJaxScript; +} + +void MarkdownEditorConfig::setMathJaxScript(const QString &p_script) +{ + updateConfig(m_mathJaxScript, p_script, this); +} + bool MarkdownEditorConfig::getPrependDotInRelativeLink() const { return m_prependDotInRelativeLink; @@ -371,6 +386,16 @@ void MarkdownEditorConfig::setIndentFirstLineEnabled(bool p_enabled) updateConfig(m_indentFirstLineEnabled, p_enabled, this); } +bool MarkdownEditorConfig::getCodeBlockLineNumberEnabled() const +{ + return m_codeBlockLineNumberEnabled; +} + +void MarkdownEditorConfig::setCodeBlockLineNumberEnabled(bool p_enabled) +{ + updateConfig(m_codeBlockLineNumberEnabled, p_enabled, this); +} + QString MarkdownEditorConfig::sectionNumberModeToString(SectionNumberMode p_mode) const { switch (p_mode) { diff --git a/src/core/markdowneditorconfig.h b/src/core/markdowneditorconfig.h index 84ca9c7a..17cb8b28 100644 --- a/src/core/markdowneditorconfig.h +++ b/src/core/markdowneditorconfig.h @@ -76,6 +76,9 @@ namespace vnotex const QString &getGraphvizExe() const; void setGraphvizExe(const QString &p_exe); + const QString &getMathJaxScript() const; + void setMathJaxScript(const QString &p_script); + bool getPrependDotInRelativeLink() const; bool getConfirmBeforeClearObsoleteImages() const; @@ -122,6 +125,9 @@ namespace vnotex bool getIndentFirstLineEnabled() const; void setIndentFirstLineEnabled(bool p_enabled); + bool getCodeBlockLineNumberEnabled() const; + void setCodeBlockLineNumberEnabled(bool p_enabled); + bool getSmartTableEnabled() const; void setSmartTableEnabled(bool p_enabled); @@ -181,6 +187,9 @@ namespace vnotex // Graphviz executable file. QString m_graphvizExe; + // MathJax script to override that in mathjax.js file. + QString m_mathJaxScript; + // Whether prepend a dot in front of the relative link, like images. bool m_prependDotInRelativeLink = false; @@ -227,6 +236,9 @@ namespace vnotex // Whether indent the first line of a paragraph. bool m_indentFirstLineEnabled = false; + // Whether enable code block line number in read mode. + bool m_codeBlockLineNumberEnabled = true; + bool m_smartTableEnabled = true; // Interval time to do smart table format. diff --git a/src/data/core/vnotex.json b/src/data/core/vnotex.json index 431f4c77..a44164a9 100644 --- a/src/data/core/vnotex.json +++ b/src/data/core/vnotex.json @@ -318,6 +318,8 @@ "web_graphviz" : true, "//commnet" : "Local Graphviz executable file to render Graphviz", "graphviz_exe" : "", + "//commnet" : "MathJax script to use", + "mathjax_script" : "", "//comment" : "Whether prepend a dot at front in relative link like images", "prepend_dot_in_relative_link" : false, "//comment" : "Whether ask for user confirmation before clearing obsolete images", @@ -350,6 +352,8 @@ "linkify" : true, "//comment" : "Whether add indentation to the first line of paragraph", "indent_first_line" : false, + "//comment" : "Whether add line number to fenced code block in read mode", + "code_block_line_number" : true, "//comment" : "Whether enable smart table (formatting)", "smart_table" : true, "//comment" : "Time interval (milliseconds) to do smart table formatting", diff --git a/src/data/extra/docs/en/markdown_guide.md b/src/data/extra/docs/en/markdown_guide.md index 90c38c88..2d9c47f5 100644 --- a/src/data/extra/docs/en/markdown_guide.md +++ b/src/data/extra/docs/en/markdown_guide.md @@ -21,8 +21,8 @@ Here is an overview of Markdown syntax supported by VNote. **Notes**: -* At least one space is needed after the `#`; -* A header should occupy one entire line; +* At least one space is needed after the `#` +* A header should occupy one entire line ### Emphasis ```md @@ -35,8 +35,8 @@ __This text will be bold__ **Notes**: -* `*` is recommended in VNote; -* If the render failed, try to add an additional space before the first `*` and after the last `*`. The space is necessary if the surrounded text begins or ends with full width punctuation; +* `*` is recommended in VNote +* If the render failed, try to add an additional space before the first `*` and after the last `*`. The space is necessary if the surrounded text begins or ends with full width punctuation ### Lists #### Unordered @@ -107,8 +107,8 @@ Here is another sentence within the quote. **Notes**: -* Space is needed after the marker `>`; -* You could just add only one `>` at the first line; +* Space is needed after the marker `>` +* You could just add only one `>` at the first line ### Fenced Code Block ```lang @@ -121,15 +121,16 @@ Here is another sentence within the quote. **Notes**: -* `lang` is optional to specify the language of the code; if not specified, VNote won't highlight the code; -* It is always a good practice to add one empty line before the whole fenced code block; +* `lang` is optional to specify the language of the code; if not specified, VNote won't highlight the code + * For a detailed supported languages list, please visit [Prism](https://prismjs.com/#supported-languages) +* It is always a good practice to add one empty line before the whole fenced code block ### Diagrams VNote supports the following engines to draw diagrams. You should specify particular language of the fenced code block and write the definition of your diagram within it. -* [Flowchart.js](http://flowchart.js.org/) for *flowchart* with language `flow` or `flowchart`; -* [Mermaid](https://mermaidjs.github.io/) with language `mermaid`; -* [WaveDrom](https://wavedrom.com/) for *digital timing diagram* with language `wavedrom`; +* [Flowchart.js](http://flowchart.js.org/) for *flowchart* with language `flow` or `flowchart` +* [Mermaid](https://mermaidjs.github.io/) with language `mermaid` +* [WaveDrom](https://wavedrom.com/) for *digital timing diagram* with language `wavedrom` For example, @@ -162,11 +163,11 @@ VNote supports [Graphviz](http://www.graphviz.org/) to draw diagrams. You should ### Math Formulas VNote supports math formulas via [MathJax](https://www.mathjax.org/). The default math delimiters are `$$...$$` for **displayed mathematics**, and `$...$` for **inline mathematics**. -* Inline mathematics should not cross multiple lines; -* Forms like `3$abc$`, `$abc$4`, `$ abc$`, and `$abc $` will not be treated as mathematics; -* Use `\` to escape `$`; -* There should be only space chars before opening `$$` and after closing `$$`; -* Use `\\` to new a line within a displayed mathematics; +* Inline mathematics should not cross multiple lines +* Forms like `3$abc$`, `$abc$4`, `$ abc$`, and `$abc $` will not be treated as mathematics +* Use `\` to escape `$` +* There should be only space chars before opening `$$` and after closing `$$` +* Use `\\` to new a line within a displayed mathematics VNote also supports displayed mathematics via fenced code block with language `mathjax` specified. diff --git a/src/data/extra/docs/en/shortcuts.md b/src/data/extra/docs/en/shortcuts.md index 96b8c510..9ee80b98 100644 --- a/src/data/extra/docs/en/shortcuts.md +++ b/src/data/extra/docs/en/shortcuts.md @@ -1,8 +1,8 @@ # Shortcuts -1. All the keys without special notice are **case insensitive**; -2. On macOS, `Ctrl` corresponds to `Command` except in Vi mode; -3. The key sequence `Ctrl+G, I` means that first press both `Ctrl` and `G` simultaneously, release them, then press `I` and release; -4. For a **complete latest shortcuts list** or modifying default shortcuts, please view the `vnotex.json` configuration file. +1. All the keys without special notice are **case insensitive** +2. On macOS, `Ctrl` corresponds to `Command` except in Vi mode +3. The key sequence `Ctrl+G, I` means that first press both `Ctrl` and `G` simultaneously, release them, then press `I` and release +4. For a **complete latest shortcuts list** or modifying default shortcuts, please view the `vnotex.json` configuration file ## General - `Ctrl+G, E` @@ -77,12 +77,12 @@ Zoom in/out the page through the mouse scroll. - `Ctrl+0` Recover the page zoom factor to 100%. - Jump between titles - - `[[`: jump to previous `N` title; - - `]]`: jump to next `N` title; - - `[]`: jump to previous `N` title at the same level; - - `][`: jump to next `N` title at the same level; - - `[{`: jump to previous `N` title at a higher level; - - `]}`: jump to next `N` title at a higher level; + - `[[`: jump to previous `N` title + - `]]`: jump to next `N` title + - `[]`: jump to previous `N` title at the same level + - `][`: jump to next `N` title at the same level + - `[{`: jump to previous `N` title at a higher level + - `]}`: jump to next `N` title at a higher level ### Edit Mode Shares the same shortcuts with Text Editor. diff --git a/src/data/extra/docs/zh_CN/markdown_guide.md b/src/data/extra/docs/zh_CN/markdown_guide.md index d0dd5d33..582be7bc 100644 --- a/src/data/extra/docs/zh_CN/markdown_guide.md +++ b/src/data/extra/docs/zh_CN/markdown_guide.md @@ -21,8 +21,8 @@ Markdown是一种通过少量简单的标记字符来格式化文本的方法。 **注意**: -* `#`之后需要至少一个空格; -* 一个标题应该占一整行; +* `#`之后需要至少一个空格 +* 一个标题应该占一整行 ### 强调 ```md @@ -35,8 +35,8 @@ __This text will be bold__ **注意**: -* VNote推荐使用`*`; -* 如果渲染错误,请尝试在第一个`*`之前以及最后一个`*`之后添加一个空格。如果被标记的文本是以全角符号开始或结尾,一般都需要前后添加一个空格; +* VNote推荐使用`*` +* 如果渲染错误,请尝试在第一个`*`之前以及最后一个`*`之后添加一个空格。如果被标记的文本是以全角符号开始或结尾,一般都需要前后添加一个空格 ### 列表 #### 无序列表 @@ -107,8 +107,8 @@ Here is another sentence within the quote. **注意**: -* `>`标记后面需要至少一个空格; -* 多行连续的引用可以只在第一行添加标记; +* `>`标记后面需要至少一个空格 +* 多行连续的引用可以只在第一行添加标记 ### 代码块 ```lang @@ -121,15 +121,16 @@ Here is another sentence within the quote. **注意**: -* `lang`用于指定代码块的代码语言,可选;如果不指定,VNote不会尝试高亮代码; -* 总是在一个代码块前面添加一个空行是一个不错的实践; +* `lang`用于指定代码块的代码语言,可选;如果不指定,VNote不会尝试高亮代码 + * 请访问[Prism](https://prismjs.com/#supported-languages)获取一个完整的支持语言列表 +* 总是在一个代码块前面添加一个空行是一个不错的实践 ### 图表 VNote支持使用以下引擎来绘制图表。您需要使用代码块,并标明特定语言,然后在代码块里面定义图表。 -* [Flowchart.js](http://flowchart.js.org/),语言为`flow`或`flowchart`; -* [Mermaid](https://mermaidjs.github.io/),语言为`mermaid`; -* [WaveDrom](https://wavedrom.com/),数字时序图,语言为`wavedrom`; +* [Flowchart.js](http://flowchart.js.org/),语言为`flow`或`flowchart` +* [Mermaid](https://mermaidjs.github.io/),语言为`mermaid` +* [WaveDrom](https://wavedrom.com/),数字时序图,语言为`wavedrom` 例如, @@ -162,11 +163,11 @@ VNote支持[Graphviz](http://www.graphviz.org/)来绘制图表。您需要使用 ### 数学公式 VNote通过[MathJax](https://www.mathjax.org/)来支持数学公式。默认的**公式块**的分隔符是`$$...$$`,**行内公式**的分隔符是`$...$`。 -* 行内公式不能跨多行; -* 形如`3$abc$`/`$abc$4`/`$ abc$`和`$abc $`的不会被解析为公式; -* 使用`\`转义`$`; -* 开始的`$$`之前以及结束的`$$`之后都只允许出现空格字符; -* 在公式块中,使用`\\`来换行; +* 行内公式不能跨多行 +* 形如`3$abc$`/`$abc$4`/`$ abc$`和`$abc $`的不会被解析为公式 +* 使用`\`转义`$` +* 开始的`$$`之前以及结束的`$$`之后都只允许出现空格字符 +* 在公式块中,使用`\\`来换行 VNote也可以使用标明语言`mathjax`的代码块来实现公式块。 diff --git a/src/data/extra/docs/zh_CN/shortcuts.md b/src/data/extra/docs/zh_CN/shortcuts.md index cf83ef66..ccc86704 100644 --- a/src/data/extra/docs/zh_CN/shortcuts.md +++ b/src/data/extra/docs/zh_CN/shortcuts.md @@ -1,8 +1,8 @@ # 快捷键 -1. 以下按键除特别说明外,都不区分大小写; -2. 在macOS下,`Ctrl`对应于`Command`,在Vi模式下除外; -3. 按键序列`Ctrl+G, I`表示先同时按下`Ctrl`和`G`,释放,然后按下`I`并释放; -4. 可以通过查看配置文件`vnotex.json`来获取一个**完整的最新的快捷键列表**或者修改默认快捷键。 +1. 以下按键除特别说明外,都不区分大小写 +2. 在macOS下,`Ctrl`对应于`Command`,在Vi模式下除外 +3. 按键序列`Ctrl+G, I`表示先同时按下`Ctrl`和`G`,释放,然后按下`I`并释放 +4. 可以通过查看配置文件`vnotex.json`来获取一个**完整的最新的快捷键列表**或者修改默认快捷键 ## 通用 - `Ctrl+G, E` @@ -77,12 +77,12 @@ VNote的很多部件均支持`Ctrl+J`和`Ctrl+K`导航。 - `Ctrl+0` 恢复页面大小为100%。 - 标题跳转 - - `[[`:跳转到上`N`个标题; - - `]]`:跳转到下`N`个标题; - - `[]`:跳转到上`N`个同层级的标题; - - `][`:跳转到下`N`个同层级的标题; - - `[{`:跳转到上`N`个高一层级的标题; - - `]}`:跳转到下`N`个高一层级的标题; + - `[[`:跳转到上`N`个标题 + - `]]`:跳转到下`N`个标题 + - `[]`:跳转到上`N`个同层级的标题 + - `][`:跳转到下`N`个同层级的标题 + - `[{`:跳转到上`N`个高一层级的标题 + - `]}`:跳转到下`N`个高一层级的标题 ### 编辑模式 和文本编辑器共享一样的快捷键。 diff --git a/src/data/extra/web/js/mathjax.js b/src/data/extra/web/js/mathjax.js index 32c9519d..7db3e313 100644 --- a/src/data/extra/web/js/mathjax.js +++ b/src/data/extra/web/js/mathjax.js @@ -56,6 +56,10 @@ class MathJaxRenderer extends VxWorker { this.initialized = true; this.readyCallback = p_callback; + if (!!window.vxOptions.mathJaxScript) { + this.mathJaxScript = window.vxOptions.mathJaxScript; + console.log('override MathJax script', this.mathJaxScript); + } Utils.loadScript(this.mathJaxScript, null); return false; } diff --git a/src/data/extra/web/js/prism.js b/src/data/extra/web/js/prism.js index 3899c58c..e19529fb 100644 --- a/src/data/extra/web/js/prism.js +++ b/src/data/extra/web/js/prism.js @@ -83,8 +83,6 @@ class PrismRenderer extends VxWorker { } } - p_containerNode.classList.add('line-numbers'); - Prism.highlightAllUnder(p_containerNode, false /* async or not */); // Remove the toolbar. diff --git a/src/data/extra/web/js/turndown.js b/src/data/extra/web/js/turndown.js index bb8c557f..ef462fb1 100644 --- a/src/data/extra/web/js/turndown.js +++ b/src/data/extra/web/js/turndown.js @@ -20,6 +20,9 @@ class TurndownConverter { this.ts.use(turndownPluginGfm.gfm); // TODO: verify and copy several rules from VNote 2.0. + // No and