fences

package
v0.63.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package fences provides utilities for detecting markdown code regions (fenced code blocks and inline code spans) and applying transformations only to text outside those regions.

This prevents special tokens like $1, $@, or @file from being interpreted when they appear inside ``` fences, ~~~ fences, or `inline` code spans.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ranges

func Ranges(content string) [][2]int

Ranges returns byte ranges [start, end) of fenced code blocks in content. Recognises both backtick (```) and tilde (~~~) fences, with optional leading indentation (up to 3 spaces) and optional info strings. An unclosed fence extends to the end of content.

func ReplaceOutside

func ReplaceOutside(content string, fn func(string) string) string

ReplaceOutside applies fn to each text segment that is outside fenced code blocks and inline code spans, leaving code content unchanged. This is the primary entry point for callers that need to do regex replacement only on non-code text.

func StripCode

func StripCode(content string) string

StripCode returns content with fenced code blocks and inline code spans removed. Useful for detection/matching where only non-code text matters.

func StripFenced

func StripFenced(content string) string

StripFenced returns content with fenced code block regions removed. Useful for detection/matching where only non-fenced text matters. NOTE: this does NOT strip inline code spans; use StripCode for both.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL