-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 reStructedText support #2564
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2564 +/- ##
==========================================
+ Coverage 27.33% 27.38% +0.04%
==========================================
Files 86 87 +1
Lines 17137 17157 +20
==========================================
+ Hits 4684 4698 +14
- Misses 11775 11780 +5
- Partials 678 679 +1
Continue to review full report at Codecov.
|
057ce9d
to
de1bdb8
Compare
Tests added and rebased. |
LGTM |
) | ||
|
||
const AppURL = "http://localhost:3000/" | ||
const Repo = "gogits/gogs" |
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.
Why gogits/gogs
?
|
||
func TestRender_StandardLinks(t *testing.T) { | ||
setting.AppURL = AppURL | ||
setting.AppSubURL = AppSubURL |
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.
Shouldn't settings
be set to previous value at the end of test to avoid affecting other tests? I think simple defer
can be used for that.
setting.AppURL = AppURL | ||
setting.AppSubURL = AppSubURL | ||
|
||
test := func(input, expected string) { |
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.
Create test
as separate function so you can use it for both tests.
return b.Bytes() | ||
} | ||
|
||
// RenderString reners reStructuredText string to HTML string |
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.
reners
- typo? I think you can remove string
from the end of comment.
return []string{".rst"} | ||
} | ||
|
||
// Render renders reStructuredText rawbytes to HTML |
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.
Is not rawbytes
in comment redudant? And should be unified with RenderString
comment.
type Parser struct { | ||
} | ||
|
||
// Name implements markup.Parser |
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.
I think function comment should tell what that function is doing, not which interface it fulfils.
return "reStructuredText" | ||
} | ||
|
||
// Extensions implements markup.Parser |
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 as for Name()
|
||
func TestRender_Images(t *testing.T) { | ||
setting.AppURL = AppURL | ||
setting.AppSubURL = AppSubURL |
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 as above.
de1bdb8
to
249fec3
Compare
@Morlinest all done. |
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.
IMO, using a third-party library that is "experimental/highly under development" (README) is not a good idea. Would it be worth finding a more stable library, or waiting until this one becomes more mature?
var b bytes.Buffer | ||
w := bufio.NewWriter(&b) | ||
p.ReStructuredText(bytes.NewReader(rawBytes), gorst.ToHTML(w)) | ||
w.Flush() |
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.
w.Flush()
returns an error
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.
done.
@ethantkoenig Yes, but this is the most mature library I can find. Also, if #2570 could be merged, external tool could override internal library. |
f9e945b
to
6a4f0f8
Compare
defer func() { | ||
setting.AppURL = appURL | ||
setting.AppSubURL = appSubURL | ||
}() |
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.
I think you can simplify it like this:
defer func(appURL, appSubURL string) {
setting.AppURL = appURL
setting.AppSubURL = appSubURL
}(setting.AppURL, setting.AppSubURL)
or to use same deffer for both tests:
func resetSetings(appURL, appSubURL string) {
setting.AppURL = appURL
setting.AppSubURL = appSubURL
}
...
defer resetSetings(setting.AppURL, setting.AppSubURL)
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.
Now, when I look at whole change at once... Why you need to change settings? I see only setting.AppSubURL
is used in test()
.
const AppSubURL = AppURL + Repo + "/" | ||
|
||
func test(t *testing.T, input, expected string) { | ||
buffer := RenderString(input, setting.AppSubURL, nil, false) |
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.
Use setting.AppSubURL
as another test()
argument. E.g. test(t *testing.T, input, expected, appSubURL string)
|
||
const AppURL = "http://localhost:3000/" | ||
const Repo = "go-gitea/gitea" | ||
const AppSubURL = AppURL + Repo + "/" |
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.
If you don't need all constants (look at comment for defer
), merge them together. Also I think you can use unexported version. E.g. const appSubURL = "http://localhost:3000/go-gitea/gitea/"
.
`<p><a href="`+lnk+`">WikiPage</a></p>`)*/ | ||
} | ||
|
||
func TestRender_Images(t *testing.T) { |
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.
If you don' need to change settings (look at defer
comment above), you can merge both tests together, remove setting
variable changes and defer
and use t.Run()
(just create array of test cases) to run tests in parallel.
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.
I still do not think that using an unstable library is a good idea, but I'll approve so that I don't block the PR.
@ethantkoenig I don't mind to put this PR later. If #2570 could be merged, it also resolved #374. |
And maybe https://github.com/demizer/go-rst is a better choice. |
should be part of #374, see below screenshots.