Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom TagHandler for <code> tags to add monospace typeface #1149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DieBauer
Copy link

@DieBauer DieBauer commented Sep 22, 2018

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 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 the Html.fromHtml encounters a tag that it doesn't recognize (pre and/or code), however this then involves more or less duplicating the Android standard library that formats the tt 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

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.
@DieBauer DieBauer changed the title Downgrade the html5 <pre><code> tags with html4 <tt> Add custom TagHandler for <code> tags to add monospace typeface Sep 23, 2018
@jblebrun
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants