mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
add config [web]/enable_code_block_copy_button
This commit is contained in:
parent
39795c3daa
commit
151481cfca
@ -51,6 +51,10 @@ if (typeof VEnableHighlightLineNumber == 'undefined') {
|
|||||||
VEnableHighlightLineNumber = false;
|
VEnableHighlightLineNumber = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof VEnableCodeBlockCopyButton == 'undefined') {
|
||||||
|
VEnableCodeBlockCopyButton = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof VStylesToInline == 'undefined') {
|
if (typeof VStylesToInline == 'undefined') {
|
||||||
VStylesToInline = '';
|
VStylesToInline = '';
|
||||||
}
|
}
|
||||||
@ -1290,6 +1294,10 @@ var addClassToCodeBlock = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var addCopyButtonToCodeBlock = function() {
|
var addCopyButtonToCodeBlock = function() {
|
||||||
|
if (!VEnableCodeBlockCopyButton) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var codes = document.getElementsByClassName(hljsClass);
|
var codes = document.getElementsByClassName(hljsClass);
|
||||||
for (var i = 0; i < codes.length; ++i) {
|
for (var i = 0; i < codes.length; ++i) {
|
||||||
var code = codes[i];
|
var code = codes[i];
|
||||||
|
@ -420,6 +420,9 @@ plantuml_cmd=
|
|||||||
; Graphviz Dot location
|
; Graphviz Dot location
|
||||||
graphviz_dot=
|
graphviz_dot=
|
||||||
|
|
||||||
|
; Whether enable copy button in code block
|
||||||
|
enable_code_block_copy_button=true
|
||||||
|
|
||||||
[shortcuts]
|
[shortcuts]
|
||||||
; Define shortcuts here, with each item in the form "operation=keysequence".
|
; Define shortcuts here, with each item in the form "operation=keysequence".
|
||||||
; Leave keysequence empty to disable the shortcut of an operation.
|
; Leave keysequence empty to disable the shortcut of an operation.
|
||||||
|
@ -857,6 +857,10 @@ QString VUtils::generateHtmlTemplate(const QString &p_template,
|
|||||||
extraFile += "<script>var VEnableFlashAnchor = true;</script>\n";
|
extraFile += "<script>var VEnableFlashAnchor = true;</script>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_config->getEnableCodeBlockCopyButton()) {
|
||||||
|
extraFile += "<script>var VEnableCodeBlockCopyButton = true;</script>\n";
|
||||||
|
}
|
||||||
|
|
||||||
if (p_addToc) {
|
if (p_addToc) {
|
||||||
extraFile += "<script>var VAddTOC = true;</script>\n";
|
extraFile += "<script>var VAddTOC = true;</script>\n";
|
||||||
extraFile += "<style type=\"text/css\">\n"
|
extraFile += "<style type=\"text/css\">\n"
|
||||||
@ -944,15 +948,24 @@ with 2em, if there are Chinese characters in it, the font will be a mess.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clipboard.js.
|
// Clipboard.js.
|
||||||
{
|
if (g_config->getEnableCodeBlockCopyButton()) {
|
||||||
const QString clipboardjs(":/utils/clipboard.js/clipboard.min.js");
|
const QString clipboardjs(":/utils/clipboard.js/clipboard.min.js");
|
||||||
QString js = VUtils::readFileFromDisk(clipboardjs);
|
QString js = VUtils::readFileFromDisk(clipboardjs);
|
||||||
extra += QString("<script type=\"text/javascript\">\n%1\n</script>\n").arg(js);
|
extra += QString("<script type=\"text/javascript\">\n%1\n</script>\n").arg(js);
|
||||||
extra += "<script type=\"text/javascript\">"
|
extra += "<script type=\"text/javascript\">"
|
||||||
"window.addEventListener('load', function() {"
|
"window.addEventListener('load', function() {"
|
||||||
"new ClipboardJS('.vnote-copy-clipboard-btn');"
|
"new ClipboardJS('.vnote-copy-clipboard-btn', {"
|
||||||
"});"
|
"text: function(trigger) {"
|
||||||
"</script>\n";
|
"var t = trigger.getAttribute('source-text');"
|
||||||
|
"if (t[t.length - 1] == '\\n') {"
|
||||||
|
"return t.substring(0, t.length - 1);"
|
||||||
|
"} else {"
|
||||||
|
"return t;"
|
||||||
|
"}"
|
||||||
|
"}"
|
||||||
|
"});"
|
||||||
|
"});"
|
||||||
|
"</script>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!extra.isEmpty()) {
|
if (!extra.isEmpty()) {
|
||||||
|
@ -333,6 +333,9 @@ void VConfigManager::initialize()
|
|||||||
initEditorConfigs();
|
initEditorConfigs();
|
||||||
|
|
||||||
initMarkdownConfigs();
|
initMarkdownConfigs();
|
||||||
|
|
||||||
|
m_enableCodeBlockCopyButton = getConfigFromSettings("web",
|
||||||
|
"enable_code_block_copy_button").toBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VConfigManager::initEditorConfigs()
|
void VConfigManager::initEditorConfigs()
|
||||||
|
@ -646,6 +646,8 @@ public:
|
|||||||
|
|
||||||
int getTableFormatInterval() const;
|
int getTableFormatInterval() const;
|
||||||
|
|
||||||
|
bool getEnableCodeBlockCopyButton() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initEditorConfigs();
|
void initEditorConfigs();
|
||||||
|
|
||||||
@ -1142,6 +1144,9 @@ private:
|
|||||||
// Interval (milliseconds) to format table.
|
// Interval (milliseconds) to format table.
|
||||||
int m_tableFormatIntervalMS;
|
int m_tableFormatIntervalMS;
|
||||||
|
|
||||||
|
// Whether enable copy button in code block in read mode.
|
||||||
|
bool m_enableCodeBlockCopyButton;
|
||||||
|
|
||||||
// The name of the config file in each directory.
|
// The name of the config file in each directory.
|
||||||
static const QString c_dirConfigFile;
|
static const QString c_dirConfigFile;
|
||||||
|
|
||||||
@ -2978,4 +2983,10 @@ inline int VConfigManager::getTableFormatInterval() const
|
|||||||
{
|
{
|
||||||
return m_tableFormatIntervalMS;
|
return m_tableFormatIntervalMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool VConfigManager::getEnableCodeBlockCopyButton() const
|
||||||
|
{
|
||||||
|
return m_enableCodeBlockCopyButton;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // VCONFIGMANAGER_H
|
#endif // VCONFIGMANAGER_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user