-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Rework special link parsing in the post-processing of markup #3354
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
Conversation
Oh, I guess I kinda forgot about the unit tests... will need to rewrite them |
But this will not render commit with just short sha clickable if I'm not wrong |
It should still do AFAIK? What do you mean? I've placed [WIP] on the header for the moment because I'm too tired now to iron out the remaining issue, but it's mostly done |
I mean this (taken from tests): |
Codecov Report
@@ Coverage Diff @@
## master #3354 +/- ##
==========================================
+ Coverage 35.79% 36.15% +0.35%
==========================================
Files 285 285
Lines 40868 40905 +37
==========================================
+ Hits 14630 14790 +160
+ Misses 24068 23943 -125
- Partials 2170 2172 +2
Continue to review full report at Codecov.
|
Since I got sick of the state of html.go, I rewrote it entirely making it use an HTML tree instead of a tokenizer + a bunch of sprintfs. I took the chance also to rewrite a bunch of stuff. It just so happened that because this enabled much more modularity than before, it also meant that implementing #2968 was pretty trivial. Note that this does not enable markdown on commits. Reviews welcome. |
@thehowl Thanks for you great PR. I think we have serval kinds of render scenes. Markup File on the tree, Wiki, Issues(comments) and Notification Mail body. Currently, all support markdown syntax and Gitea Postprocesses. Markup File supports other syntax and Gitea Postprocesses. But there are some differences between markup files and wikis. So a set of Post processes could be a group, markup files and wikis could be different group. |
You mean to make this into a different package? |
In Gitea 1.3.2, a URL like Is this related to the work being done here? |
@ypnos Slightly related, however the link you posted doesn't look like a case we need to handle seeing as it is an URL for a GitHub issue, and not the local instance. On the local instance, that is something we already handle; see this: https://try.gitea.io/Howl/aaa/issues/1 |
This is just an example of an external link with a dash in it. So external URLs in the format |
External links in general are a part of this PR, though they were already supported before (using js, that is). They render as a simple link, e.g. https://google.com, instead of https://google.com. Is that what you mean? |
Great, so the current behavior is buggy and I wondered if you could check the new code for this. Please have a look at my example comment at https://try.gitea.io/Howl/aaa/issues/1 |
Interesting. Then yes, the bug still exists in my code. The way this could be solved is by, instead of using a regex, to use strings.FieldsFunc and find in the resulting array the strings beginning with As a workaround, I recommend you use the standard markdown feature, which is that of wrapping the URL in angle brackets (e.g. |
Thank you. After some of my own research on regular expressions for matching URLs I conclude that it is not worth the trouble for achieving more proper URL detection, hence I will not file another issue on this. Btw. I also believe the more complicated approach with url.Parse would not be the end to it, for example it would most probably include a period at the end of the URL, which should in general be excluded. |
rebased onto master. Please review. |
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.
Other than these small issues otherwise it LG-TM
modules/markup/html.go
Outdated
} | ||
|
||
// remove initial parts - because Render creates a whole HTML page. | ||
const lenInit = len(`<html><head></head><body>`) |
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.
Can this instead use find <body>
in string and respective closing tag to be more future proof?
modules/markup/markup.go
Outdated
@@ -69,7 +69,8 @@ func RenderWiki(filename string, rawBytes []byte, urlPrefix string, metas map[st | |||
func render(parser Parser, rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte { | |||
urlPrefix = strings.Replace(urlPrefix, " ", "+", -1) | |||
result := parser.Render(rawBytes, urlPrefix, metas, isWiki) | |||
result = PostProcess(result, urlPrefix, metas, isWiki) | |||
// TODO: one day the error should be checked and returned. | |||
result, _ = PostProcess(result, urlPrefix, metas, isWiki) |
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.
Error should be at least logged
modules/templates/helper.go
Outdated
cleanMsg := template.HTMLEscapeString(msg) | ||
fullMessage := string(markup.RenderIssueIndexPattern([]byte(cleanMsg), opts)) | ||
body := strings.Split(strings.TrimSpace(fullMessage), "\n") | ||
fullMessage, _ := markup.RenderCommitMessage([]byte(cleanMsg), urlPrefix, "", metas) |
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.
Log error
modules/templates/helper.go
Outdated
msgLines := strings.Split(strings.TrimSpace(fullMessage), "\n") | ||
// we can safely assume that it will not return any error, since there | ||
// shouldn't be any special HTML. | ||
fullMessage, _ := markup.RenderCommitMessage([]byte(cleanMsg), urlPrefix, urlDefault, metas) |
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.
Same here, log error
@@ -0,0 +1,378 @@ | |||
package markup |
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.
Missing license comment
modules/markup/html_internal_test.go
Outdated
|
||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/util" | ||
"github.com/stretchr/testify/assert" |
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.
Missing empty line between local and external package.
See https://github.com/go-gitea/gitea/blob/master/CONTRIBUTING.md#styleguide
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.
Addressed.
…er changes to processor logic
This is just a description to allow me to force push in order to restart the drone build.
Fixes #3327. Adds the ability to link emails in markdown, both
[email protected]
,<[email protected]>
and[hello](mailto:[email protected])
, all of which previously didn't work. Also removed the autolink js library, as the link processing can be very easily done on the backend using a very simple blackfriday option.Closes #3364. Closes #652.
In the new mechanism, the post processing is done by passing the input through a given set of functions, passed to a new
postProcessCtx
. This enables the ability to customise the post-processing features to enable, and thus also closes #2968. It also enables in the commit message many other features, such as linking, writing emails, and basically everything PostProcess does except for shortlinks.Closes #3112 as well.
The only thing that seems to be needed is some unit tests, but this should be on its way for 1.5