2020-07-28 14:09:36 -04:00
---
stage: Create
group: Source Code
2020-11-26 01:09:20 -05:00
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-07-28 14:09:36 -04:00
type: reference
---
2021-02-09 13:09:59 -05:00
# Syntax Highlighting **(FREE)**
2016-06-23 14:08:04 -04:00
2022-07-01 17:08:27 -04:00
GitLab provides syntax highlighting on all files through [Highlight.js ](https://github.com/highlightjs/highlight.js/ ) and the
2022-03-11 19:07:24 -05:00
[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.
The paths here are Git's built-in [`.gitattributes` interface ](https://git-scm.com/docs/gitattributes ).
2020-06-18 08:09:25 -04:00
2020-12-04 16:09:29 -05:00
NOTE:
2020-06-18 08:09:25 -04:00
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-06-23 14:08:04 -04:00
2022-03-11 19:07:24 -05:00
## Override syntax highlighting for a file type
2016-06-23 14:08:04 -04:00
2022-03-11 19:07:24 -05:00
NOTE:
The Web IDE [does not support `.gitattribute` files ](https://gitlab.com/gitlab-org/gitlab/-/issues/22014 ).
2016-06-23 14:08:04 -04:00
2022-03-11 19:07:24 -05:00
To override syntax highlighting for a file type:
2021-08-16 20:10:22 -04:00
2022-03-11 19:07:24 -05:00
1. If a `.gitattributes` file does not exist in the root directory of your project,
create a blank file with this name.
1. For each file type you want to modify, add a line to the `.gitattributes` file
declaring the file extension and your desired highlighting language:
2021-08-16 20:10:22 -04:00
2022-03-11 19:07:24 -05:00
```conf
# This extension would normally receive Perl syntax highlighting
# but if we also use Prolog, we may want to override highlighting for
# files with this extension:
*.pl gitlab-language=prolog
```
2016-06-23 14:08:04 -04:00
2022-03-11 19:07:24 -05:00
1. Commit, push, and merge your changes into your default branch.
2016-06-23 14:08:04 -04:00
2022-03-11 19:07:24 -05:00
After the changes merge into your [default branch ](repository/branches/default.md ),
all `*.pl` files in your project are highlighted in your preferred language.
2016-06-23 14:08:04 -04:00
2022-06-06 14:09:02 -04:00
You can also extend the highlighting with Common Gateway Interface (CGI) options, such as:
2016-06-23 14:08:04 -04:00
2016-06-23 17:11:38 -04:00
``` conf
2022-03-11 19:07:24 -05:00
# JSON file with .erb in it
2016-06-23 14:08:04 -04:00
/my-cool-file gitlab-language=erb?parent=json
2022-03-11 19:07:24 -05:00
# An entire file of highlighting errors!
2016-06-23 14:08:04 -04:00
/other-file gitlab-language=text?token=Error
```
2016-06-27 17:17:04 -04:00
2022-03-11 19:07:24 -05:00
## Disable syntax highlighting for a file type
2020-06-18 08:09:25 -04:00
2022-03-11 19:07:24 -05:00
To disable highlighting entirely for a file type, follow the instructions for overriding
the highlighting for a file type, and use `gitlab-language=text` :
2021-05-10 11:10:24 -04:00
2022-03-11 19:07:24 -05:00
```conf
# Disable syntax highlighting for this file type
*.module gitlab-language=text
```
2021-05-10 11:10:24 -04:00
2022-03-11 19:07:24 -05:00
## Configure maximum file size for highlighting
2021-05-10 11:10:24 -04:00
2022-03-11 19:07:24 -05:00
By default, GitLab renders any file larger than 512 KB in plain text. To change this value:
2021-05-10 11:10:24 -04:00
2022-03-11 19:07:24 -05:00
1. Open the [`gitlab.yml` ](https://gitlab.com/gitlab-org/gitlab-foss/blob/master/config/gitlab.yml.example )
configuration file for your project.
2021-05-10 11:10:24 -04:00
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
```
2022-03-11 19:07:24 -05:00
1. Commit, push, and merge your changes into your default branch.