---
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-08-21.1"
catalog_published_at: "2026-08-20T18:50:00Z"
---

# 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 lines. Running it on matching code markup removes the markup.

## Action details

| Field | Value |
| --- | --- |
| Category | Markdown |
| Action type | JavaScript |
| Result | Replace or copy text |
| 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. Review the result, then replace the selection or copy the new text.

## Requirements

No setup required.

## Privacy

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

## Action configuration

````javascript
function run(selected_text) {
  const block = selected_text.match(/^(`{3,})[^\n]*\n([\s\S]*?)\n?\1[ \t]*$/);
  if (block) return block[2];

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

    const leading = (selected_text.match(/^\s*/) || [""])[0];
    const trailing = (selected_text.match(/\s*$/) || [""])[0];
    const content = selected_text.slice(leading.length, selected_text.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 normalized = selected_text.replace(/\r\n?|\n/g, "\n");
  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)
