diff --git a/.vscode/settings.json b/.vscode/settings.json index 5fe99f8..44a2689 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -74,6 +74,9 @@ "unordered_set": "cpp", "regex": "cpp", "shared_mutex": "cpp", - "*.inc": "cpp" + "*.inc": "cpp", + "syntax_extension.h": "c", + "render.h": "c", + "node.h": "c" } } \ No newline at end of file diff --git a/src/draw.cc b/src/draw.cc index 12c6373..4eb5aa2 100644 --- a/src/draw.cc +++ b/src/draw.cc @@ -1,5 +1,6 @@ #include "draw.h" #include "node.h" +#include "syntax_extension.h" #include "strikethrough.h" #include "mainwindow.h" #include @@ -27,14 +28,15 @@ Draw::Draw(MainWindow &mainWindow) listLevel(0), isBold(false), isItalic(false), + isStrikethrough(false), bulletListLevel(0), orderedListLevel(0), isOrderedList(false), isLink(false), defaultFont(fontFamily), + boldItalic(fontFamily), bold(fontFamily), italic(fontFamily), - boldItalic(fontFamily), heading1(fontFamily), heading2(fontFamily), heading3(fontFamily), @@ -609,15 +611,30 @@ void Draw::processNode(cmark_node *node, cmark_event_type ev_type) { bool entering = (ev_type == CMARK_EVENT_ENTER); + // Take care of the markdown extensions + if (node->extension) + { + if (strcmp(node->extension->name, "strikethrough") == 0) + { + isStrikethrough = entering; + } + return; + } + switch (node->type) { case CMARK_NODE_DOCUMENT: if (entering) { - // Reset + // Reset all (better safe then sorry) headingLevel = 0; bulletListLevel = 0; + orderedListLevel = 0; listLevel = 0; + isOrderedList = false; + isBold = false; + isItalic = false; + isStrikethrough = false; } break; @@ -787,7 +804,7 @@ void Draw::processNode(cmark_node *node, cmark_event_type ev_type) break; } } - // Bold/italic text + // Bold, italic and strikethrough text else if (isBold && isItalic) { insertBoldItalic(text); @@ -800,6 +817,10 @@ void Draw::processNode(cmark_node *node, cmark_event_type ev_type) { insertItalic(text); } + else if (isStrikethrough) + { + insertStrikethrough(text); + } // URL else if (isLink) { @@ -845,7 +866,7 @@ void Draw::processNode(cmark_node *node, cmark_event_type ev_type) isItalic = entering; break; - //case CMARK_NODE_STRIKETHROUGH: + //case CMARK_NODE_STRIKETHROUGH: //break; case CMARK_NODE_LINK: @@ -928,6 +949,11 @@ void Draw::insertHeading6(const std::string &text) insertMarkupTextOnThread("\n" + text + "\n"); } +void Draw::insertBoldItalic(const std::string &text) +{ + insertMarkupTextOnThread("" + text + ""); +} + void Draw::insertBold(const std::string &text) { insertMarkupTextOnThread("" + text + ""); @@ -938,9 +964,9 @@ void Draw::insertItalic(const std::string &text) insertMarkupTextOnThread("" + text + ""); } -void Draw::insertBoldItalic(const std::string &text) +void Draw::insertStrikethrough(const std::string &text) { - insertMarkupTextOnThread("" + text + ""); + insertMarkupTextOnThread("" + text + ""); } /****************************************************** diff --git a/src/draw.h b/src/draw.h index 5022bbd..a0abe8e 100644 --- a/src/draw.h +++ b/src/draw.h @@ -72,9 +72,10 @@ private: void insertHeading4(const std::string &text); void insertHeading5(const std::string &text); void insertHeading6(const std::string &text); + void insertBoldItalic(const std::string &text); void insertItalic(const std::string &text); void insertBold(const std::string &text); - void insertBoldItalic(const std::string &text); + void insertStrikethrough(const std::string &text); void insertMarkupTextOnThread(const std::string &text); void clearOnThread(); @@ -92,6 +93,7 @@ private: int listLevel; bool isBold; bool isItalic; + bool isStrikethrough; int bulletListLevel; int orderedListLevel; bool isOrderedList;