DprintMarkdownFormatter.PatchBuilder (dprint_markdown_formatter v0.5.1)

View Source

Utilities for building replacement strings and patches for formatted content.

Handles the conversion of formatted markdown content into appropriate string replacements, supporting both simple strings and heredoc formats.

Summary

Functions

Builds a replacement string for heredoc content.

Builds a replacement string for sigil content, preserving the original sigil type and delimiter.

Builds a replacement string for formatted content based on the original delimiter.

Builds a replacement string for simple string content.

Functions

build_heredoc_replacement(formatted)

@spec build_heredoc_replacement(String.t()) :: String.t()

Builds a replacement string for heredoc content.

Always preserves the heredoc format regardless of content.

Examples

iex> DprintMarkdownFormatter.PatchBuilder.build_heredoc_replacement("Hello")
"\"\"\"\nHello\n\"\"\""

iex> DprintMarkdownFormatter.PatchBuilder.build_heredoc_replacement("Hello\nWorld")
"\"\"\"\nHello\nWorld\n\"\"\""

build_replacement_sigil_string(formatted, sigil_prefix, delimiter)

@spec build_replacement_sigil_string(String.t(), String.t(), String.t()) :: String.t()

Builds a replacement string for sigil content, preserving the original sigil type and delimiter.

Handles all supported sigil delimiters and maintains proper formatting for both simple and heredoc-style sigils.

Examples

iex> DprintMarkdownFormatter.PatchBuilder.build_replacement_sigil_string("Hello", "~S", "\"")
"~S\"Hello\""

iex> DprintMarkdownFormatter.PatchBuilder.build_replacement_sigil_string("Hello\nWorld", "~S", "\"\"\"")
"~S\"\"\"\nHello\nWorld\n\"\"\""

iex> DprintMarkdownFormatter.PatchBuilder.build_replacement_sigil_string("Hello", "~s", "/")
"~s/Hello/"

build_replacement_string(formatted, delimiter)

@spec build_replacement_string(String.t(), String.t()) :: String.t()

Builds a replacement string for formatted content based on the original delimiter.

Automatically handles conversion between simple strings and heredocs when content becomes multi-line.

Examples

iex> DprintMarkdownFormatter.PatchBuilder.build_replacement_string("Hello", "\"")
"\"Hello\""

iex> DprintMarkdownFormatter.PatchBuilder.build_replacement_string("Hello\nWorld", "\"")
"\"\"\"\nHello\nWorld\n\"\"\""

iex> DprintMarkdownFormatter.PatchBuilder.build_replacement_string("Hello\nWorld", "\"\"\"")
"\"\"\"\nHello\nWorld\n\"\"\""

build_simple_string_replacement(formatted)

@spec build_simple_string_replacement(String.t()) :: String.t()

Builds a replacement string for simple string content.

If the content contains newlines, it will be converted to heredoc format. Otherwise, it remains as a simple quoted string.

Examples

iex> DprintMarkdownFormatter.PatchBuilder.build_simple_string_replacement("Hello")
"\"Hello\""

iex> DprintMarkdownFormatter.PatchBuilder.build_simple_string_replacement("Hello\nWorld")
"\"\"\"\nHello\nWorld\n\"\"\""