mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
highlighter: no need to check if a header is valid
It is fixed in the upstream pmh_parser.
This commit is contained in:
parent
274a5a1aec
commit
4e744f30f9
@ -271,9 +271,6 @@ void HGMarkdownHighlighter::initBlockHighlightFromResult(int nrBlocks)
|
||||
const HighlightingStyle &style = highlightingStyles[i];
|
||||
pmh_element *elem_cursor = result[style.type];
|
||||
|
||||
// pmh_H1 to pmh_H6 is continuous.
|
||||
bool isHeader = style.type >= pmh_H1 && style.type <= pmh_H6;
|
||||
|
||||
while (elem_cursor != NULL)
|
||||
{
|
||||
// elem_cursor->pos and elem_cursor->end is the start
|
||||
@ -283,13 +280,6 @@ void HGMarkdownHighlighter::initBlockHighlightFromResult(int nrBlocks)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check header. Skip those headers with no spaces after #s.
|
||||
if (isHeader
|
||||
&& !isValidHeader(elem_cursor->pos, elem_cursor->end)) {
|
||||
elem_cursor = elem_cursor->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
initBlockHighlihgtOne(elem_cursor->pos, elem_cursor->end, i);
|
||||
elem_cursor = elem_cursor->next;
|
||||
}
|
||||
@ -383,8 +373,7 @@ void HGMarkdownHighlighter::initHeaderRegionsFromResult()
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
pmh_element *elem = result[hx[i]];
|
||||
while (elem != NULL) {
|
||||
if (elem->end <= elem->pos
|
||||
|| !isValidHeader(elem->pos, elem->end)) {
|
||||
if (elem->end <= elem->pos) {
|
||||
elem = elem->next;
|
||||
continue;
|
||||
}
|
||||
@ -1015,27 +1004,6 @@ void HGMarkdownHighlighter::highlightChanged()
|
||||
m_completeTimer->start();
|
||||
}
|
||||
|
||||
bool HGMarkdownHighlighter::isValidHeader(unsigned long p_pos, unsigned long p_end)
|
||||
{
|
||||
// There must exist spaces after #s.
|
||||
// No more than 6 #s.
|
||||
int nrNumberSign = 0;
|
||||
for (unsigned long i = p_pos; i < p_end; ++i) {
|
||||
QChar ch = document->characterAt(i);
|
||||
if (ch.isSpace()) {
|
||||
return nrNumberSign > 0;
|
||||
} else if (ch == QChar('#')) {
|
||||
if (++nrNumberSign > 6) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HGMarkdownHighlighter::isValidHeader(const QString &p_text)
|
||||
{
|
||||
// There must exist spaces after #s.
|
||||
|
@ -410,9 +410,6 @@ private:
|
||||
// Highlight color column in code block.
|
||||
void highlightCodeBlockColorColumn(const QString &p_text);
|
||||
|
||||
// Check if [p_pos, p_end) is a valid header.
|
||||
bool isValidHeader(unsigned long p_pos, unsigned long p_end);
|
||||
|
||||
bool isValidHeader(const QString &p_text);
|
||||
|
||||
VTextBlockData *currentBlockData() const;
|
||||
|
@ -298,8 +298,8 @@ void VMdEditor::contextMenuEvent(QContextMenuEvent *p_event)
|
||||
emit m_object->discardAndRead();
|
||||
});
|
||||
|
||||
QAction *toggleLivePreviewAct = new QAction(tr("Toggle Live Preview"), menu.data());
|
||||
toggleLivePreviewAct->setToolTip(tr("Toggle live preview of diagrams"));
|
||||
QAction *toggleLivePreviewAct = new QAction(tr("Live Preview for Diagrams"), menu.data());
|
||||
toggleLivePreviewAct->setToolTip(tr("Toggle live preview panel for diagrams"));
|
||||
connect(toggleLivePreviewAct, &QAction::triggered,
|
||||
this, [this]() {
|
||||
m_editTab->toggleLivePreview();
|
||||
|
Loading…
x
Reference in New Issue
Block a user