Class: Sourcerer::SourceSkim::MarkdownSkimmer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/sourcerer/source_skim/markdown_skimmer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Parses Markdown content and produces a JSON-ready skim hash.

Heading levels are mapped to mirror AsciiDoc document structure: a single # heading becomes the document title (level 0); all subsequent #+#+ headings become sections starting at level 1. This keeps Markdown and AsciiDoc skim output shapes consistent.

A new instance should be created per-document call. External callers should use skim_file or skim_string with a Markdown file or format: :markdown rather than instantiating this class directly.

Constant Summary collapse

MD_HEADING_RE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Matches ATX-style Markdown headings: one to six leading # characters.

/^(\#{1,6})\s+(.+?)\s*$/

Instance Method Summary collapse

Instance Method Details

#process(content, config: Config.new(forms: [:flat])) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns JSON-ready skim.

Parameters:

  • content (String)

    raw Markdown text

  • config (Config) (defaults to: Config.new(forms: [:flat]))

Returns:

  • (Hash)

    JSON-ready skim



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sourcerer/source_skim/markdown_skimmer.rb', line 24

def process content, config: Config.new(forms: [:flat])
  @config = config

  fm               = Sourcerer::YamlFrontmatter.extract(content)
  body             = Sourcerer::YamlFrontmatter.strip(content)
  offset           = content.lines.length - body.lines.length
  title, sections  = extract_title_and_sections(body, offset)

  result = {
    title:       title || fm['title'].to_s,
    frontmatter: fm
  }
  result[:sections_flat] = sections if @config.flat?
  result[:sections_tree] = build_tree(sections) if @config.tree?
  result
end