You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

external-renderers.en-us.md 2.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ---
  2. date: "2018-11-23:00:00+02:00"
  3. title: "External renderers"
  4. slug: "external-renderers"
  5. weight: 40
  6. toc: true
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "advanced"
  11. name: "External renderers"
  12. weight: 40
  13. identifier: "external-renderers"
  14. ---
  15. # Custom files rendering configuration
  16. Gitea supports custom file renderings (i.e., Jupyter notebooks, asciidoc, etc.) through external binaries,
  17. it is just a matter of:
  18. * installing external binaries
  19. * add some configuration to your `app.ini` file
  20. * restart your Gitea instance
  21. ## Installing external binaries
  22. In order to get file rendering through external binaries, their associated packages must be installed.
  23. If you're using a Docker image, your `Dockerfile` should contain something along this lines:
  24. ```
  25. FROM gitea/gitea:{{< version >}}
  26. [...]
  27. COPY custom/app.ini /data/gitea/conf/app.ini
  28. [...]
  29. RUN apk --no-cache add asciidoctor freetype freetype-dev gcc g++ libpng python-dev py-pip python3-dev py3-pip py3-zmq
  30. # install any other package you need for your external renderers
  31. RUN pip3 install --upgrade pip
  32. RUN pip3 install -U setuptools
  33. RUN pip3 install jupyter matplotlib docutils
  34. # add above any other python package you may need to install
  35. ```
  36. ## `app.ini` file configuration
  37. add one `[markup.XXXXX]` section per external renderer on your custom `app.ini`:
  38. ```
  39. [markup.asciidoc]
  40. ENABLED = true
  41. FILE_EXTENSIONS = .adoc,.asciidoc
  42. RENDER_COMMAND = "asciidoctor -e -a leveloffset=-1 --out-file=- -"
  43. ; Input is not a standard input but a file
  44. IS_INPUT_FILE = false
  45. [markup.jupyter]
  46. ENABLED = true
  47. FILE_EXTENSIONS = .ipynb
  48. RENDER_COMMAND = "jupyter nbconvert --stdout --to html --template basic "
  49. IS_INPUT_FILE = true
  50. [markup.restructuredtext]
  51. ENABLED = true
  52. FILE_EXTENSIONS = .rst
  53. RENDER_COMMAND = rst2html.py
  54. IS_INPUT_FILE = false
  55. ```
  56. 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/).
  57. ```ini
  58. [markup.sanitizer]
  59. ; Pandoc renders TeX segments as <span>s with the "math" class, optionally
  60. ; with "inline" or "display" classes depending on context.
  61. ELEMENT = span
  62. ALLOW_ATTR = class
  63. REGEXP = ^\s*((math(\s+|$)|inline(\s+|$)|display(\s+|$)))+
  64. [markup.markdown]
  65. ENABLED = true
  66. FILE_EXTENSIONS = .md,.markdown
  67. RENDER_COMMAND = pandoc -f markdown -t html --katex
  68. ```
  69. 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.
  70. Once your configuration changes have been made, restart Gitea to have changes take effect.