From 151481cfcaab469e7bbde7d732cbab88389092fe Mon Sep 17 00:00:00 2001 From: Le Tan Date: Mon, 24 Jun 2019 20:23:50 +0800 Subject: [PATCH] add config [web]/enable_code_block_copy_button --- src/resources/markdown_template.js | 8 ++++++++ src/resources/vnote.ini | 3 +++ src/utils/vutils.cpp | 31 +++++++++++++++++++++--------- src/vconfigmanager.cpp | 3 +++ src/vconfigmanager.h | 11 +++++++++++ 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/resources/markdown_template.js b/src/resources/markdown_template.js index 534720e8..af331ca6 100644 --- a/src/resources/markdown_template.js +++ b/src/resources/markdown_template.js @@ -51,6 +51,10 @@ if (typeof VEnableHighlightLineNumber == 'undefined') { VEnableHighlightLineNumber = false; } +if (typeof VEnableCodeBlockCopyButton == 'undefined') { + VEnableCodeBlockCopyButton = false; +} + if (typeof VStylesToInline == 'undefined') { VStylesToInline = ''; } @@ -1290,6 +1294,10 @@ var addClassToCodeBlock = function() { }; var addCopyButtonToCodeBlock = function() { + if (!VEnableCodeBlockCopyButton) { + return; + } + var codes = document.getElementsByClassName(hljsClass); for (var i = 0; i < codes.length; ++i) { var code = codes[i]; diff --git a/src/resources/vnote.ini b/src/resources/vnote.ini index 72db7cd9..98ce82fd 100644 --- a/src/resources/vnote.ini +++ b/src/resources/vnote.ini @@ -420,6 +420,9 @@ plantuml_cmd= ; Graphviz Dot location graphviz_dot= +; Whether enable copy button in code block +enable_code_block_copy_button=true + [shortcuts] ; Define shortcuts here, with each item in the form "operation=keysequence". ; Leave keysequence empty to disable the shortcut of an operation. diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 82875f2a..c2522985 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -857,6 +857,10 @@ QString VUtils::generateHtmlTemplate(const QString &p_template, extraFile += "\n"; } + if (g_config->getEnableCodeBlockCopyButton()) { + extraFile += "\n"; + } + if (p_addToc) { extraFile += "\n"; extraFile += "