Skip to content

feat(plugin): add RobustCodeBlock plugin for syntax highlighter support#7

Merged
abimaelmartell merged 1 commit intomasterfrom
feat/robust-code-block-plugin
Feb 4, 2026
Merged

feat(plugin): add RobustCodeBlock plugin for syntax highlighter support#7
abimaelmartell merged 1 commit intomasterfrom
feat/robust-code-block-plugin

Conversation

@abimaelmartell
Copy link
Member

Summary

  • Adds a new RobustCodeBlock() plugin for handling code blocks from various syntax highlighting libraries
  • Extracts content from nested divs/spans used by highlight.js, prism.js, and similar libraries
  • Detects language from language-* and lang-* CSS classes
  • Strips gutter/line-number elements automatically
  • Handles <br> tags and block elements with proper newline insertion

Motivation

This consolidates code block handling logic that was duplicated across multiple Firecrawl services (go-html-to-md-service and sharedLibs/go-html-to-md). Moving it upstream:

  • Creates a single source of truth
  • Makes testing easier
  • Prevents drift between implementations

Usage

converter := md.NewConverter("", true, nil)
converter.Use(plugin.RobustCodeBlock())

Test plan

  • Language detection tests (language-, lang- prefixes)
  • Gutter stripping tests
  • Syntax highlighter div extraction tests
  • Inline code tests
  • Newline preservation tests
  • BR tag handling tests

🤖 Generated with Claude Code

Adds a new plugin that provides robust handling of code blocks from various
syntax highlighting libraries. Features:

- Language detection from `language-*` and `lang-*` CSS classes
- Gutter/line-number stripping (skips elements with `gutter` or `line-numbers` classes)
- Recursive text extraction from nested divs/spans (handles highlight.js, prism.js, etc.)
- Proper newline handling for block elements and <br> tags
- Safe inline code fencing with backtick escaping

This consolidates code block handling logic that was duplicated across
multiple Firecrawl services.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@abimaelmartell abimaelmartell merged commit d5aaf05 into master Feb 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant