debian-mirror-gitlab/doc/user/project/highlighting.md

75 lines
2.9 KiB
Markdown
Raw Normal View History

2020-10-24 23:57:45 +05:30
---
stage: Create
group: Source Code
2021-02-22 17:27:13 +05:30
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments"
2020-10-24 23:57:45 +05:30
type: reference
---
2021-03-11 19:13:27 +05:30
# Syntax Highlighting **(FREE)**
2016-08-24 12:49:21 +05:30
2021-03-11 19:13:27 +05:30
GitLab provides syntax highlighting on all files through the [Rouge](https://rubygems.org/gems/rouge) Ruby gem. It attempts to guess what language to use based on the file extension, which most of the time is sufficient.
2020-07-28 23:09:34 +05:30
2021-02-22 17:27:13 +05:30
NOTE:
2020-07-28 23:09:34 +05:30
The [Web IDE](web_ide/index.md) and [Snippets](../snippets.md) use [Monaco Editor](https://microsoft.github.io/monaco-editor/)
for text editing, which internally uses the [Monarch](https://microsoft.github.io/monaco-editor/monarch.html)
library for syntax highlighting.
2016-08-24 12:49:21 +05:30
2021-10-27 15:23:28 +05:30
<!-- vale gitlab.Spelling = NO -->
2021-03-11 19:13:27 +05:30
If GitLab is guessing wrong, you can override its choice of language using the
2021-10-27 15:23:28 +05:30
`gitlab-language` attribute in `.gitattributes`. For example, if you are working in a Prolog
2021-03-11 19:13:27 +05:30
project and using the `.pl` file extension (which would normally be highlighted as Perl),
you can add the following to your `.gitattributes` file:
2016-08-24 12:49:21 +05:30
2021-10-27 15:23:28 +05:30
<!-- vale gitlab.Spelling = YES -->
2016-08-24 12:49:21 +05:30
``` conf
*.pl gitlab-language=prolog
```
2021-03-11 19:13:27 +05:30
<!-- vale gitlab.Spelling = NO -->
2021-10-27 15:23:28 +05:30
2021-03-11 19:13:27 +05:30
When you check in and push that change, all `*.pl` files in your project are highlighted as Prolog.
2021-10-27 15:23:28 +05:30
2021-03-11 19:13:27 +05:30
<!-- vale gitlab.Spelling = YES -->
2016-08-24 12:49:21 +05:30
2021-03-11 19:13:27 +05:30
The paths here are Git's built-in [`.gitattributes` interface](https://git-scm.com/docs/gitattributes). So, if you were to invent a file format called a `Nicefile` at the root of your project that used Ruby syntax, all you need is:
2016-08-24 12:49:21 +05:30
``` conf
/Nicefile gitlab-language=ruby
```
2021-02-22 17:27:13 +05:30
To disable highlighting entirely, use `gitlab-language=text`. Lots more fun shenanigans are available through common gateway interface (CGI) options, such as:
2016-08-24 12:49:21 +05:30
``` conf
# json with erb in it
/my-cool-file gitlab-language=erb?parent=json
# an entire file of highlighting errors!
/other-file gitlab-language=text?token=Error
```
2021-10-27 15:23:28 +05:30
These configurations only take effect when the `.gitattributes`
2021-09-04 01:27:46 +05:30
file is in your [default branch](repository/branches/default.md).
2020-07-28 23:09:34 +05:30
2021-02-22 17:27:13 +05:30
NOTE:
2020-07-28 23:09:34 +05:30
The Web IDE does not support `.gitattribute` files, but it's [planned for a future release](https://gitlab.com/gitlab-org/gitlab/-/issues/22014).
2021-06-08 01:23:25 +05:30
## Configure maximum file size for highlighting
You can configure the maximum size of the file to be highlighted.
The file size is measured in kilobytes, and is set to a default of `512 KB`. Any file _over_ the file size is rendered in plain text.
1. Open the [`gitlab.yml`](https://gitlab.com/gitlab-org/gitlab-foss/blob/master/config/gitlab.yml.example) configuration file.
1. Add this section, replacing `maximum_text_highlight_size_kilobytes` with the value you want.
```yaml
gitlab:
extra:
## Maximum file size for syntax highlighting
## https://docs.gitlab.com/ee/user/project/highlighting.html
maximum_text_highlight_size_kilobytes: 512
```