forgejo-aneksajo/modules/markup
Michael Hanke 195388ba62 Elevate external markup renderer interface for annexed file content (#36)
Previously, an external renderer that matched on an annexed file would
only see its content streamed via `STDIN`, or a temporary file with a copy
of its content would be generated and passed-by-filepath (with
`IS_INPUT_FILE=true`). Whether that happens, is also subject to
`MAX_DISPLAY_FILE_SIZE` (which defaults to 8MB).

This was problematic, because annexed files tend to be large. Moreover,
if present, they already exist as write-protected files on the
file-system. Creating a copy is both expensive and serves no particular
purpose.

This commit changes how external renderers are called.

1) With `IS_INPUT_FILE=true`, the renderer is passed the true location
   of an annex key, if present, and an empty path, if not.
2) The original, repository-relative path of the rendering target is
   made available to the renderer via the `GITEA_RELATIVE_PATH`
   environment variable.

To achieve a lean implementation, the `Blob` of the rendering target
is passed on to the `RenderContext` (because the implementation of
the annex-related functionality is centered on this dtype.

This change makes it less costly to increase `MAX_DISPLAY_FILE_SIZE`,
in order to make large, annexed files eligible for markup rendering,
because no content copies will be made any longer.

External renderers can now use the original file path, with the full
original filename, including extensions, for decision making. For
example, to detect particular compression formats based in a file name
extension, or to alter the rendering based on contextual information
encoded in the file path (e.g., a multi-file data structure with a
particular organization pattern).

Apart from the additional environment variable, there is no change to
the handling of renderers that take their input via `STDIN` (i.e.,
`IS_INPUT_FILE=false`).

Fixes #35.

Reviewed-on: https://codeberg.org/matrss/forgejo-aneksajo/pulls/36
Reviewed-by: matrss <matrss@noreply.codeberg.org>
Co-authored-by: Michael Hanke <michael.hanke@gmail.com>
Co-committed-by: Michael Hanke <michael.hanke@gmail.com>
2025-03-24 09:06:59 +01:00
..
asciicast Fix and refactor markdown rendering (#32522) 2024-11-17 20:34:28 +01:00
common [GITEA] test markdown CleanValue to prevent regression 2024-02-05 16:09:41 +01:00
console Construct screen 2024-09-06 20:24:51 +02:00
csv Fix and refactor markdown rendering (#32522) 2024-11-17 20:34:28 +01:00
external Elevate external markup renderer interface for annexed file content (#36) 2025-03-24 09:06:59 +01:00
markdown [v10.0/forgejo] fix: render link in heading correctly in TOC (#6859) 2025-02-08 14:33:01 +00:00
mdstripper chore: fix deprecation 2024-11-02 16:39:27 +01:00
orgmode Update module github.com/alecthomas/chroma/v2 to v2.15.0 (v10.0/forgejo) (#6553) 2025-01-14 21:40:06 +00:00
tests/repo/repo1_filepreview [v10.0/forgejo] fix inline file preview for files with encoded URL, fix #5069 (#6739) 2025-01-30 11:49:16 +00:00
camo.go Use camo.Always instead of camo.Allways (#32097) 2024-09-27 08:45:55 +02:00
camo_test.go Use camo.Always instead of camo.Allways (#32097) 2024-09-27 08:45:55 +02:00
file_preview.go [v10.0/forgejo] fix inline file preview for files with encoded URL, fix #5069 (#6739) 2025-01-30 11:49:16 +00:00
html.go feat: Add partial quoting 2024-10-26 19:15:43 +02:00
html_internal_test.go fix: improve PR/issue short link display text 2024-08-22 15:49:05 -06:00
html_test.go [v10.0/forgejo] fix inline file preview for files with encoded URL, fix #5069 (#6739) 2025-01-30 11:49:16 +00:00
renderer.go Elevate external markup renderer interface for annexed file content (#36) 2025-03-24 09:06:59 +01:00
renderer_test.go Move IsReadmeFile* from modules/markup/ to modules/util (#22877) 2023-02-13 15:01:09 -05:00
sanitizer.go fix: strict matching of allowed content for sanitizer 2024-11-15 10:59:36 +01:00
sanitizer_test.go feat: Add partial quoting 2024-10-26 19:15:43 +02:00