diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-02-16 09:56:14 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-02-16 00:19:29 +0100 |
| commit | 4135e0d368a8181b7422338559bdcd3b214443c4 (patch) | |
| tree | 7447e944f42d00f6196c08d9def78f8fadd6c22e /src/renderers | |
| parent | 5acffd9b549c89670a7af69d613266b8d8120ecd (diff) | |
| download | kristall-4135e0d368a8181b7422338559bdcd3b214443c4.tar.gz | |
Improved blockquotes
Diffstat (limited to 'src/renderers')
| -rw-r--r-- | src/renderers/geminirenderer.cpp | 21 | ||||
| -rw-r--r-- | src/renderers/markdownrenderer.cpp | 2 | ||||
| -rw-r--r-- | src/renderers/textstyleinstance.cpp | 17 | ||||
| -rw-r--r-- | src/renderers/textstyleinstance.hpp | 4 |
4 files changed, 31 insertions, 13 deletions
diff --git a/src/renderers/geminirenderer.cpp b/src/renderers/geminirenderer.cpp index 5f82bb8..595db44 100644 --- a/src/renderers/geminirenderer.cpp +++ b/src/renderers/geminirenderer.cpp @@ -6,6 +6,7 @@ #include <QList> #include <QStringList> #include <QDebug> +#include <QTextTable> #include "kristall.hpp" @@ -106,20 +107,28 @@ std::unique_ptr<GeminiDocument> GeminiRenderer::render( if(line.startsWith(">")) { - if(not blockquote ) { - // cursor.insertBlock(); + if(!blockquote) + { + // Start blockquote + QTextTable *table = cursor.insertTable(1, 1, text_style.blockquote_tableformat); + cursor.setBlockFormat(text_style.blockquote_format); + QTextTableCell cell = table->cellAt(0, 0); + cell.setFormat(text_style.blockquote); + blockquote = true; } - blockquote = true; - cursor.setBlockFormat(text_style.block_quote_format); replace_quotes(line); - cursor.insertText(trim_whitespace(line.mid(1)) + "\n", text_style.standard); + cursor.insertText(trim_whitespace(line.mid(1)) + "\n", text_style.blockquote); continue; } else { - if(blockquote) { + if (blockquote) + { + // End blockquote + cursor.deletePreviousChar(); + cursor.movePosition(QTextCursor::NextBlock); cursor.setBlockFormat(text_style.standard_format); } blockquote = false; diff --git a/src/renderers/markdownrenderer.cpp b/src/renderers/markdownrenderer.cpp index 2b8657d..d3c5f1d 100644 --- a/src/renderers/markdownrenderer.cpp +++ b/src/renderers/markdownrenderer.cpp @@ -121,7 +121,7 @@ static void renderNode(RenderState &state, cmark_node & node, const QTextCharFor state.emitNewBlock(); state.suppress_next_block = true; - cursor.setBlockFormat(state.text_style.block_quote_format); + cursor.setBlockFormat(state.text_style.blockquote_format); renderChildren(state, node, current_format, page_title); state.emitNewBlock(); diff --git a/src/renderers/textstyleinstance.cpp b/src/renderers/textstyleinstance.cpp index aaf7ee6..cce6313 100644 --- a/src/renderers/textstyleinstance.cpp +++ b/src/renderers/textstyleinstance.cpp @@ -26,10 +26,11 @@ TextStyleInstance::TextStyleInstance(DocumentStyle const & themed_style) standard_h3.setFont(themed_style.h3_font); standard_h3.setForeground(QBrush(themed_style.h3_color)); - preformatted_format.setNonBreakableLines(true); + blockquote.setFont(themed_style.blockquote_font); + blockquote.setForeground(QBrush(themed_style.blockquote_fgcolor)); + blockquote.setBackground(themed_style.blockquote_bgcolor); - block_quote_format.setIndent(themed_style.indent_bq); - block_quote_format.setBackground(themed_style.blockquote_color); + preformatted_format.setNonBreakableLines(true); // Other alignments auto align = themed_style.justify_text ? Qt::AlignJustify : Qt::AlignLeft; @@ -42,9 +43,15 @@ TextStyleInstance::TextStyleInstance(DocumentStyle const & themed_style) link_format.setLineHeight(themed_style.line_height_p, QTextBlockFormat::LineDistanceHeight); - block_quote_format.setAlignment(align); - block_quote_format.setLineHeight(themed_style.line_height_p, + blockquote_format.setAlignment(align); + blockquote_format.setLineHeight(themed_style.line_height_p, QTextBlockFormat::LineDistanceHeight); + blockquote_tableformat.setBorderStyle(QTextFrameFormat::BorderStyle_None); + blockquote_tableformat.setHeaderRowCount(0); + blockquote_tableformat.setCellPadding(16.0); + blockquote_tableformat.setAlignment(Qt::AlignJustify); + blockquote_tableformat.setLeftMargin(20.0 * themed_style.indent_bq); + blockquote_tableformat.setBottomMargin(20.0); list_format.setStyle(QTextListFormat::ListDisc); list_format.setIndent(themed_style.indent_l); diff --git a/src/renderers/textstyleinstance.hpp b/src/renderers/textstyleinstance.hpp index cab2d25..f1d34bc 100644 --- a/src/renderers/textstyleinstance.hpp +++ b/src/renderers/textstyleinstance.hpp @@ -16,13 +16,15 @@ struct TextStyleInstance QTextCharFormat standard_h1; QTextCharFormat standard_h2; QTextCharFormat standard_h3; + QTextCharFormat blockquote; QTextBlockFormat standard_format; QTextBlockFormat preformatted_format; - QTextBlockFormat block_quote_format; + QTextBlockFormat blockquote_format; QTextBlockFormat heading_format; QTextBlockFormat link_format; QTextListFormat list_format; + QTextTableFormat blockquote_tableformat; explicit TextStyleInstance(DocumentStyle const & style); }; |
