TSBSoftware/elm-textblock/1.0.0

TextBlock

Process multiline strings in Elm, removing unwanted indentation and providing flexible formatting options, similar to C# Raw String Literals or Java Text Blocks.

Ideal for generating clean SQL queries, email templates, HTML, or Markdown.

Types

type alias TextBlockOptions =
{ indent : Int
, indentChar : Char
, newline : String
, templateValueStart : String
, templateValueEnd : String
}

Configuration options for text block processing.

  • indent: Number of indentation characters to add to each line (default: 0).
  • indentChar: Character used for indentation (default: space).
  • newline: String used for line breaks (default: "\n").
  • templateValueStart: Start delimiter for interpolation placeholders (default: "{{").
  • templateValueEnd: End delimiter for interpolation placeholders (default: "}}").
defaultOptions : TextBlockOptions

Default configuration for text block processing.

Use as-is or customize fields, e.g., { defaultOptions | indent = 2, indentChar = '.' }.

Functions

textBlock : String -> String

Process a multiline string with default options, removing unwanted leading indentation.

textBlock
    """
    <div>
        <p>Hello</p>
    </div>
    """
-- "<div>\n    <p>Hello</p>\n</div>"

Supports backslash (\) for newline escaping and pipe (|) for preserving trailing spaces.

textBlockWith : TextBlockOptions -> String -> String

Process a multiline string with custom options.

textBlockWith { defaultOptions | indent = 2, indentChar = '.' }
    """
    <div>
        <p>Hello</p>
    </div>
    """
-- "..<div>\n..    <p>Hello</p>\n..</div>"

Supports backslash (\) for newline escaping and pipe (|) for preserving trailing spaces.

textBlockWithFormat : TextBlockOptions -> List ( String, String ) -> String -> String

Process a multiline string with custom options and replace placeholders with values.

textBlockWithFormat defaultOptions
    [ ( "name", "World" ) ]
    """
    Hello {{name}}!
    """
-- "Hello World!"

Placeholders are defined by templateValueStart and templateValueEnd in TextBlockOptions.