Add custom TagHandler for <code> tags to add monospace typeface#1149
Open
DieBauer wants to merge 2 commits intohidroh:masterfrom
Open
Add custom TagHandler for <code> tags to add monospace typeface#1149DieBauer wants to merge 2 commits intohidroh:masterfrom
DieBauer wants to merge 2 commits intohidroh:masterfrom
Conversation
The textview supports formatting of a few built-in html tags, `tt` (teletype) is deprecated in html5, but for android this is still implemented Advantages of this `tt` formatting is that it respects newlines and whitespace, which makes code formatted comments on Hackernews better readable. Fixes hidroh#883
Advantage over regex is that this handling only kicks in the moment the text contains such a <code> tag.
<pre><code> tags with html4 <tt>|
Thanks for doing this, I was just about to investigate doing something similar, and discovered that you've already got this PR up. I would love to see this get merged in! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
ttformatting 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
TagHandlerthat is being called when theHtml.fromHtmlencounters a tag that it doesn't recognize (preand/orcode), however this then involves more or less duplicating the Android standard library that formats thetttag 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