---
title: "Markdown Code action for ActionClip"
canonical_url: "https://actionclip.app/actions/markdown-code"
document_type: "standalone_action"
official: true
action_count: 1
catalog_schema_version: 1
catalog_revision: "2026-09-11.1"
catalog_published_at: "2026-09-11T09:31:40Z"
---

# Markdown Code action for ActionClip

Toggle Markdown code markup around selected text.

## What it does

Uses inline backticks for one line and a safe-length fenced code block for multiple standard or rich-text lines. Running it on matching code markup removes the markup.

## Action details

| Field | Value |
| --- | --- |
| Category | Markdown |
| Action type | JavaScript |
| Default result | Replace selected text by default |
| Internet | Not required |

## Action and outcome

| Action | Outcome |
| --- | --- |
| **Markdown Code** — Selected text: total += item | `total += item` |

## How to toggle Markdown code markup around selected text with ActionClip

1. Select the text you want to use.
2. Choose **Markdown Code** from ActionClip.
3. In editable text, ActionClip replaces the selection immediately. In read-only text, it opens the result for review and copying.

## Requirements

No setup required.

## Privacy

Runs locally in ActionClip’s JavaScript sandbox. Selected text does not leave your Mac.

## Action script

````javascript
function run(selected_text) {
  const normalized = selected_text.replace(/\r\n|[\n\r\u000B\u000C\u0085\u2028\u2029]/g, "\n");
  const block = normalized.match(/^(`{3,})[^\n]*\n([\s\S]*?)\n?\1[ \t]*$/);
  if (block) return block[2];

  if (!/[\r\n]/.test(normalized)) {
    const inline = normalized.match(/^(\s*)(`+)([\s\S]*?)\2(\s*)$/);
    if (inline) return inline[1] + inline[3] + inline[4];

    const leading = (normalized.match(/^\s*/) || [""])[0];
    const trailing = (normalized.match(/\s*$/) || [""])[0];
    const content = normalized.slice(leading.length, normalized.length - trailing.length);
    const runs = content.match(/`+/g) || [];
    const fenceLength = Math.max(1, ...runs.map((run) => run.length + 1));
    const fence = "`".repeat(fenceLength);
    const needsPadding = content.startsWith("`") || content.endsWith("`");
    return leading + fence + (needsPadding ? " " : "") + content
      + (needsPadding ? " " : "") + fence + trailing;
  }

  const runs = normalized.match(/`+/g) || [];
  const fenceLength = Math.max(3, ...runs.map((run) => run.length + 1));
  const fence = "`".repeat(fenceLength);
  return fence + "\n" + normalized + (normalized.endsWith("\n") ? "" : "\n") + fence;
}
````

## Links

- [HTML listing](https://actionclip.app/actions/markdown-code)
- [Download action definition](https://actionclip.app/actions/markdown-code.actionclip)
- [Browse Markdown actions](https://actionclip.app/marketplace#marketplace-markdown)
- [All Marketplace listings](https://actionclip.app/marketplace)
