From df4fbcb4cf6c593c725f677b2ed587e877ae6709 Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Tue, 9 Jun 2020 00:19:32 +0200 Subject: Adds help document, adds block quote support, updates gemini parser to newest spec, adds support for arbitrary gemini files in about: space, adds url bar shortcut, fixes bug with line breaks in preformatted text --- src/geminirenderer.cpp | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'src/geminirenderer.cpp') diff --git a/src/geminirenderer.cpp b/src/geminirenderer.cpp index fd475ce..d497a6c 100644 --- a/src/geminirenderer.cpp +++ b/src/geminirenderer.cpp @@ -29,9 +29,6 @@ std::unique_ptr GeminiRenderer::render( DocumentStyle const & themed_style, DocumentOutlineModel &outline) { - QTextOption no_wrap; - no_wrap.setWrapMode(QTextOption::NoWrap); - QTextCharFormat preformatted; preformatted.setFont(themed_style.preformatted_font); preformatted.setForeground(themed_style.preformatted_color); @@ -67,17 +64,25 @@ std::unique_ptr GeminiRenderer::render( std::unique_ptr result = std::make_unique(); result->setDocumentMargin(themed_style.margin); result->background_color = themed_style.background_color; - result->setDefaultTextOption(no_wrap); - + result->setIndentWidth(20); bool emit_fancy_text = global_settings.value("text_decoration").toBool(); QTextCursor cursor{result.get()}; - QTextBlockFormat non_list_format = cursor.blockFormat(); + QTextBlockFormat standard_format = cursor.blockFormat(); + + QTextBlockFormat preformatted_format = standard_format; + preformatted_format.setNonBreakableLines(true); + + QTextBlockFormat block_quote_format = standard_format; + block_quote_format.setIndent(1); + block_quote_format.setBackground(themed_style.blockquote_color); + bool verbatim = false; QTextList *current_list = nullptr; + bool blockquote = false; outline.beginBuild(); @@ -94,18 +99,19 @@ std::unique_ptr GeminiRenderer::render( { if (line.startsWith("```")) { + cursor.setBlockFormat(standard_format); verbatim = false; } else { - cursor.block().layout()->setTextOption(no_wrap); + cursor.setBlockFormat(preformatted_format); cursor.setCharFormat(preformatted); cursor.insertText(line + "\n"); } } else { - if (line.startsWith("*")) + if (line.startsWith("* ")) { if (current_list == nullptr) { @@ -127,11 +133,31 @@ std::unique_ptr GeminiRenderer::render( if (current_list != nullptr) { cursor.insertBlock(); - cursor.setBlockFormat(non_list_format); + cursor.setBlockFormat(standard_format); } current_list = nullptr; } + if(line.startsWith(">")) + { + if(not blockquote ) { + // cursor.insertBlock(); + } + blockquote = true; + + cursor.setBlockFormat(block_quote_format); + cursor.insertText(trim_whitespace(line.mid(1)) + "\n", standard); + + continue; + } + else + { + if(blockquote) { + cursor.setBlockFormat(standard_format); + } + blockquote = false; + } + if (line.startsWith("###")) { auto heading = trim_whitespace(line.mid(3)); @@ -234,6 +260,8 @@ std::unique_ptr GeminiRenderer::render( { if(emit_fancy_text) { + // TODO: Fix UTF-8 encoding here… Don't emit single characters but always spans! + bool rendering_bold = false; bool rendering_underlined = false; -- cgit v1.2.3