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

External markup renderers can't use in-repo images #5031

Closed
2 of 7 tasks
pjanx opened this issue Oct 7, 2018 · 2 comments · Fixed by #5201
Closed
2 of 7 tasks

External markup renderers can't use in-repo images #5031

pjanx opened this issue Oct 7, 2018 · 2 comments · Fixed by #5201
Labels
type/enhancement An improvement of existing functionality
Milestone

Comments

@pjanx
Copy link

pjanx commented Oct 7, 2018

  • Gitea version (or commit ref): 1.5.1
  • Git version: master
  • Operating system: Linux
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant

Description

The logic in modules/markup/markdown's (*Renderer).Image is inaccessible to external renderers. Relative image URLs pass through unchanged and wrong.

I can think of two solutions:

  • Expose urlPrefix to the process as an environment variable, such as GITEA_PREFIX_SRC=https://github.com/user/repo/raw/branch/master/subdir/ and GITEA_PREFIX_RAW=/user/repo/raw/branch/master/subdir/. Then you can at least wrap external tools in scripts; asciidoctor just needs to have the imagesdir attribute set appropriately.
  • Change all relative image srcs in a PostProcess step to point to a /raw/ location because they are pointless anyway (a brute force solution would be to use <base href=> in the header template).
@lunny lunny added the type/enhancement An improvement of existing functionality label Oct 7, 2018
@pjanx
Copy link
Author

pjanx commented Oct 11, 2018

Slight generalization of my workaround for nginx, works only for a project's root README:

# Circumventing Gitea issue #5031
# Must not catch POST /user/login, that is an awful surprise
set $redirectable 1;
if ($request_method !~ ^(HEAD|GET)$) {
        set $redirectable 0;
}
if ($request_uri !~ ^(/[^/]+/[^/]+)$) {
        set $redirectable 0;
}
if ($redirectable) {
        return  301 https://$host$request_uri/;
}
#!/bin/sh
external-markup-renderer-invocation | perl -pe '
    # The URL must end with a slash; since <script> does not
    # come through, I had to resolve that in nginx.conf
    s,(<img src=")([^/]*?"),$1raw/branch/master/$2,g'
RENDER_COMMAND = /path/to/that/script

@Eisfunke
Copy link
Contributor

Eisfunke commented Oct 22, 2018

I noticed this too (when using Pandoc as markdown parser) and was just about to open an issue about this.

I would prefer the approach using an environment variable, as this would be more flexible. If there are no objections and I get around to it, I'll try to make a PR doing that.

Also, thanks for the workaround script!

@lunny lunny added this to the 1.7.0 milestone Oct 30, 2018
@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
type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants