You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Converts HTML content to plain text with configurable line width.
44
-
45
-
This function converts HTML content to plain text and optionally wraps lines at the
46
-
specified width. The width can be either a positive integer representing the maximum
47
-
number of characters per line, or `:infinity` for unlimited line width.
42
+
@typeopts::[
43
+
width: pos_integer()|:infinity,
44
+
decorate: boolean(),
45
+
link_footnotes: boolean(),
46
+
table_borders: boolean(),
47
+
pad_block_width: boolean(),
48
+
allow_width_overflow: boolean(),
49
+
min_wrap_width: pos_integer(),
50
+
raw: boolean(),
51
+
wrap_links: boolean(),
52
+
unicode_strikeout: boolean()
53
+
]
48
54
49
-
## Parameters
55
+
@doc"""
56
+
Converts HTML content to plain text.
57
+
58
+
## Options
59
+
- `:width` — Maximum line width (positive integer or `:infinity`). Defaults to `80`. Setting to `:infinity` disables line wrapping and outputs the entire text on a single line.
60
+
- `:decorate` — Enables text decorations like bold or italic. Boolean, defaults to `true`. When `false`, output is plain text without styling.
61
+
- `:link_footnotes` — Adds numbered link footnotes at the end of the text. Boolean, defaults to `true`. When `false`, links are omitted.
62
+
- `:table_borders` — Shows ASCII borders around table cells. Boolean, defaults to `true`. When `false`, tables render without borders.
63
+
- `:pad_block_width` — Pads blocks with spaces to align text to full width. Boolean, defaults to `false`. Useful for fixed-width layouts.
64
+
- `:allow_width_overflow` — Allows lines to exceed the specified width if wrapping is impossible. Boolean, defaults to `false`. Prevents errors when content can't fit.
65
+
- `:min_wrap_width` — Minimum length of text chunks when wrapping lines. Integer ≥ 1, defaults to `3`. Helps avoid awkwardly narrow wraps.
66
+
- `:raw` — Enables raw mode with minimal processing and formatting. Boolean, defaults to `false`. Produces plain, raw text output.
67
+
- `:wrap_links` — Wraps long URLs or links onto multiple lines. Boolean, defaults to `true`. When `false`, links stay on a single line and may overflow.
68
+
- `:unicode_strikeout` — Uses Unicode characters for strikeout text. Boolean, defaults to `true`. When `false`, strikeout renders in simpler styles.
50
69
51
-
- `html` - A binary containing the HTML content to convert
52
-
- `width` - Either a positive integer for line width or `:infinity` for unlimited width
70
+
## Examples
53
71
54
-
## Return Value
72
+
iex> html = "<h1>Title</h1><p>Some paragraph text.</p>"
73
+
...> HTML2Text.convert(html, width: 15)
74
+
{:ok, "# Title\\n\\nSome paragraph\\ntext.\\n"}
55
75
56
-
Returns a string containing the plain text representation of the HTML content.
iex> html = "<h1>Welcome to Our Amazing Website</h1><p>This is a comprehensive guide that covers everything you need to know about our services and products.</p>"
62
-
iex> HTML2Text.convert(html, 30)
63
-
"# Welcome to Our Amazing\\n# Website\\n\\nThis is a comprehensive guide\\nthat covers everything you\\nneed to know about our\\nservices and products.\\n"
64
-
65
-
# Converting with unlimited width
66
-
iex> html = "<div><strong>Important:</strong> Please read all the terms and conditions carefully before proceeding with your purchase.</div>"
67
-
iex> HTML2Text.convert(html, :infinity)
68
-
"**Important:** Please read all the terms and conditions carefully before proceeding with your purchase.\\n"
69
-
70
-
# Converting lists and complex HTML
71
-
iex> html = "<ul><li>First item with some detailed description</li><li>Second item that also has quite a bit of text</li><li>Third item</li></ul>"
72
-
iex> HTML2Text.convert(html, 25)
73
-
"* First item with some\\n detailed description\\n* Second item that also\\n has quite a bit of text\\n* Third item\\n"
74
-
75
-
# Converting tables and structured content
76
-
iex> html = "<table><tr><td>Product Name</td><td>Description</td><td>Price</td></tr><tr><td>Widget</td><td>A useful widget for everyday tasks</td><td>$19.99</td></tr></table>"
0 commit comments