-
Notifications
You must be signed in to change notification settings - Fork 221
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
Improve links behavior in Markdown files + rendering tweaks #1147
Conversation
|
||
private static String rewriteUrlsInAttribute(String attribute, String html, String baseUrl) { | ||
final Matcher matcher = Pattern.compile("(" + attribute + ")=\"(\\S+)\"").matcher(html); | ||
final StringBuffer sb = new StringBuffer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have two iterations per rewrite now instead of one, I wonder whether it wouldn't make sense to check whether there's any match at all first, and if there isn't, return html
right away?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you would have 3 iterations in case you have a match and still one in any case... I don't think there is a concrete performance penalty that justifies a preliminary check, which would still involve a full text scan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then lazy init sb
in the first 'found match' run and return html
instead of sb
if it's still null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then lazy init sb in the first 'found match' run and return html instead of sb if it's still null.
I didn't fully understand what you meant with this, but it seemed to me that the goal was to avoid the copy of the html
string in the StringBuffer.
I did another thing instead: I've set the initial capacity of the StringBuffer to the length of html
, to minimize the number of copies/reallocations when appending to the buffer.
I think that any other change that would make the logic more complex is simply not worth it. In the best case you would only save a few memory allocations.
Link URLs are now rewritten to be github.com absolute URLs instead of raw.github.com, so that the file they point to can be opened directly in OctoDroid.
Now reuses the same logic of the Readme preview, handles relative paths to the current file and works with <img> tags in Markdown too
I've also found out that updating Showdown makes Markdown anchor links work in WebView! |
Oh, I see why. The anchor links in that Readme have a <h2 dir="auto">
<a id="user-content-frequently-requested-features" class="anchor" aria-hidden="true" href="#frequently-requested-features">[... omitted ...]</a>
<a name="user-content-frequently-requested-features"></a>Frequently requested features
</h2> The only way to fix this would be not to generate the HTML with Showdown.js, but instead retrieve it directly from GitHub API. |
This PR makes further improvements to the behavior of links especially in Markdown files, which enable a better user experience:
mailto:
links (the introduction of Improve links behavior #1118 made them unopenable)Last but not least, I've made some minor improvements to Markdown-in-WebView styling: better paragraph spacing, fix for invisible separators and some more (4bc9f50). Here's a representative comparison (image was broken since the old URL rewriting in showdown.js didn't work with
<img>
tags in Markdown):Fixes #1090
Closes #764