]> source.dussan.org Git - gitea.git/commitdiff
Pass link prefixes to external markup parsers (#5201)
authorNicolas Lenz <nicolas@eisfunke.com>
Tue, 30 Oct 2018 14:34:12 +0000 (15:34 +0100)
committertechknowlogick <hello@techknowlogick.com>
Tue, 30 Oct 2018 14:34:12 +0000 (10:34 -0400)
* Pass environment variables for URL prefixes to external markup parser

Signed-off-by: Nicolas Lenz <nicolas@eisfunke.com>
* Document external markup link prefix environment variables

Signed-off-by: Nicolas Lenz <nicolas@eisfunke.com>
* Run format on link prefix changes

Signed-off-by: Nicolas Lenz <nicolas@eisfunke.com>
docs/content/doc/advanced/config-cheat-sheet.en-us.md
modules/markup/external/external.go

index 4dbc4c0d7cdfd61e205799c0b71d35c2e1421d77..1c327f6073a69de60e3266b1e3b8a37a5b0fd71e 100644 (file)
@@ -359,6 +359,10 @@ IS_INPUT_FILE = false
 - RENDER\_COMMAND: External command to render all matching extensions.
 - IS\_INPUT\_FILE: **false** Input is not a standard input but a file param followed `RENDER_COMMAND`.
 
+Two special environment variables are passed to the render command:
+- `GITEA_PREFIX_SRC`, which contains the current URL prefix in the `src` path tree. To be used as prefix for links.
+- `GITEA_PREFIX_RAW`, which contains the current URL prefix in the `raw` path tree. To be used as prefix for image paths.
+
 ## Other (`other`)
 
 - `SHOW_FOOTER_BRANDING`: **false**: Show Gitea branding in the footer.
index 676ec4b4c5b85687f5f8b8b0e19b72a1489436a6..73bf7a327e7afe72928e889bf6455bec2d5ffd12 100644 (file)
@@ -76,6 +76,11 @@ func (p *Parser) Render(rawBytes []byte, urlPrefix string, metas map[string]stri
        }
 
        cmd := exec.Command(commands[0], args...)
+       cmd.Env = append(
+               os.Environ(),
+               "GITEA_PREFIX_SRC="+urlPrefix,
+               "GITEA_PREFIX_RAW="+strings.Replace(urlPrefix, "/src/", "/raw/", 1),
+       )
        if !p.IsInputFile {
                cmd.Stdin = rd
        }