Skip to content

Commit

Permalink
Merge pull request #1599 from Waqar144/rewrite-em
Browse files Browse the repository at this point in the history
Update to new inline highlighter
  • Loading branch information
pbek committed Jan 21, 2020
2 parents c388d86 + 17c803f commit bd38e99
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
55 changes: 27 additions & 28 deletions src/helpers/qownnotesmarkdownhighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ void QOwnNotesMarkdownHighlighter::setCodeHighlighting(bool state)
* @param text
*/
void QOwnNotesMarkdownHighlighter::highlightBlock(const QString &text) {
//updateCurrentNote();
setCurrentBlockState(HighlighterState::NoState);
currentBlock().setUserState(HighlighterState::NoState);

Expand All @@ -107,42 +106,42 @@ void QOwnNotesMarkdownHighlighter::highlightBlock(const QString &text) {
}

void QOwnNotesMarkdownHighlighter::highlightMarkdown(const QString& text) {
if (!text.isEmpty()) {

const QString &next = currentBlock().next().text();
const bool isHeading = text.at(0) == QChar('#');
const bool isHeadWithUnderline =
text.startsWith(QLatin1String("===")) || text.startsWith(QLatin1String("---"));
const bool nextHasUnderLine =
next.startsWith(QLatin1String("===")) || next.startsWith(QLatin1String("---"));
const bool isCodeBlock = MarkdownHighlighter::isCodeBlock(previousBlockState()) ||
text.startsWith(QLatin1String("```")) ||
text.startsWith(QLatin1String("~~~"));

if (!isCodeBlock) {
const bool isCodeBlock = MarkdownHighlighter::isCodeBlock(previousBlockState()) ||
text.startsWith(QLatin1String("```")) ||
text.startsWith(QLatin1String("~~~"));
const QString &next = currentBlock().next().text();
const bool isHeading = text.at(0) == QChar('#');
const bool isSetextHeading = (next.startsWith(QLatin1String("===")) ||
next.startsWith(QLatin1String("---"))) &&
!text.isEmpty();
const bool isSetextHeadingUnderline = (text.startsWith(QLatin1String("===")) ||
text.startsWith(QLatin1String("---"))) &&
!currentBlock().previous().text().isEmpty();
const bool isBlockHeading = isHeading || isSetextHeading || isSetextHeadingUnderline;

if (!text.isEmpty() && !isCodeBlock) {
if (!isSetextHeading && !isSetextHeadingUnderline)
highlightAdditionalRules(_highlightingRulesPre, text);

// needs to be called after the horizontal ruler highlighting
if (isHeading || isHeadWithUnderline || nextHasUnderLine) {
highlightHeadline(text);
}
// needs to be called after the horizontal ruler highlighting
if (isBlockHeading)
highlightHeadline(text);

highlightAdditionalRules(_highlightingRulesAfter, text);
highlightAdditionalRules(_highlightingRulesAfter, text);

// highlight broken note links
if (text.contains(QLatin1String("note://")) || text.contains(QLatin1String(".md"))) {
highlightBrokenNotesLink(text);
}
}
highlightInlineRules(text);

// highlight broken note links
if (text.contains(QLatin1String("note://")) || text.contains(QLatin1String(".md"))) {
highlightBrokenNotesLink(text);
}
}

if (commentHighlightingOn) {
if (!isBlockHeading && commentHighlightingOn)
highlightCommentBlock(text);
}

if (codeHighlightingOn) {
if (MarkdownHighlighter::isCodeBlock(previousBlockState()) ||
text.startsWith(QLatin1String("```")) || text.startsWith(QLatin1String("~~~"))) {
if (isCodeBlock) {
highlightCodeFence(text);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/qmarkdowntextedit

0 comments on commit bd38e99

Please sign in to comment.