Last updated
Text Wrapper Examples
The Text Wrapper reformats text to fit within a specified line width by inserting line breaks at word boundaries. Below are practical examples for email formatting, code comments, terminal output, and documentation.
Basic Text Wrapping (Width: 72)
// Input (one long line):
"The quick brown fox jumps over the lazy dog. This is a longer sentence that demonstrates how the text wrapper breaks long lines at word boundaries to fit within the specified column width."
// Wrapped at 72 characters:
The quick brown fox jumps over the lazy dog. This is a longer sentence
that demonstrates how the text wrapper breaks long lines at word
boundaries to fit within the specified column width.
Email Formatting (Width: 72)
// Plain text email — traditional standard is 72 characters per line
// Input:
Hi Alice, I wanted to follow up on our conversation from last week about the project timeline. We need to finalize the requirements by Friday and schedule a review meeting for next week. Please let me know your availability.
// Wrapped at 72 characters:
Hi Alice, I wanted to follow up on our conversation from last week
about the project timeline. We need to finalize the requirements by
Friday and schedule a review meeting for next week. Please let me
know your availability.
Code Comment Wrapping (Width: 80)
// Input (long comment):
// This function calculates the total price including tax and shipping costs based on the items in the cart and the user's shipping address.
// Wrapped at 80 characters:
// This function calculates the total price including tax and shipping costs
// based on the items in the cart and the user's shipping address.
// Python docstring wrapped at 79 characters (PEP 8):
def calculate_total(cart, address):
"""
Calculate the total price including tax and shipping costs based on
the items in the cart and the user's shipping address.
Args:
cart: List of cart items with price and quantity.
address: User's shipping address for tax calculation.
Returns:
Total price as a float.
"""
Terminal Output (Width: 80)
// Help text wrapped for 80-column terminal:
// Input:
"Usage: mytool [OPTIONS] FILE\n\nThis tool processes the specified file and applies the configured transformations. Multiple files can be processed in sequence by providing multiple FILE arguments."
// Wrapped at 80 characters:
Usage: mytool [OPTIONS] FILE
This tool processes the specified file and applies the configured
transformations. Multiple files can be processed in sequence by
providing multiple FILE arguments.
Indentation Preservation
// Input (indented list items):
" - This is a list item with a very long description that needs to be wrapped to fit within the column width while preserving the indentation."
// Wrapped at 72 characters (indentation preserved):
- This is a list item with a very long description that needs to be
wrapped to fit within the column width while preserving the
indentation.
Hanging Indent
// Bibliography entry with hanging indent:
// Input:
"Smith, J. (2024). The Complete Guide to Modern Web Development. New York: Tech Publishing House. ISBN: 978-0-123456-78-9."
// Wrapped with hanging indent (first line full width, continuation indented):
Smith, J. (2024). The Complete Guide to Modern Web Development. New
York: Tech Publishing House. ISBN: 978-0-123456-78-9.
// Definition list with hanging indent:
API (Application Programming Interface): A set of rules and protocols
that allows different software applications to communicate with
each other over a network.
Multi-Paragraph Wrapping
// Input (two paragraphs):
"First paragraph with a long line that needs wrapping to fit within the column width.
Second paragraph that also has a long line requiring wrapping at the specified column width."
// Wrapped at 60 characters (paragraphs preserved):
First paragraph with a long line that needs wrapping
to fit within the column width.
Second paragraph that also has a long line requiring
wrapping at the specified column width.
Unwrap Text (Join Wrapped Lines)
// Input (hard-wrapped text):
The quick brown fox jumps over
the lazy dog. This text was
hard-wrapped at 30 characters
and needs to be unwrapped.
// Unwrapped output (single paragraph):
The quick brown fox jumps over the lazy dog. This text was hard-wrapped at 30 characters and needs to be unwrapped.
// Useful for:
// - Processing text that was wrapped for display
// - Re-wrapping at a different width
// - Feeding text to NLP tools that expect full sentences
README Documentation (Width: 80)
// Input:
"This library provides a comprehensive set of utilities for working with dates, times, and time zones in JavaScript applications. It supports all major time zone databases and provides a simple, intuitive API."
// Wrapped at 80 characters:
This library provides a comprehensive set of utilities for working with dates,
times, and time zones in JavaScript applications. It supports all major time
zone databases and provides a simple, intuitive API.
Python Text Wrapping
import textwrap
text = "The quick brown fox jumps over the lazy dog. This demonstrates Python's textwrap module."
# Wrap at 40 characters
print(textwrap.fill(text, width=40))
# The quick brown fox jumps over the
# lazy dog. This demonstrates Python's
# textwrap module.
# With indentation
print(textwrap.fill(text, width=40, initial_indent=' ', subsequent_indent=' '))
# Wrap and preserve paragraphs
paragraphs = text.split('\n\n')
wrapped = '\n\n'.join(textwrap.fill(p, width=72) for p in paragraphs)
# Unwrap (dedent)
print(textwrap.dedent(text))
Common Column Width Standards
- 72 characters: plain text email (RFC 2822 recommendation)
- 79 characters: Python code (PEP 8)
- 80 characters: traditional terminal width, many style guides
- 100 characters: modern wide terminal, some team style guides
- 120 characters: wide-screen code editors
- 132 characters: legacy mainframe terminal width
Common Use Cases
- Format plain text email to 72-character line width
- Wrap code comments to match project line length limit
- Prepare terminal help text and usage messages
- Format README and documentation files
- Unwrap text before re-wrapping at a different width
- Normalize line lengths in configuration files
- Format text for fixed-width displays and legacy systems
Paste your text into the Text Wrapper, set your column width, and get properly wrapped output ready to use.