mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59: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;
|
||||
}
|
||||
|
||||
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];
|
||||
|
@ -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.
|
||||
|
@ -857,6 +857,10 @@ QString VUtils::generateHtmlTemplate(const QString &p_template,
|
||||
extraFile += "<script>var VEnableFlashAnchor = true;</script>\n";
|
||||
}
|
||||
|
||||
if (g_config->getEnableCodeBlockCopyButton()) {
|
||||
extraFile += "<script>var VEnableCodeBlockCopyButton = true;</script>\n";
|
||||
}
|
||||
|
||||
if (p_addToc) {
|
||||
extraFile += "<script>var VAddTOC = true;</script>\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.
|
||||
{
|
||||
const QString clipboardjs(":/utils/clipboard.js/clipboard.min.js");
|
||||
QString js = VUtils::readFileFromDisk(clipboardjs);
|
||||
extra += QString("<script type=\"text/javascript\">\n%1\n</script>\n").arg(js);
|
||||
extra += "<script type=\"text/javascript\">"
|
||||
"window.addEventListener('load', function() {"
|
||||
"new ClipboardJS('.vnote-copy-clipboard-btn');"
|
||||
"});"
|
||||
"</script>\n";
|
||||
if (g_config->getEnableCodeBlockCopyButton()) {
|
||||
const QString clipboardjs(":/utils/clipboard.js/clipboard.min.js");
|
||||
QString js = VUtils::readFileFromDisk(clipboardjs);
|
||||
extra += QString("<script type=\"text/javascript\">\n%1\n</script>\n").arg(js);
|
||||
extra += "<script type=\"text/javascript\">"
|
||||
"window.addEventListener('load', function() {"
|
||||
"new ClipboardJS('.vnote-copy-clipboard-btn', {"
|
||||
"text: function(trigger) {"
|
||||
"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()) {
|
||||
|
@ -333,6 +333,9 @@ void VConfigManager::initialize()
|
||||
initEditorConfigs();
|
||||
|
||||
initMarkdownConfigs();
|
||||
|
||||
m_enableCodeBlockCopyButton = getConfigFromSettings("web",
|
||||
"enable_code_block_copy_button").toBool();
|
||||
}
|
||||
|
||||
void VConfigManager::initEditorConfigs()
|
||||
|
@ -646,6 +646,8 @@ public:
|
||||
|
||||
int getTableFormatInterval() const;
|
||||
|
||||
bool getEnableCodeBlockCopyButton() const;
|
||||
|
||||
private:
|
||||
void initEditorConfigs();
|
||||
|
||||
@ -1142,6 +1144,9 @@ private:
|
||||
// Interval (milliseconds) to format table.
|
||||
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.
|
||||
static const QString c_dirConfigFile;
|
||||
|
||||
@ -2978,4 +2983,10 @@ inline int VConfigManager::getTableFormatInterval() const
|
||||
{
|
||||
return m_tableFormatIntervalMS;
|
||||
}
|
||||
|
||||
inline bool VConfigManager::getEnableCodeBlockCopyButton() const
|
||||
{
|
||||
return m_enableCodeBlockCopyButton;
|
||||
}
|
||||
|
||||
#endif // VCONFIGMANAGER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user