How to Insert a Code Block in a Mastodon Post via Glitch-Soc
🔍 WiseChecker

How to Insert a Code Block in a Mastodon Post via Glitch-Soc

If you want to share a snippet of code in a Mastodon post, the standard interface does not include a dedicated code block button. This makes it difficult to preserve indentation and formatting, especially for longer code samples. Glitch-Soc, a popular fork of Mastodon, adds native support for code blocks directly in the post composer. This article explains how to enable and use code blocks in Glitch-Soc so your code stays readable and correctly formatted.

Key Takeaways: Inserting Code Blocks in Glitch-Soc Mastodon

  • Preferences > Appearance > Enable advanced composer: Turns on the rich text editor with code block support.
  • Composer toolbar > Code block icon (<>): Inserts a formatted code area into your post.
  • Manual Markdown triple backticks: Works if the advanced composer is off, but only on instances that render Markdown.

ADVERTISEMENT

What Glitch-Soc Code Blocks Are and Why They Matter

Glitch-Soc is an open-source fork of Mastodon that adds experimental features not found in the official Mastodon codebase. One of these features is a rich text composer that supports formatting options like bold, italic, and code blocks. The standard Mastodon web interface only supports plain text with basic Markdown-like formatting for links and mentions. Code blocks are not part of standard Mastodon because the platform prioritizes simplicity and accessibility. Glitch-Soc addresses this by providing a WYSIWYG editor that lets you insert a code block with a single click.

A code block in Glitch-Soc is rendered as a monospaced, bordered area that preserves whitespace and line breaks. This is essential for sharing programming snippets, configuration files, or any text where indentation matters. Without a code block, the post may collapse multiple spaces into one and remove line breaks, making the code unreadable. Glitch-Soc also allows you to specify the programming language for syntax highlighting, though this feature depends on the instance theme and client settings.

Steps to Insert a Code Block in a Glitch-Soc Post

Before you can use the code block feature, you must enable the advanced composer in your Glitch-Soc preferences. The following steps assume you are using the Glitch-Soc web interface. Mobile apps may not support the advanced composer.

  1. Log in to your Glitch-Soc instance
    Open your preferred browser and go to the web address of your Mastodon instance that runs Glitch-Soc. Enter your email and password, then click Log in.
  2. Open Preferences
    Click the gear icon in the right column under your profile information. On mobile, tap the hamburger menu and select Preferences.
  3. Enable the advanced composer
    In the Preferences page, click Appearance. Under the Posting section, check the box next to Enable advanced composer. This turns on the rich text toolbar in the post composer.
  4. Go back to the main timeline
    Click the Back button or the instance logo to return to the home timeline. The composer box at the top now shows a toolbar with formatting buttons.
  5. Click the code block icon
    In the composer toolbar, look for an icon that shows angle brackets (<>). Click it. A code block placeholder appears in the composer. The placeholder may show the text Code block with a monospaced font.
  6. Type or paste your code
    Click inside the code block area. Type your code or paste it from your clipboard. The formatting and line breaks are preserved. You can also type text outside the code block for context.
  7. Optionally specify a language for syntax highlighting
    Some Glitch-Soc themes and clients allow you to add a language identifier after the opening backticks. If your instance supports it, you can manually edit the code block to add the language name, for example: ```python. This step is optional and may not be visible in the WYSIWYG editor.
  8. Post your toot
    Click the Toot button to publish your post. The code block appears as a distinct formatted area with a monospaced font and a light gray background.

Alternative Method: Manual Markdown Code Blocks

If you prefer not to use the advanced composer, or if your Glitch-Soc instance has the advanced composer disabled, you can insert a code block using Markdown syntax. This method works only if your instance renders Markdown in posts, which is not guaranteed. Type three backticks on a line, then your code on the next line, and close with three backticks on a new line. For example:

```
function hello() {
  console.log("Hello, Mastodon!");
}
```

The post will render the code in a monospaced block. This approach is less reliable because some instances strip backticks or do not parse Markdown in toot bodies.

ADVERTISEMENT

Common Issues When Using Code Blocks in Glitch-Soc

Code block icon is missing from the composer toolbar

The most common cause is that the advanced composer is not enabled. Go to Preferences > Appearance and ensure the Enable advanced composer checkbox is checked. If the checkbox is already checked but the icon is still missing, your instance may be running an older version of Glitch-Soc that does not include the code block button. Contact your instance admin to update the software.

Code block does not preserve indentation after posting

This happens when you paste code that uses tab characters instead of spaces. Glitch-Soc may convert tabs to a single space. To fix this, replace tabs with spaces before pasting. Most code editors have a feature to convert tabs to spaces. Alternatively, use the manual Markdown method with triple backticks, which usually preserves whitespace better.

Syntax highlighting does not appear

Syntax highlighting is not a built-in feature of Glitch-Soc code blocks. Some instance themes or user styles may add it, but it is not guaranteed. To get syntax highlighting, you may need to use a third-party client like Halcyon or Pinafore that supports highlighted code blocks. Alternatively, use a service like Carbon to generate a screenshot of your code and attach it as an image.

Glitch-Soc Code Block vs Standard Mastodon Plain Text

Item Glitch-Soc Code Block Standard Mastodon Plain Text
Formatting preservation Preserves indentation and line breaks Collapses multiple spaces; removes line breaks
Visual appearance Monospaced font with background color Same font as regular text
Ease of insertion One click in advanced composer No built-in method; manual Markdown may fail
Syntax highlighting Not built-in; depends on theme or client Not available
Character limit impact Characters inside the block count toward the post limit Same

The table shows that Glitch-Soc code blocks are superior for sharing code because they maintain structure and readability. Standard Mastodon lacks any native code formatting, making it unsuitable for technical posts.

You can now insert a code block in any Mastodon post by enabling the advanced composer in Glitch-Soc and using the toolbar icon. If you share code frequently, consider using a dedicated code-sharing service like Pastebin or GitHub Gist and linking to it in your post to avoid character limit issues. For maximum readability, always replace tabs with spaces before pasting your code into the block.

ADVERTISEMENT