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!
This commit is contained in:
dece 2022-01-28 12:00:11 +01:00
parent 9c0603cf67
commit 117c70100f
3 changed files with 21 additions and 10 deletions

View file

@ -61,8 +61,7 @@ private fun parseLine(line: CharBuffer, isPreformatted: Boolean): Line =
line.startsWith("##") -> TitleLine(2, getCharsFrom(line, 2)) line.startsWith("##") -> TitleLine(2, getCharsFrom(line, 2))
line.startsWith("#") -> TitleLine(1, getCharsFrom(line, 1)) line.startsWith("#") -> TitleLine(1, getCharsFrom(line, 1))
line.startsWith("* ") -> ListItemLine(getCharsFrom(line, 2)) line.startsWith("* ") -> ListItemLine(getCharsFrom(line, 2))
line.startsWith(">") -> getCharsFrom(line, 1) // eh empty lines in quotes… line.startsWith(">") -> BlockquoteLine(getCharsFrom(line, 1))
.run { if (isBlank()) EmptyLine() else BlockquoteLine(this) }
line.startsWith("=>") -> getCharsFrom(line, 2) line.startsWith("=>") -> getCharsFrom(line, 2)
.split(" ", "\t", limit = 2) .split(" ", "\t", limit = 2)
.run { LinkLine(get(0), if (size == 2) get(1).trimStart() else "") } .run { LinkLine(get(0), if (size == 2) get(1).trimStart() else "") }

View file

@ -37,7 +37,7 @@ class PageAdapter(private val listener: ContentAdapterListener) :
class Title(val text: String, val level: Int) : ContentBlock() class Title(val text: String, val level: Int) : ContentBlock()
class Link(val url: String, val label: String) : ContentBlock() class Link(val url: String, val label: String) : ContentBlock()
class Pre(val caption: String, var content: String, var closed: Boolean) : 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() class ListItem(val text: String) : ContentBlock()
} }
@ -57,7 +57,6 @@ class PageAdapter(private val listener: ContentAdapterListener) :
is EmptyLine -> blocks.add(ContentBlock.Empty) is EmptyLine -> blocks.add(ContentBlock.Empty)
is ParagraphLine -> blocks.add(ContentBlock.Paragraph(line.text)) is ParagraphLine -> blocks.add(ContentBlock.Paragraph(line.text))
is LinkLine -> blocks.add(ContentBlock.Link(line.url, line.label)) 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 ListItemLine -> blocks.add(ContentBlock.ListItem(line.text))
is TitleLine -> blocks.add(ContentBlock.Title(line.text, line.level)) is TitleLine -> blocks.add(ContentBlock.Title(line.text, line.level))
is PreFenceLine -> { is PreFenceLine -> {
@ -80,6 +79,13 @@ class PageAdapter(private val listener: ContentAdapterListener) :
Log.e(TAG, "setLines: unexpected preformatted line") 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++ currentLine++
} }
val numAdded = blocks.size - lastBlockCount val numAdded = blocks.size - lastBlockCount

View file

@ -1,9 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout
android:id="@+id/text_view" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="16dp">
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/CometText" style="@style/CometText"
android:textStyle="italic" android:background="@color/background_emph"
android:paddingStart="32dp" android:textStyle="italic" />
android:paddingEnd="16dp" /> </FrameLayout>