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 3.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. This supports rendering of whole files. If you want to render code blocks in markdown you would need to do something with javascript. See some examples on the [Customizing Gitea](../customizing-gitea) page.
  22. ## Installing external binaries
  23. In order to get file rendering through external binaries, their associated packages must be installed.
  24. If you're using a Docker image, your `Dockerfile` should contain something along this lines:
  25. ```
  26. FROM gitea/gitea:{{< version >}}
  27. [...]
  28. COPY custom/app.ini /data/gitea/conf/app.ini
  29. [...]
  30. RUN apk --no-cache add asciidoctor freetype freetype-dev gcc g++ libpng python-dev py-pip python3-dev py3-pip py3-pyzmq
  31. # install any other package you need for your external renderers
  32. RUN pip3 install --upgrade pip
  33. RUN pip3 install -U setuptools
  34. RUN pip3 install jupyter matplotlib docutils
  35. # add above any other python package you may need to install
  36. ```
  37. ## `app.ini` file configuration
  38. add one `[markup.XXXXX]` section per external renderer on your custom `app.ini`:
  39. ```
  40. [markup.asciidoc]
  41. ENABLED = true
  42. FILE_EXTENSIONS = .adoc,.asciidoc
  43. RENDER_COMMAND = "asciidoctor -e -a leveloffset=-1 --out-file=- -"
  44. ; Input is not a standard input but a file
  45. IS_INPUT_FILE = false
  46. [markup.jupyter]
  47. ENABLED = true
  48. FILE_EXTENSIONS = .ipynb
  49. RENDER_COMMAND = "jupyter nbconvert --stdout --to html --template basic "
  50. IS_INPUT_FILE = true
  51. [markup.restructuredtext]
  52. ENABLED = true
  53. FILE_EXTENSIONS = .rst
  54. RENDER_COMMAND = rst2html.py
  55. IS_INPUT_FILE = false
  56. ```
  57. 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/).
  58. ```ini
  59. [markup.sanitizer.TeX]
  60. ; Pandoc renders TeX segments as <span>s with the "math" class, optionally
  61. ; with "inline" or "display" classes depending on context.
  62. ELEMENT = span
  63. ALLOW_ATTR = class
  64. REGEXP = ^\s*((math(\s+|$)|inline(\s+|$)|display(\s+|$)))+
  65. [markup.markdown]
  66. ENABLED = true
  67. FILE_EXTENSIONS = .md,.markdown
  68. RENDER_COMMAND = pandoc -f markdown -t html --katex
  69. ```
  70. You must define `ELEMENT`, `ALLOW_ATTR`, and `REGEXP` in each section.
  71. To define multiple entries, add a unique alphanumeric suffix (e.g., `[markup.sanitizer.1]` and `[markup.sanitizer.something]`).
  72. Once your configuration changes have been made, restart Gitea to have changes take effect.
  73. **Note**: Prior to Gitea 1.12 there was a single `markup.sanitiser` section with keys that were redefined for multiple rules, however,
  74. there were significant problems with this method of configuration necessitating configuration through multiple sections.