debian-mirror-gitlab/doc/user/project/highlighting.md
2021-06-08 01:23:25 +05:30

2.9 KiB

stage group info type
Create Source Code 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 reference

Syntax Highlighting (FREE)

GitLab provides syntax highlighting on all files through the Rouge Ruby gem. It attempts to guess what language to use based on the file extension, which most of the time is sufficient.

NOTE: The Web IDE and Snippets use Monaco Editor for text editing, which internally uses the Monarch library for syntax highlighting.

If GitLab is guessing wrong, you can override its choice of language using the gitlab-language attribute in .gitattributes. For example, if you are working in a

Prolog

project and using the .pl file extension (which would normally be highlighted as Perl), you can add the following to your .gitattributes file:

*.pl gitlab-language=prolog

When you check in and push that change, all *.pl files in your project are highlighted as Prolog.

The paths here are Git's built-in .gitattributes interface. 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:

/Nicefile gitlab-language=ruby

To disable highlighting entirely, use gitlab-language=text. Lots more fun shenanigans are available through common gateway interface (CGI) options, such as:

# 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

Please note that these configurations only take effect when the .gitattributes file is in your default branch (usually master).

NOTE: The Web IDE does not support .gitattribute files, but it's planned for a future release.

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 configuration file.

  2. 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