Add custom TagHandler for <code> tags to add monospace typeface #1149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The textview supports formatting of a few built-in html tags,
tt
(teletype) is deprecated in html5, but for android this is still implementedAdvantages of this
tt
formatting is that it respects newlines and whitespace using a monospace font, which makes code formatted comments on Hackernews better readable.Hackernews, makes use of the html5 successor
<pre><code>
to format code blocks with a monospace font. In order to add support to the textview we need to transform the input, or adjust the presentation.One solution takes a regex and replaces the tags for every comment.
Another solution is to implement a
TagHandler
that is being called when theHtml.fromHtml
encounters a tag that it doesn't recognize (pre
and/orcode
), however this then involves more or less duplicating the Android standard library that formats thett
tag currently.The latter has the advantage that it only kicks in when the comment / text contains such a tag, thus being more efficient, with the same result. And it is more futureproof.
Addresses #883 and #1037