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;
#ifndef QT_NO_DEBUG
// #define VX_DEBUG_WEB
#define VX_DEBUG_WEB
#endif
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("linkifyEnabled: %1,\n").arg(Utils::boolToString(m_linkifyEnabled))
+ 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("}");
}
@ -157,6 +158,7 @@ void HtmlTemplateHelper::updateMarkdownViewerTemplate(const MarkdownEditorConfig
opts.m_webPlantUml = p_config.getWebPlantUml();
opts.m_webGraphviz = p_config.getWebGraphviz();
opts.m_sectionNumberEnabled = p_config.getSectionNumberMode() == MarkdownEditorConfig::SectionNumberMode::Read;
opts.m_sectionNumberBaseLevel = p_config.getSectionNumberBaseLevel();
opts.m_constrainImageWidthEnabled = p_config.getConstrainImageWidthEnabled();
opts.m_protectFromXss = p_config.getProtectFromXss();
opts.m_htmlTagEnabled = p_config.getHtmlTagEnabled();

View File

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

View File

@ -117,5 +117,4 @@ QString MainConfig::getVersion(const QJsonObject &p_jobj)
void MainConfig::doVersionSpecificOverride()
{
// 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,
"//comment" : "none/read/edit",
"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,
"//comment" : "Style of the section number in edit mode",
"//comment" : "digdotdigdot/digdotdig",

View File

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

View File

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

View File

@ -32,13 +32,15 @@ pre[class*="language-"] {
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
background-color: #1976d2;
color: #f1f1f1;
}
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
background-color: #1976d2;
color: #f1f1f1;
}
@media print {
@ -242,4 +244,3 @@ div.code-toolbar > .toolbar span:focus {
color: inherit;
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. */
/* Section numbering */
#vx-content.vx-section-number, #vx-content.vx-section-number h1 {
counter-reset: section1 section2 section3 section4 section5;
#vx-content.vx-section-number,
#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 {
counter-reset: section2 section3 section4 seciton5;
#vx-content.vx-section-number-1 h1,
#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 {
counter-reset: section3 section4 section5;
#vx-content.vx-section-number-1 h2,
#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 {
counter-reset: section4 section5;
#vx-content.vx-section-number-1 h3,
#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 {
counter-reset: section5;
#vx-content.vx-section-number-1 h4,
#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;
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;
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;
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;
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;
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 {
max-width: 100%;
height: auto;
@ -55,15 +83,35 @@
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;
}
#vx-content.vx-section-number .vx-table-of-contents > ol > li ol li {
#vx-content.vx-section-number-1 .vx-table-of-contents ol li {
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, '.') '. ';
font-family: cursive;
}

View File

@ -37,6 +37,8 @@ class VNoteX extends EventEmitter {
this.turndown = null;
this.sectionNumberBaseLevel = 2;
window.addEventListener('load', () => {
console.log('window load finished');
@ -52,6 +54,12 @@ class VNoteX extends EventEmitter {
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;
// Signal out.
@ -202,10 +210,13 @@ class VNoteX extends EventEmitter {
setSectionNumberEnabled(p_enabled) {
let sectionClass = 'vx-section-number';
let sectionLevelClass = 'vx-section-number-' + this.sectionNumberBaseLevel;
if (p_enabled) {
this.contentContainer.classList.add(sectionClass);
this.contentContainer.classList.add(sectionLevelClass);
} else {
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),
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);
});