Skip to content

Extend extract_md_blocks to Return Code Block Metadata #3

Description

@chigwell
As a developer, 
I would like the extract_md_blocks function to return each code block along with its associated language type and starting line number, 
to enable more detailed parsing, indexing, and processing of markdown files.

Background

Currently, extract_md_blocks only extracts the content inside fenced code blocks. However, for more advanced applications (such as syntax-aware parsing, error localization, and automated documentation generation), it is necessary to know additional metadata about each block, including the programming language declared (if any) and the line number where the block appears in the source markdown.

Acceptance Criteria

  • Each extracted block is represented as a dictionary with at least the following keys:
    • content: The code block content as a string.
    • language: The language identifier if specified; otherwise None.
    • start_line: The 1-based line number in the original markdown text where the block starts.
  • If no language is declared in the fenced code block, the language field is set to None.
  • Line numbers are accurately calculated even if multiple blocks exist or blocks span multiple lines.
  • The function signature is updated appropriately, maintaining backward compatibility if needed.
  • Unit tests validate the accuracy of content, language, and line numbers across various markdown inputs.
  • Documentation is updated to describe the returned structure and provide examples.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions