Implementation:1broseidon Ketch extract PostProcess
| Knowledge Sources | |
|---|---|
| Domains | Extraction, Postprocessing |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
The shared output post-processing step for the CLI's `--trim`/`--max-chars` flags and the MCP tools' `trim`/`max_chars` params: strip markdown syntax, then truncate by Unicode code points.
Description
PostProcess composes two pure functions. StripMarkdown (`--trim`) removes markdown formatting syntax (bold/italic/links/headings/code; fenced code blocks are preserved) to keep only content text. Truncate (`--max-chars`) caps the string at N Unicode code points and appends `[truncated]`; `<=0` disables it. The order is fixed: trim first, then truncate, so truncation counts the stripped text.
Usage
Called by the CLI scrape/extract/crawl commands and the MCP scrape/search/crawl tools after extraction. Both parameters are per-invocation options; config-level settings are never involved.
Code Reference
Source Location
- Repository: ketch
- File: extract/post.go, extract/strip.go
Signature
// Truncate caps s at maxChars Unicode code points, appending a marker.
func Truncate(s string, maxChars int) string
// StripMarkdown removes markdown formatting syntax, keeping content text.
func StripMarkdown(s string) string
// PostProcess applies trim (StripMarkdown) then Truncate to markdown content.
func PostProcess(s string, trim bool, maxChars int) string
Import
import "github.com/1broseidon/ketch/extract"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| s | string | Yes | Raw markdown |
| trim | bool | Yes | Strip markdown syntax first |
| maxChars | int | Yes | Cap at N code points (<=0 disables) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | string | Trimmed and/or truncated markdown |
Usage Examples
Bounded Output
markdown := extract.PostProcess(page.Markdown, true, 2000)
// markdown has no **bold**/_italic_/[links](…) and is capped at 2000 runes.