Adds C# Raw String Literal style functionality to multiline strings.
$ dotnet add package TSBSoftware.TextBlockMakes F# multiline strings work like C# Raw string literal, or Java text blocks.
F# developers who would like to utilize multiline strings to format content, such as: html, xml, sql, templates, etc.
To start using TextBlock, install the nuget package into your project file.
dotnet add package TextBlock
Then, open the namespace to expose the extension.
open TextBlock
let myText =
"""
<div>
<p>Hello</p>
</div>
"""
.TextBlock()
Strings can contain imbedded newline characters.
let embeddedNewlines =
let nl = System.Environment.NewLine
$"""
This content has {nl}several lines
in {nl}the text.
"""
.TextBlock()
This will produce
This content has
several lines
in
the text.
Spaces at the end of each line can be preserved.
let blockedLines =
"""
Blocked |
Text |
"""
.TextBlock()
This will produce the following. Spaces represended by spaces.
Blocked...
Text......
Additional indentation can be applied. Indentation character can optionally be applied, which is a space by default. We will use a period to show what is applied.
let someHtml =
"""
<div>
<p>Hello</p>
</div>
"""
.TextBlock(indent = 4, indentChar = '.')
Will produce indented with the specified intentation.
....<div>
.... <p>Hello</p>
....</div>