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 reStructedText support #2564

Closed
wants to merge 5 commits into from
Closed

Conversation

lunny
Copy link
Member

@lunny lunny commented Sep 21, 2017

should be part of #374, see below screenshots.

-1
-2

@lunny lunny added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Sep 21, 2017
@lunny lunny added this to the 1.3.0 milestone Sep 21, 2017
@lunny lunny added the pr/wip This PR is not ready for review label Sep 21, 2017
@codecov-io
Copy link

codecov-io commented Sep 21, 2017

Codecov Report

Merging #2564 into master will increase coverage by 0.04%.
The diff coverage is 70%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
modules/markup/orgmode/orgmode.go 90.9% <ø> (ø) ⬆️
...odules/markup/reStructuredText/reStructuredText.go 70% <70%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fa6d7c7...6a4f0f8. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Sep 21, 2017
@lunny lunny removed the pr/wip This PR is not ready for review label Sep 22, 2017
@lunny
Copy link
Member Author

lunny commented Sep 22, 2017

Tests added and rebased.

@lafriks
Copy link
Member

lafriks commented Sep 22, 2017

LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Sep 22, 2017
)

const AppURL = "http://localhost:3000/"
const Repo = "gogits/gogs"
Copy link
Member

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
Copy link
Member

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) {
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@lunny
Copy link
Member Author

lunny commented Sep 23, 2017

@Morlinest all done.

Copy link
Member

@ethantkoenig ethantkoenig left a 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()
Copy link
Member

@ethantkoenig ethantkoenig Sep 24, 2017

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@lunny
Copy link
Member Author

lunny commented Sep 24, 2017

@ethantkoenig Yes, but this is the most mature library I can find. Also, if #2570 could be merged, external tool could override internal library.

defer func() {
setting.AppURL = appURL
setting.AppSubURL = appSubURL
}()
Copy link
Member

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)

Copy link
Member

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)
Copy link
Member

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 + "/"
Copy link
Member

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) {
Copy link
Member

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.

Copy link
Member

@ethantkoenig ethantkoenig left a 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.

@lunny
Copy link
Member Author

lunny commented Sep 25, 2017

@ethantkoenig I don't mind to put this PR later. If #2570 could be merged, it also resolved #374.

@lunny lunny modified the milestones: 1.3.0, 1.x.x Sep 25, 2017
@lunny
Copy link
Member Author

lunny commented Sep 25, 2017

And maybe https://github.com/demizer/go-rst is a better choice.

@lunny lunny added the pr/wip This PR is not ready for review label Sep 25, 2017
@lunny lunny added the status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR label Sep 25, 2017
@lunny lunny changed the title Add reStructedText support and fix readme render bug Add reStructedText support Nov 7, 2017
@ghost
Copy link

ghost commented Jul 21, 2018

@lunny go-rst is marked as ABANDONED. I think with #374 closed this could also be closed.

@bkcsoft bkcsoft added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jul 21, 2018
@lunny lunny removed this from the 1.x.x milestone Jul 22, 2018
@lunny lunny closed this Jul 22, 2018
@lunny lunny deleted the lunny/reStructedText branch November 18, 2020 04:34
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. pr/wip This PR is not ready for review status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants