-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add init support of orgmode document type on file view and readme #2525
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a73058f
add init support of orgmode document type on file view and readme
lunny 2cafa3c
fix imports
lunny bb044eb
fix imports and readmeExist
lunny 378f34a
fix imports order
lunny c27558e
fix format
lunny f2eac3d
remove unnecessary convert
lunny f53ee7c
Merge branch 'master' into lunny/org-mode-support2
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2017 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package markup | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/markup" | ||
"code.gitea.io/gitea/modules/markup/markdown" | ||
|
||
"github.com/chaseadamsio/goorgeous" | ||
"github.com/russross/blackfriday" | ||
) | ||
|
||
func init() { | ||
markup.RegisterParser(Parser{}) | ||
} | ||
|
||
// Parser implements markup.Parser for orgmode | ||
type Parser struct { | ||
} | ||
|
||
// Name implements markup.Parser | ||
func (Parser) Name() string { | ||
return "orgmode" | ||
} | ||
|
||
// Extensions implements markup.Parser | ||
func (Parser) Extensions() []string { | ||
return []string{".org"} | ||
} | ||
|
||
// Render renders orgmode rawbytes to HTML | ||
func Render(rawBytes []byte, urlPrefix string, metas map[string]string, isUncyclo bool) []byte { | ||
htmlFlags := blackfriday.HTML_USE_XHTML | ||
htmlFlags |= blackfriday.HTML_SKIP_STYLE | ||
htmlFlags |= blackfriday.HTML_OMIT_CONTENTS | ||
renderer := &markdown.Renderer{ | ||
Renderer: blackfriday.HtmlRenderer(htmlFlags, "", ""), | ||
URLPrefix: urlPrefix, | ||
IsUncyclo: isUncyclo, | ||
} | ||
|
||
result := goorgeous.Org(rawBytes, renderer) | ||
return result | ||
} | ||
|
||
// RenderString reners orgmode string to HTML string | ||
func RenderString(rawContent string, urlPrefix string, metas map[string]string, isUncyclo bool) string { | ||
return string(Render([]byte(rawContent), urlPrefix, metas, isUncyclo)) | ||
} | ||
|
||
// Render implements markup.Parser | ||
func (Parser) Render(rawBytes []byte, urlPrefix string, metas map[string]string, isUncyclo bool) []byte { | ||
return Render(rawBytes, urlPrefix, metas, isUncyclo) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2017 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package markup | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/markup" | ||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const AppURL = "http://localhost:3000/" | ||
const Repo = "gogits/gogs" | ||
const AppSubURL = AppURL + Repo + "/" | ||
|
||
func TestRender_StandardLinks(t *testing.T) { | ||
setting.AppURL = AppURL | ||
setting.AppSubURL = AppSubURL | ||
|
||
test := func(input, expected string) { | ||
buffer := RenderString(input, setting.AppSubURL, nil, false) | ||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||
} | ||
|
||
googleRendered := `<p><a href="https://google.com/" title="https://google.com/">https://google.com/</a></p>` | ||
test("[[https://google.com/]]", googleRendered) | ||
|
||
lnk := markup.URLJoin(AppSubURL, "UncycloPage") | ||
test("[[UncycloPage][UncycloPage]]", | ||
`<p><a href="`+lnk+`" title="UncycloPage">UncycloPage</a></p>`) | ||
} | ||
|
||
func TestRender_Images(t *testing.T) { | ||
setting.AppURL = AppURL | ||
setting.AppSubURL = AppSubURL | ||
|
||
test := func(input, expected string) { | ||
buffer := RenderString(input, setting.AppSubURL, nil, false) | ||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer)) | ||
} | ||
|
||
url := "../../.images/src/02/train.jpg" | ||
title := "Train" | ||
result := markup.URLJoin(AppSubURL, url) | ||
|
||
test( | ||
"[[file:"+url+"]["+title+"]]", | ||
`<p><a href="`+result+`"><img src="`+result+`" alt="`+title+`" title="`+title+`" /></a></p>`) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
?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.
No reason. Just copied from markdown test.