Skip to content

[Feature] Markdown パーサー(ファイル走査・heading分割・frontmatter/tag抽出) #3

@Kewton

Description

@Kewton

概要

Markdownファイルを解析し、heading単位のチャンクに分割・構造化するパーサーモジュールを実装する。

背景・動機

Phase 1 の基盤となるモジュール。tantivy へのインデックス登録に必要な構造化データを生成する。

提案する解決策

src/parser/ モジュールとして以下を実装する。

主要な機能

  1. Markdownファイル走査: 指定ディレクトリ配下の .md ファイルを再帰的に列挙
  2. heading単位分割: #, ##, ### 等の見出しでドキュメントをチャンクに分割
  3. frontmatter抽出: YAML frontmatter(--- で囲まれた領域)をパース
  4. tag抽出: frontmatter 内の tags フィールドを抽出
  5. リンク抽出: [[]] (wiki link) / []() (markdown link) を抽出

データ構造(案)

pub struct MarkdownDocument {
    pub path: PathBuf,
    pub frontmatter: Option<Frontmatter>,
    pub sections: Vec<Section>,
    pub links: Vec<Link>,
}

pub struct Frontmatter {
    pub tags: Vec<String>,
    pub raw: HashMap<String, serde_json::Value>,
}

pub struct Section {
    pub heading: String,
    pub level: u8,       // 1-6
    pub body: String,    // heading以下の本文
    pub line_start: usize,
}

pub struct Link {
    pub target: String,
    pub link_type: LinkType, // WikiLink / MarkdownLink
}

受け入れ基準

  • 指定ディレクトリ配下の .md ファイルを再帰的に列挙できる
  • heading単位でセクションに分割できる(####### 対応)
  • YAML frontmatter を正しくパースできる
  • frontmatter 内の tags を抽出できる
  • [[target]] 形式と [text](target) 形式のリンクを抽出できる
  • frontmatter がないファイルでもエラーにならない
  • 空ファイル、heading がないファイルでもエラーにならない
  • cargo test / clippy / fmt 全パス

影響範囲

新規ファイル

  • src/parser/mod.rs
  • src/parser/markdown.rs
  • src/parser/frontmatter.rs
  • src/parser/link.rs
  • tests/parser_markdown.rs

依存クレート(追加候補)

  • serde_yaml — frontmatter パース
  • walkdir — ディレクトリ再帰走査

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions