From 117c70100f5a4292764fad8616d94ae5ccceaea5 Mon Sep 17 00:00:00 2001 From: dece Date: Fri, 28 Jan 2022 12:00:11 +0100 Subject: [PATCH] consider blockquotes as a blocks instead of lines This is roughly the same system as for preformatted blocks. Even though the spec implies that a line starting with ">" is a blockquote type line and should be a quote on its own, it is so frequently used as a block-like type that taking the spec literally causes rendering issues on many capsules. To be clear, we get blocks like this: > Lorem ipsum dolor sit amet, > consectetur adipiscing elit. > > Sed do eiusmod tempor incididunt > ut labore et dolore magna aliqua. where we should instead have something like: > Lorem ipsum dolor sit amet, consectetur adipiscing elit. > Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. To the people's defense, it is usual to quote a message using the first syntax. As this issue is minor and the spec is not very adamant on things here, I don't think there is much wrongdoing in treating the first syntax as the norm, but the code is open to changes! --- .../java/dev/lowrespalmtree/comet/Gemtext.kt | 3 +-- .../dev/lowrespalmtree/comet/PageAdapter.kt | 10 ++++++++-- app/src/main/res/layout/gemtext_blockquote.xml | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/dev/lowrespalmtree/comet/Gemtext.kt b/app/src/main/java/dev/lowrespalmtree/comet/Gemtext.kt index be46b4f..7301d70 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/Gemtext.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/Gemtext.kt @@ -61,8 +61,7 @@ private fun parseLine(line: CharBuffer, isPreformatted: Boolean): Line = line.startsWith("##") -> TitleLine(2, getCharsFrom(line, 2)) line.startsWith("#") -> TitleLine(1, getCharsFrom(line, 1)) line.startsWith("* ") -> ListItemLine(getCharsFrom(line, 2)) - line.startsWith(">") -> getCharsFrom(line, 1) // eh empty lines in quotes… - .run { if (isBlank()) EmptyLine() else BlockquoteLine(this) } + line.startsWith(">") -> BlockquoteLine(getCharsFrom(line, 1)) line.startsWith("=>") -> getCharsFrom(line, 2) .split(" ", "\t", limit = 2) .run { LinkLine(get(0), if (size == 2) get(1).trimStart() else "") } diff --git a/app/src/main/java/dev/lowrespalmtree/comet/PageAdapter.kt b/app/src/main/java/dev/lowrespalmtree/comet/PageAdapter.kt index 614154a..434a622 100644 --- a/app/src/main/java/dev/lowrespalmtree/comet/PageAdapter.kt +++ b/app/src/main/java/dev/lowrespalmtree/comet/PageAdapter.kt @@ -37,7 +37,7 @@ class PageAdapter(private val listener: ContentAdapterListener) : class Title(val text: String, val level: Int) : ContentBlock() class Link(val url: String, val label: String) : ContentBlock() class Pre(val caption: String, var content: String, var closed: Boolean) : ContentBlock() - class Blockquote(val text: String) : ContentBlock() + class Blockquote(var text: String) : ContentBlock() class ListItem(val text: String) : ContentBlock() } @@ -57,7 +57,6 @@ class PageAdapter(private val listener: ContentAdapterListener) : is EmptyLine -> blocks.add(ContentBlock.Empty) is ParagraphLine -> blocks.add(ContentBlock.Paragraph(line.text)) is LinkLine -> blocks.add(ContentBlock.Link(line.url, line.label)) - is BlockquoteLine -> blocks.add(ContentBlock.Blockquote(line.text)) is ListItemLine -> blocks.add(ContentBlock.ListItem(line.text)) is TitleLine -> blocks.add(ContentBlock.Title(line.text, line.level)) is PreFenceLine -> { @@ -78,6 +77,13 @@ class PageAdapter(private val listener: ContentAdapterListener) : lastBlock.content += line.text + "\n" else Log.e(TAG, "setLines: unexpected preformatted line") + } + } + is BlockquoteLine -> { + if (blocks.isNotEmpty() && blocks.last() is ContentBlock.Blockquote) + (blocks.last() as ContentBlock.Blockquote).text += "\n" + line.text + else + blocks.add(ContentBlock.Blockquote(line.text)) } } currentLine++ diff --git a/app/src/main/res/layout/gemtext_blockquote.xml b/app/src/main/res/layout/gemtext_blockquote.xml index 5ec7b94..30fa5a8 100644 --- a/app/src/main/res/layout/gemtext_blockquote.xml +++ b/app/src/main/res/layout/gemtext_blockquote.xml @@ -1,9 +1,15 @@ - \ No newline at end of file + android:paddingStart="16dp" + android:paddingEnd="16dp"> + +