DprintMarkdownFormatter.AstProcessor (dprint_markdown_formatter v0.5.1)

View Source

AST processing utilities for extracting and formatting module attributes.

Handles parsing Elixir source code, identifying module attributes that contain markdown content, and creating patches to apply formatted content back to the source.

Summary

Functions

Applies patches to source content and performs final cleanup.

Collects patches for formatting module attributes containing markdown.

Creates a patch for formatted content if the attribute should be processed.

Parses Elixir source content into an AST.

Processes a single AST node to determine if it needs patching.

Functions

apply_patches(content, patches)

@spec apply_patches(String.t(), patches()) ::
  {:ok, String.t()} | {:error, Exception.t()}

Applies patches to source content and performs final cleanup.

Returns {:ok, patched_content} on success, or {:error, error} if patching fails.

collect_patches_for_doc_attributes(ast, doc_attributes, config)

@spec collect_patches_for_doc_attributes(
  ast(),
  [atom()],
  DprintMarkdownFormatter.Config.t()
) ::
  {:ok, patches()} | {:error, Exception.t()}

Collects patches for formatting module attributes containing markdown.

Walks the AST and creates patches for any attributes in doc_attributes that contain markdown content needing formatting.

create_patch_for_formatted_content(node, formatted, string_node, block_meta, acc)

@spec create_patch_for_formatted_content(
  ast(),
  String.t(),
  ast(),
  keyword(),
  patches()
) ::
  {ast(), patches()}

Creates a patch for formatted content if the attribute should be processed.

Formats the markdown content and creates a source patch if the content changed.

parse_elixir_source(content)

@spec parse_elixir_source(String.t()) :: {:ok, ast()} | {:error, Exception.t()}

Parses Elixir source content into an AST.

Returns {:ok, ast} on success, or {:error, error} if parsing fails.

process_node_for_patches(node, doc_attributes, nif_config, acc)

@spec process_node_for_patches(ast(), [atom()], map(), patches()) ::
  {ast(), patches()}

Processes a single AST node to determine if it needs patching.

Identifies module attribute nodes that match the target attributes and contain markdown content, then creates appropriate patches.