All Collections
Enterprise
Product Features
Syntax Highlighting in Code Blocks
Syntax Highlighting in Code Blocks

How to configure syntax highlighting in SOE code blocks.

L
Written by Loren Alldrin
Updated over a week ago

Tags | Code blocks |

Applies to: Enterprise

This documentation is for Stack Overflow Enterprise. Free, Basic, and Business users can access their documentation here. Find your plan.


Overview

Stack Overflow Enterprise (SOE) applies basic syntax highlighting to blocks of code in questions and answers. This is similar to programming editors, which use colors and formatting to make code easier to read and parse. Here's a before and after example of code highlighting:

Tag highlighting

Most syntax highlighting happens at the tag level, by assigning a highlighting color scheme to a specific tag. Assigning a color scheme is especially useful for tags related to programming languages, libraries, extensions, and frameworks.

To set the highlighting color scheme for a tag, visit the tag's wiki. At the bottom of the page, you'll see a dropdown menu with all the syntax highlighting options.

SOE will apply the selected highlighting scheme to code blocks in all posts with that tag, unless overridden by the user that created the post (see the Post-specific highlighting section below).

The following rules define the behavior of tag-specific syntax highlighting:

  • If a question has no tags with a default or specific language set, SOE will apply no syntax highlighting.

  • If a question has only one tag with a specific language hint, plus any number of default or null hints, SOE will apply syntax highlighting only for that specific language.

  • If a question has two or more tags that define specific languages, SOE ignores the tag formatting and instead attempts to detect the language for each block of code.

  • If a question has one or more tags with default language hints, but none with a specific language hint, SOE will attempt to detect the language.

Post-specific highlighting

When composing a post, you can override the default formatting for a tag by using a supported syntax highlighting code or a tag-name in the code block. Here are some examples:

Indent with four spaces:

Use code fences:

If a user specifies a language tag for code blocks in their post, those declarations override global highlighting settings for tags. This gives better results for posts that contain code blocks in multiple languages, or posts that use tags without global syntax highlighting settings.

For help with syntax highlighting—and other Markdown features—when writing a post, click the Formating Help link. This displays helpful information in the "How to Ask" sidebar.


If you need further support or have questions, contact your site administrator.

Did this answer your question?