-
-
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 external markup render support #2570
Conversation
d1e36e9
to
97c28e9
Compare
Codecov Report
@@ Coverage Diff @@
## master #2570 +/- ##
=======================================
Coverage 26.85% 26.85%
=======================================
Files 89 89
Lines 17607 17607
=======================================
Hits 4728 4728
Misses 12193 12193
Partials 686 686 Continue to review full report at Codecov.
|
conf/app.ini
Outdated
@@ -551,3 +551,12 @@ SHOW_FOOTER_BRANDING = false | |||
SHOW_FOOTER_VERSION = true | |||
; Show time of template execution in the footer | |||
SHOW_FOOTER_TEMPLATE_LOAD_TIME = true | |||
|
|||
[markup.asciidoc] | |||
ENABLED = true |
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 that this example markup renderer should be disabled by default or in this example because it requires third party tools.
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.
@JonasFranzDEV this file is an example file. It will not effect anything if you upgrade.
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.
The example should follow the default values, shouldn't it?
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.
[markup.xxxx]
are dynamic sections. Default values is no any [markup.xxxx]
section just like this PR did. I put this section on the example ini file for others know how to add one or more tools. Also I will add these to config cheatsheet but I think put it in example ini file is easier to find for users.
modules/markup/external/external.go
Outdated
// RegisterParsers registers all supported third part parsers according settings | ||
func RegisterParsers() { | ||
for _, render := range setting.ExternalMarkupRenders { | ||
if render.Enabled && render.Command != "" && len(render.FileExtensions) > 0 { |
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.
It might be good to validate the file extension to deny illegal file extensions.
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.
For example?
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.
.<iframe>
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.
But if you can change the ini file. I will trust you.
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.
We could only allow the regex \.\w
? This would prevent misconfiguration.
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.
Just a random thought... somehow I don't like that external tool is called (and I know there is no go alternatives) |
@lafriks any name proposed if you don't like external? |
@lunny I think he means calling |
@Morlinest oh, I see. |
modules/markup/external/external.go
Outdated
} | ||
|
||
_, err = io.Copy(f, rd) | ||
f.Close() |
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.
File.Close() 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.
I don't think this is needed. We have handle the err returned above line.
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.
What if the copy is successful, but there's an error closing the file?
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.
@ethantkoenig we will ignore that since it's a temp file. It will not effect the rendering.
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.
Maybe good to check to prevent leaks?
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.
added.
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.
We still don't check the error
modules/markup/external/external.go
Outdated
fPath := filepath.Join(os.TempDir(), gouuid.NewV4().String()) | ||
f, err := os.Create(fPath) | ||
if err != nil { | ||
log.Error(4, "%s render run command %s failed: %v", p.Name(), p.Command, err) |
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.
Incorrect error message
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.
modules/markup/external/external.go
Outdated
var rd = bytes.NewReader(rawBytes) | ||
commands := strings.Fields(p.Command) | ||
var command = commands[0] | ||
var args []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.
Can just do args := commands[1:]
, since we're already assuming commands
is not empty
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.
97c28e9
to
0900445
Compare
modules/markup/external/external.go
Outdated
return p.MarkupName | ||
} | ||
|
||
// 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.
Rewrite comments please, it should tell what is the function doing.
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.
modules/markup/external/external.go
Outdated
} | ||
|
||
_, err = io.Copy(f, rd) | ||
f.Close() |
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.
Maybe good to check to prevent leaks?
0900445
to
f0f93e0
Compare
f0f93e0
to
662bff9
Compare
@sapk @JonasFranzDEV @Morlinest all done. |
662bff9
to
6a274c7
Compare
@sapk @JonasFranzDEV @Morlinest rebased. |
modules/markup/external/external.go
Outdated
|
||
_, err = io.Copy(f, rd) | ||
f.Close() | ||
os.Remove(fPath) |
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 do we delete the file immediately after writing to it?
modules/markup/external/external.go
Outdated
} | ||
|
||
_, err = io.Copy(f, rd) | ||
f.Close() |
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.
We still don't check the error
6a274c7
to
72817ce
Compare
@ethantkoenig done. |
modules/markup/external/external.go
Outdated
|
||
if p.IsInputFile { | ||
// write to templ file | ||
fPath := filepath.Join(os.TempDir(), gouuid.NewV4().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.
You should check if the file already exists although it is very unlikely to happen. Or as an alternative you could add this check to your err != nil
check at line 60.
72817ce
to
4bcca9d
Compare
@JonasFranzDEV done. |
@lunny IMO it would be better to use I don't rly like the way how it is initialized (hard dependency on setting package), I want to look if there is no better way. |
@Morlinest did you mean put this note on the setting file?
|
@lunny No, it is already there. As comment on function where we set setting variables.
|
modules/setting/setting.go
Outdated
@@ -60,6 +60,15 @@ const ( | |||
LandingPageExplore LandingPage = "/explore" | |||
) | |||
|
|||
// MarkupParser defines the external parser configed on ini |
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.
nit: configured in
modules/markup/external/external.go
Outdated
) | ||
|
||
if p.IsInputFile { | ||
// write to templ file |
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.
nit: temp
LGTM just two typos |
b43874b
to
640eaba
Compare
@ethantkoenig done. |
just wondering, is the expected output of the render command html? |
@kellpossible Yes. |
Will close #374.
Usage:
Add the below to your
custom/conf/app.ini
file. You can add one or more sections. The section name shouldmarkup.xxxxx
, which you can name it as you like. Follow the below config items then restart yourgitea
, it's done. For example:On MacOS,
Then add below config to your
custom/conf/app.ini
file and restart. Migrationhttps://github.com/maxandersen/gdoc2adoc.git
and then view the.adoc
file.