Skip to content

Commit 220ee6a

Browse files
Eisfunketechknowlogick
authored andcommitted
Pass link prefixes to external markup parsers (#5201)
* Pass environment variables for URL prefixes to external markup parser Signed-off-by: Nicolas Lenz <[email protected]> * Document external markup link prefix environment variables Signed-off-by: Nicolas Lenz <[email protected]> * Run format on link prefix changes Signed-off-by: Nicolas Lenz <[email protected]>
1 parent e61c6cd commit 220ee6a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ IS_INPUT_FILE = false
359359
- RENDER\_COMMAND: External command to render all matching extensions.
360360
- IS\_INPUT\_FILE: **false** Input is not a standard input but a file param followed `RENDER_COMMAND`.
361361

362+
Two special environment variables are passed to the render command:
363+
- `GITEA_PREFIX_SRC`, which contains the current URL prefix in the `src` path tree. To be used as prefix for links.
364+
- `GITEA_PREFIX_RAW`, which contains the current URL prefix in the `raw` path tree. To be used as prefix for image paths.
365+
362366
## Other (`other`)
363367

364368
- `SHOW_FOOTER_BRANDING`: **false**: Show Gitea branding in the footer.

modules/markup/external/external.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ func (p *Parser) Render(rawBytes []byte, urlPrefix string, metas map[string]stri
7676
}
7777

7878
cmd := exec.Command(commands[0], args...)
79+
cmd.Env = append(
80+
os.Environ(),
81+
"GITEA_PREFIX_SRC="+urlPrefix,
82+
"GITEA_PREFIX_RAW="+strings.Replace(urlPrefix, "/src/", "/raw/", 1),
83+
)
7984
if !p.IsInputFile {
8085
cmd.Stdin = rd
8186
}

0 commit comments

Comments
 (0)