aboutsummaryrefslogtreecommitdiff
path: root/src/renderers/markdownrenderer.cpp
diff options
context:
space:
mode:
authorKarol Kosek <krkk@krkk.ct8.pl>2020-12-28 15:04:50 +0100
committerFelix Queißner <felix@ib-queissner.de>2020-12-28 16:31:26 +0100
commit30f807a5801bb9e6bd3c52d0f2ceb65b4c664eed (patch)
tree62cdb6335ddd165cafb46f5e46d2708f85a9248b /src/renderers/markdownrenderer.cpp
parent16946275d260d4587494ac642441b1ce0eb17eed (diff)
downloadkristall-30f807a5801bb9e6bd3c52d0f2ceb65b4c664eed.tar.gz
MarkdownRenderer: indent lists
Diffstat (limited to 'src/renderers/markdownrenderer.cpp')
-rw-r--r--src/renderers/markdownrenderer.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/renderers/markdownrenderer.cpp b/src/renderers/markdownrenderer.cpp
index 65bff68..db09e21 100644
--- a/src/renderers/markdownrenderer.cpp
+++ b/src/renderers/markdownrenderer.cpp
@@ -75,13 +75,13 @@ struct RenderState
}
};
-static void renderNode(RenderState &state, cmark_node &node, QTextCharFormat current_format, QString &page_title);
+static void renderNode(RenderState &state, cmark_node &node, QTextCharFormat current_format, QString &page_title, int listIndent = 1);
-static void renderChildren(RenderState &state, cmark_node & node, QTextCharFormat current_format, QString &page_title)
+static void renderChildren(RenderState &state, cmark_node & node, QTextCharFormat current_format, QString &page_title, int listIndent = 1)
{
for (auto child = cmark_node_first_child(&node); child != nullptr; child = cmark_node_next(child))
{
- renderNode(state, *child, current_format, page_title);
+ renderNode(state, *child, current_format, page_title, listIndent);
}
}
@@ -102,7 +102,7 @@ static QString extractNodeText(cmark_node &node)
return QString::fromUtf8(data, strlen(data));
}
-static void renderNode(RenderState &state, cmark_node & node, QTextCharFormat current_format, QString &page_title)
+static void renderNode(RenderState &state, cmark_node & node, QTextCharFormat current_format, QString &page_title, int listIndent)
{
auto & cursor = state.cursor;
@@ -131,15 +131,18 @@ static void renderNode(RenderState &state, cmark_node & node, QTextCharFormat cu
case CMARK_NODE_LIST:
{
auto fmt = cursor.blockFormat();
+ QTextListFormat listFormat;
+ listFormat.setIndent(listIndent++);
if(cmark_node_get_list_type(&node) == CMARK_BULLET_LIST) {
- cursor.insertList(QTextListFormat::ListDisc);
+ listFormat.setStyle(QTextListFormat::ListDisc);
} else {
- cursor.insertList(QTextListFormat::ListDecimal);
+ listFormat.setStyle(QTextListFormat::ListDecimal);
}
+ cursor.insertList(listFormat);
state.suppress_next_block = true;
- renderChildren(state, node, current_format, page_title);
+ renderChildren(state, node, current_format, page_title, listIndent);
state.emitNewBlock();
state.suppress_next_block = true;
@@ -148,7 +151,7 @@ static void renderNode(RenderState &state, cmark_node & node, QTextCharFormat cu
}
case CMARK_NODE_ITEM:
{
- renderChildren(state, node, current_format, page_title);
+ renderChildren(state, node, current_format, page_title, listIndent);
break;
}
case CMARK_NODE_CODE_BLOCK: