Function preprocessCustomBlocks

  • Preprocess custom blocks in input content.

    Converts <<<\n...content...\n>>> blocks into properly quoted strings with format-specific escaping. Handles both bare and quoted blocks.

    Parameters

    • content: string

      The raw input content to preprocess

    • format: Format

      The format of the input ('yaml', 'json', or 'csv')

    Returns string

    The preprocessed content with blocks converted, or original input if unchanged/error

    Example

    // YAML bare block
    preprocessCustomBlocks('desc: <<<\nText\n>>>', 'yaml');
    // Returns: 'desc: "Text"'

    // JSON with quotes inside
    preprocessCustomBlocks('{"a": <<<\nSay "hi"\n>>>}', 'json');
    // Returns: '{"a": "Say \\"hi\\""}'

    // CSV cell
    preprocessCustomBlocks('A,B\n1,<<<\nLine 1\n>>>', 'csv');
    // Returns: 'A,B\n1,"Line 1"'