support section number base level [1,3] in read mode

This commit is contained in:
Le Tan 2021-01-12 20:34:45 +08:00
parent a43bd84570
commit 9e20f1b0a6
11 changed files with 386 additions and 323 deletions

View File

@ -24,7 +24,7 @@
using namespace vnotex; using namespace vnotex;
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
// #define VX_DEBUG_WEB #define VX_DEBUG_WEB
#endif #endif
const QString ConfigMgr::c_orgName = "VNote"; const QString ConfigMgr::c_orgName = "VNote";

View File

@ -25,7 +25,8 @@ QString WebGlobalOptions::toJavascriptObject() const
+ QString("autoBreakEnabled: %1,\n").arg(Utils::boolToString(m_autoBreakEnabled)) + QString("autoBreakEnabled: %1,\n").arg(Utils::boolToString(m_autoBreakEnabled))
+ QString("linkifyEnabled: %1,\n").arg(Utils::boolToString(m_linkifyEnabled)) + QString("linkifyEnabled: %1,\n").arg(Utils::boolToString(m_linkifyEnabled))
+ QString("indentFirstLineEnabled: %1,\n").arg(Utils::boolToString(m_indentFirstLineEnabled)) + QString("indentFirstLineEnabled: %1,\n").arg(Utils::boolToString(m_indentFirstLineEnabled))
+ QString("sectionNumberEnabled: %1\n").arg(Utils::boolToString(m_sectionNumberEnabled)) + QString("sectionNumberEnabled: %1,\n").arg(Utils::boolToString(m_sectionNumberEnabled))
+ QString("sectionNumberBaseLevel: %1\n").arg(m_sectionNumberBaseLevel)
+ QStringLiteral("}"); + QStringLiteral("}");
} }
@ -157,6 +158,7 @@ void HtmlTemplateHelper::updateMarkdownViewerTemplate(const MarkdownEditorConfig
opts.m_webPlantUml = p_config.getWebPlantUml(); opts.m_webPlantUml = p_config.getWebPlantUml();
opts.m_webGraphviz = p_config.getWebGraphviz(); opts.m_webGraphviz = p_config.getWebGraphviz();
opts.m_sectionNumberEnabled = p_config.getSectionNumberMode() == MarkdownEditorConfig::SectionNumberMode::Read; opts.m_sectionNumberEnabled = p_config.getSectionNumberMode() == MarkdownEditorConfig::SectionNumberMode::Read;
opts.m_sectionNumberBaseLevel = p_config.getSectionNumberBaseLevel();
opts.m_constrainImageWidthEnabled = p_config.getConstrainImageWidthEnabled(); opts.m_constrainImageWidthEnabled = p_config.getConstrainImageWidthEnabled();
opts.m_protectFromXss = p_config.getProtectFromXss(); opts.m_protectFromXss = p_config.getProtectFromXss();
opts.m_htmlTagEnabled = p_config.getHtmlTagEnabled(); opts.m_htmlTagEnabled = p_config.getHtmlTagEnabled();

View File

@ -16,6 +16,8 @@ namespace vnotex
bool m_sectionNumberEnabled = true; bool m_sectionNumberEnabled = true;
int m_sectionNumberBaseLevel = 2;
bool m_constrainImageWidthEnabled = true; bool m_constrainImageWidthEnabled = true;
bool m_protectFromXss = false; bool m_protectFromXss = false;

View File

@ -117,5 +117,4 @@ QString MainConfig::getVersion(const QJsonObject &p_jobj)
void MainConfig::doVersionSpecificOverride() void MainConfig::doVersionSpecificOverride()
{ {
// In a new version, we may want to change one value by force. // In a new version, we may want to change one value by force.
m_coreConfig->setTheme(QStringLiteral("pure"));
} }

View File

@ -229,7 +229,7 @@
"insert_file_name_as_title" : true, "insert_file_name_as_title" : true,
"//comment" : "none/read/edit", "//comment" : "none/read/edit",
"section_number" : "read", "section_number" : "read",
"//comment" : "Base level to start section numbering, valid only in edit mode", "//comment" : "Base level to start section numbering",
"section_number_base_level" : 2, "section_number_base_level" : 2,
"//comment" : "Style of the section number in edit mode", "//comment" : "Style of the section number in edit mode",
"//comment" : "digdotdigdot/digdotdig", "//comment" : "digdotdigdot/digdotdig",

View File

@ -227,4 +227,3 @@ div.code-toolbar > .toolbar span:focus {
color: inherit; color: inherit;
text-decoration: none; text-decoration: none;
} }

View File

@ -33,13 +33,15 @@ pre[class*="language-"] {
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection, pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection { code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none; text-shadow: none;
background: #b3d4fc; background-color: #1976D2;
color: white;
} }
pre[class*="language-"]::selection, pre[class*="language-"] ::selection, pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection { code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none; text-shadow: none;
background: #b3d4fc; background-color: #1976D2;
color: white;
} }
@media print { @media print {
@ -245,4 +247,3 @@ div.code-toolbar > .toolbar span:focus {
color: inherit; color: inherit;
text-decoration: none; text-decoration: none;
} }

View File

@ -32,13 +32,15 @@ pre[class*="language-"] {
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection, pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection { code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none; text-shadow: none;
background: #b3d4fc; background-color: #1976d2;
color: #f1f1f1;
} }
pre[class*="language-"]::selection, pre[class*="language-"] ::selection, pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection { code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none; text-shadow: none;
background: #b3d4fc; background-color: #1976d2;
color: #f1f1f1;
} }
@media print { @media print {
@ -242,4 +244,3 @@ div.code-toolbar > .toolbar span:focus {
color: inherit; color: inherit;
text-decoration: none; text-decoration: none;
} }

View File

@ -1,50 +1,78 @@
/* Styles here will be placed in the header of the HTML template as global embedded styles. */ /* Styles here will be placed in the header of the HTML template as global embedded styles. */
/* Section numbering */ /* Section numbering */
#vx-content.vx-section-number, #vx-content.vx-section-number h1 { #vx-content.vx-section-number,
counter-reset: section1 section2 section3 section4 section5; #vx-content.vx-section-number-2 h1,
#vx-content.vx-section-number-3 h1,
#vx-content.vx-section-number-3 h2 {
counter-reset: section1 section2 section3 section4 section5 section6;
} }
#vx-content.vx-section-number h2 { #vx-content.vx-section-number-1 h1,
counter-reset: section2 section3 section4 seciton5; #vx-content.vx-section-number-2 h2,
#vx-content.vx-section-number-3 h3 {
counter-reset: section2 section3 section4 seciton5 section6;
} }
#vx-content.vx-section-number h3 { #vx-content.vx-section-number-1 h2,
counter-reset: section3 section4 section5; #vx-content.vx-section-number-2 h3,
#vx-content.vx-section-number-3 h4 {
counter-reset: section3 section4 section5 section6;
} }
#vx-content.vx-section-number h4 { #vx-content.vx-section-number-1 h3,
counter-reset: section4 section5; #vx-content.vx-section-number-2 h4,
#vx-content.vx-section-number-3 h5 {
counter-reset: section4 section5 section6;
} }
#vx-content.vx-section-number h5 { #vx-content.vx-section-number-1 h4,
counter-reset: section5; #vx-content.vx-section-number-2 h5 {
counter-reset: section5 section6;
} }
#vx-content.vx-section-number h2::before { #vx-content.vx-section-number-1 h5 {
counter-reset: section6;
}
#vx-content.vx-section-number-1 h1::before,
#vx-content.vx-section-number-2 h2::before,
#vx-content.vx-section-number-3 h3::before {
counter-increment: section1; counter-increment: section1;
content: counter(section1) ". "; content: counter(section1) ". ";
} }
#vx-content.vx-section-number h3::before { #vx-content.vx-section-number-1 h2::before,
#vx-content.vx-section-number-2 h3::before,
#vx-content.vx-section-number-3 h4::before {
counter-increment: section2; counter-increment: section2;
content: counter(section1) "." counter(section2) ". "; content: counter(section1) "." counter(section2) ". ";
} }
#vx-content.vx-section-number h4::before { #vx-content.vx-section-number-1 h3::before,
#vx-content.vx-section-number-2 h4::before,
#vx-content.vx-section-number-3 h5::before {
counter-increment: section3; counter-increment: section3;
content: counter(section1) "." counter(section2) "." counter(section3) ". "; content: counter(section1) "." counter(section2) "." counter(section3) ". ";
} }
#vx-content.vx-section-number h5::before { #vx-content.vx-section-number-1 h4::before,
#vx-content.vx-section-number-2 h5::before,
#vx-content.vx-section-number-3 h6::before {
counter-increment: section4; counter-increment: section4;
content: counter(section1) "." counter(section2) "." counter(section3) "." counter(section4) ". "; content: counter(section1) "." counter(section2) "." counter(section3) "." counter(section4) ". ";
} }
#vx-content.vx-section-number h6::before { #vx-content.vx-section-number-1 h5::before,
#vx-content.vx-section-number-2 h6::before {
counter-increment: section5; counter-increment: section5;
content: counter(section1) "." counter(section2) "." counter(section3) "." counter(section4) "." counter(section5) ". "; content: counter(section1) "." counter(section2) "." counter(section3) "." counter(section4) "." counter(section5) ". ";
} }
#vx-content.vx-section-number-1 h6::before {
counter-increment: section6;
content: counter(section1) "." counter(section2) "." counter(section3) "." counter(section4) "." counter(section5) "." counter(section6) ". ";
}
#vx-content.vx-constrain-image-width img { #vx-content.vx-constrain-image-width img {
max-width: 100%; max-width: 100%;
height: auto; height: auto;
@ -55,15 +83,35 @@
list-style: none; list-style: none;
} }
#vx-content.vx-section-number .vx-table-of-contents > ol > li ol { #vx-content.vx-section-number-1 .vx-table-of-contents ol {
counter-reset: toc; counter-reset: toc;
} }
#vx-content.vx-section-number-1 .vx-table-of-contents ol li {
#vx-content.vx-section-number .vx-table-of-contents > ol > li ol li {
counter-increment: toc; counter-increment: toc;
} }
#vx-content.vx-section-number-1 .vx-table-of-contents ol li:before {
content: counters(toc, '.') '. ';
font-family: cursive;
}
#vx-content.vx-section-number .vx-table-of-contents > ol > li ol li:before { #vx-content.vx-section-number-2 .vx-table-of-contents > ol > li ol {
counter-reset: toc;
}
#vx-content.vx-section-number-2 .vx-table-of-contents > ol > li ol li {
counter-increment: toc;
}
#vx-content.vx-section-number-2 .vx-table-of-contents > ol > li ol li:before {
content: counters(toc, '.') '. ';
font-family: cursive;
}
#vx-content.vx-section-number-3 .vx-table-of-contents > ol > li > ol > li ol {
counter-reset: toc;
}
#vx-content.vx-section-number-3 .vx-table-of-contents > ol > li > ol > li ol li {
counter-increment: toc;
}
#vx-content.vx-section-number-3 .vx-table-of-contents > ol > li > ol > li ol li:before {
content: counters(toc, '.') '. '; content: counters(toc, '.') '. ';
font-family: cursive; font-family: cursive;
} }

View File

@ -37,6 +37,8 @@ class VNoteX extends EventEmitter {
this.turndown = null; this.turndown = null;
this.sectionNumberBaseLevel = 2;
window.addEventListener('load', () => { window.addEventListener('load', () => {
console.log('window load finished'); console.log('window load finished');
@ -52,6 +54,12 @@ class VNoteX extends EventEmitter {
this.searcher = new MarkJs(this, this.contentContainer); this.searcher = new MarkJs(this, this.contentContainer);
this.sectionNumberBaseLevel = window.vxOptions.sectionNumberBaseLevel;
if (this.sectionNumberBaseLevel > 3) {
console.warn('only support section number base level less than 3', this.sectionNumberBaseLevel);
this.sectionNumberBaseLevel = 3;
}
this.initialized = true; this.initialized = true;
// Signal out. // Signal out.
@ -202,10 +210,13 @@ class VNoteX extends EventEmitter {
setSectionNumberEnabled(p_enabled) { setSectionNumberEnabled(p_enabled) {
let sectionClass = 'vx-section-number'; let sectionClass = 'vx-section-number';
let sectionLevelClass = 'vx-section-number-' + this.sectionNumberBaseLevel;
if (p_enabled) { if (p_enabled) {
this.contentContainer.classList.add(sectionClass); this.contentContainer.classList.add(sectionClass);
this.contentContainer.classList.add(sectionLevelClass);
} else { } else {
this.contentContainer.classList.remove(sectionClass); this.contentContainer.classList.remove(sectionClass);
this.contentContainer.classList.remove(sectionLevelClass);
} }
} }

View File

@ -277,7 +277,7 @@ QGroupBox *MarkdownEditorPage::setupGeneralGroup()
connect(m_sectionNumberComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), connect(m_sectionNumberComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, [this](int p_index) { this, [this](int p_index) {
m_sectionNumberBaseLevelSpinBox->setEnabled(p_index == MarkdownEditorConfig::SectionNumberMode::Edit); m_sectionNumberBaseLevelSpinBox->setEnabled(p_index != MarkdownEditorConfig::SectionNumberMode::None);
m_sectionNumberStyleComboBox->setEnabled(p_index == MarkdownEditorConfig::SectionNumberMode::Edit); m_sectionNumberStyleComboBox->setEnabled(p_index == MarkdownEditorConfig::SectionNumberMode::Edit);
}); });