consolelog.tools

Code Block Formatter

Wrap raw code in a properly-fenced markdown code block — pick your language, add a filename, enable line numbers, and highlight specific lines

About this ToolHow it works, benefits & use cases

Wrapping a snippet in a proper Markdown code block is more than adding three backticks — you want the right language tag, sometimes a filename label, and occasionally line numbers or highlighted lines. This formatter does all of it. Paste your code, pick a language from fifteen options (JavaScript, TypeScript, Python, Java, Go, Rust, PHP, Ruby, CSS, HTML, JSON, YAML, Bash, SQL, Markdown), and it emits a fenced ``` block tagged with that language. Choose the indented (4-space) style instead if you prefer. An optional filename is added as an HTML comment above the block, line numbers can be prepended in a padded "N | code" gutter, and you can mark specific lines (entered comma-separated, e.g. 1, 3, 5) with a `// [!code highlight]` annotation that VitePress and similar renderers understand. The output is copy-ready Markdown, shareable via URL, and can pipe into another tool.

How to Use

  1. 1Choose the Language for your snippet from the dropdown (defaults to JavaScript).
  2. 2Optionally set a Filename (added as a comment) and a comma-separated list of Highlight lines.
  3. 3Pick the Code block style — Fenced (```) or Indented (4 spaces).
  4. 4Toggle Show line numbers if you want a numbered gutter.
  5. 5Paste your code into the input panel, or click Load example.
  6. 6Click Format Code Block, then copy, download, or share the resulting Markdown.

Key Benefits

  • Fifteen language tags for correct syntax highlighting in renderers
  • Fenced (```) or 4-space indented output styles
  • Optional filename label added as an HTML comment above the block
  • Line numbers in a padded "N | code" gutter when you want them
  • Highlight specific lines with the // [!code highlight] annotation
  • Settings persist locally; output is copyable, downloadable, and shareable by URL
  • Pipe the formatted block straight into another markdown tool

Common Use Cases

  • Pasting a snippet into a README or blog post with the correct language fence
  • Adding a filename label so readers know which file a code block belongs to
  • Marking the key lines of an example with VitePress-style highlight annotations
  • Converting an indented code block to a fenced one (or vice versa) for a docs site
  • Producing a numbered code listing for a tutorial or step-by-step guide

Formatting options

0 characters

Run to see the formatted code block.

Was this tool helpful?

Share Your Experience

Help others discover this tool!

Related tools