Skip to content

Commit 5353d15

Browse files
committed
Document new sanitization configuration
- Adds basic documentation to app.ini.sample, - Adds an example to the Configuration Cheat Sheet, and - Adds extended information to External Renderers section. Signed-off-by: Alexander Scheel <[email protected]>
1 parent 9025a69 commit 5353d15

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

custom/conf/app.ini.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,12 @@ SHOW_FOOTER_VERSION = true
877877
; Show template execution time in the footer
878878
SHOW_FOOTER_TEMPLATE_LOAD_TIME = true
879879

880+
[markup.sanitizer]
881+
; The following keys can be used multiple times to define sanitation policy rules.
882+
;ELEMENT = span
883+
;ALLOW_ATTR = class
884+
;REGEXP = ^(info|warning|error)$
885+
880886
[markup.asciidoc]
881887
ENABLED = false
882888
; List of file extensions that should be rendered by an external command

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,24 @@ Two special environment variables are passed to the render command:
578578
- `GITEA_PREFIX_SRC`, which contains the current URL prefix in the `src` path tree. To be used as prefix for links.
579579
- `GITEA_PREFIX_RAW`, which contains the current URL prefix in the `raw` path tree. To be used as prefix for image paths.
580580

581+
582+
Gitea supports customizing the sanitization policy for rendered HTML. The example below will support KaTeX output from pandoc.
583+
584+
```ini
585+
[markup.sanitizer]
586+
; Pandoc renders TeX segments as <span>s with the "math" class, optionally
587+
; with "inline" or "display" classes depending on context.
588+
ELEMENT = span
589+
ALLOW_ATTR = class
590+
REGEXP = ^\s*((math(\s+|$)|inline(\s+|$)|display(\s+|$)))+
591+
```
592+
593+
- `ELEMENT`: The element this policy applies to. Must be non-empty.
594+
- `ALLOW_ATTR`: The attribute this policy allows. Must be non-empty.
595+
- `REGEXP`: A regex to match the contents of the attribute against. Must be present but may be empty for unconditional whitelisting of this attribute.
596+
597+
You may redefine `ELEMENTS`, `ALLOW_ATTRS`, and `REGEXP` multiple times; each time all three are defined is a single policy entry.
598+
581599
## Time (`time`)
582600

583601
- `FORMAT`: Time format to diplay on UI. i.e. RFC1123 or 2006-01-02 15:04:05

docs/content/doc/advanced/external-renderers.en-us.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,22 @@ RENDER_COMMAND = rst2html.py
6868
IS_INPUT_FILE = false
6969
```
7070

71+
If your external markup relies on additional classes and attributes on the generated HTML elements, you might need to enable custom sanitizer policies. Gitea uses the [`bluemonday`](https://godoc.org/github.com/microcosm-cc/bluemonday) package as our HTML sanitizier. The example below will support [KaTeX](https://katex.org/) output from [`pandoc`](https://pandoc.org/).
72+
73+
```ini
74+
[markup.sanitizer]
75+
; Pandoc renders TeX segments as <span>s with the "math" class, optionally
76+
; with "inline" or "display" classes depending on context.
77+
ELEMENT = span
78+
ALLOW_ATTR = class
79+
REGEXP = ^\s*((math(\s+|$)|inline(\s+|$)|display(\s+|$)))+
80+
81+
[markup.markdown]
82+
ENABLED = true
83+
FILE_EXTENSIONS = .md,.markdown
84+
RENDER_COMMAND = pandoc -f markdown -t html --katex
85+
```
86+
87+
You may redefine `ELEMENT`, `ALLOW_ATTR`, and `REGEXP` multiple times; each time all three are defined is a single policy entry. All three must be defined, but `REGEXP` may be blank to allow unconditional whitelisting of that attribute.
88+
7189
Once your configuration changes have been made, restart Gitea to have changes take effect.

0 commit comments

Comments
 (0)