Syntax Highlighting
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
GitLab provides syntax highlighting on all files through Highlight.js and the 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 use the .gitattributes
interface in Git.
The Web IDE and Snippets use Monaco Editor for text editing, which internally uses the Monarch library for syntax highlighting.
Override syntax highlighting for a file type
The Web IDE does not support .gitattribute
files.
To override syntax highlighting for a file type:
If a
.gitattributes
file does not exist in the root directory of your project, create a blank file with this name.For each file type you want to modify, add a line to the
.gitattributes
file declaring the file extension and your desired highlighting language:# 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
Commit, push, and merge your changes into your default branch.
After the changes merge into your default branch,
all *.pl
files in your project are highlighted in your preferred language.
You can also extend the highlighting with Common Gateway Interface (CGI) options, such as:
# JSON file 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
Disable syntax highlighting for a file type
To disable highlighting entirely for a file type, follow the instructions for overriding
the highlighting for a file type, and use gitlab-language=text
:
# Disable syntax highlighting for this file type
*.module gitlab-language=text
Configure maximum file size for highlighting
By default, GitLab renders any file larger than 512 KB in plain text. To change this value:
Open the
gitlab.yml
configuration file for your project.Add this section, replacing
maximum_text_highlight_size_kilobytes
with the value you want.gitlab: extra: ## Maximum file size for syntax highlighting ## https://docs.gitlab.com/ee/user/project/highlighting.html maximum_text_highlight_size_kilobytes: 512
Commit, push, and merge your changes into your default branch.
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support