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!
main
dece 2 years ago
parent 9c0603cf67
commit 117c70100f

@ -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 "") }

@ -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++

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

Loading…
Cancel
Save