TToolbox
↵

Word Wrap

Hard-wrap to a width, counting CJK as double

About this tool

Hard Word Wrapping and column width formatting is a fundamental text processing utility for terminal CLI printing, Git commit message formatting (the 72-character convention), RFC 5322 plain text email transmission, and micro-controller display rendering. While modern browsers soft-wrap continuous text, exporting raw text files without physical newline characters (`\n`) yields unreadable thousand-character horizontal lines. This tool calculates visual column widths, preserves English word boundaries, counts CJK characters as double-width, and generates clean hard-wrapped prose locally.

How to Use This Tool (Step-by-Step)

1

Paste Continuous Text

Paste your continuous run-on paragraphs, Markdown drafts, or unformatted text streams into the input window.

2

Set Target Column Width

Adjust the column limit slider (e.g., Git standard 72 or terminal 80 columns) and toggle 'Wrap at Word Boundaries'.

3

Inspect Hard-Wrapped Text & Copy

The right pane reflects the hard-wrapped text blocks with clean vertical right margins. Copy output with one click.

Intelligent Word Boundary Protection

Automatically pushes overflowing English words to the next line, avoiding ugly mid-word hyphens and broken vocabularies.

CJK Double-Width Monospace Tracking

Strictly conforms to Unicode East Asian Width: tallies CJK characters as 2 visual columns and ASCII as 1 for balanced gutters.

100% Client-Side Air-Gapped

Line wrapping executes strictly inside local browser memory. Confidential scripts and teleprompter drafts are never logged.

Typography Guidelines & Word Wrapping Gotchas

  • •Chinese Kinsoku Shori punctuation rules: Commas and periods must never start a newline. The formatter wraps trailing punctuation automatically.
  • •Handling unbroken long URLs: Unspaced 100-character URLs exceed standard margins. Consider keeping links on isolated dedicated lines.
  • •Markdown hard linebreaks: Standard markdown collapses single newlines into spaces. Append two trailing spaces to force line breaks in Markdown.

Code & Transformation Examples

Industry Standard Hard-Wrap Column Widths Benchmark

Standard Column Limits
• 50 字符 : Git 提交信息第一行摘要标准 (Subject line, 适合单行快速阅读)
• 72 字符 : Git 提交信息正文详细说明 (Body text, 保证在 git log 中不破损)
• 80 字符 : 经典 Unix/Linux 终端屏幕物理宽度 (80x24 虚拟控制台黄金标准)
• 100/120 : 现代前端代码 Prettier / ESLint 推荐单行代码最大宽度
Soft vs Hard Wrap
• 软换行 (Soft Wrap) : 纯属文本编辑器界面自带的视觉折叠,文件中根本不存在换行符;
• 硬换行 (Hard Wrap) : 物理向文本中插入真实的 '\n' 换行字节,无论放到任何软件里宽度完全不变!

* Git commit guidelines mandate wrapping body text at 72 columns to keep terminal logs clean.

JavaScript Greedy Word Wrapping Implementation

Word Wrap Snippet
function hardWordWrap(text, maxWidth = 72) {
  const words = text.split(/\s+/);
  let lines = [];
  let curLine = '';
  for (const w of words) {
    if (!curLine) {
      curLine = w;
    } else if (curLine.length + 1 + w.length <= maxWidth) {
      curLine += ' ' + w;
    } else {
      lines.push(curLine);
      curLine = w;
    }
  }
  if (curLine) lines.push(curLine);
  return lines.join('\n');
}
Output
输入一段 500 字英文,算法能在保留所有单词完整性的前提下,将其整齐裁切为每行严格小于 72 字符的优美矩形段落!

* Linear greedy parsing formats sprawling documents in single-pass O(N) time efficiency.

Frequently Asked Questions

Q: Why is 80 columns the historical standard for terminals?

A: IBM punch cards in 1928 held 80 columns. DEC VT100 terminal monitors standardized on 80x24 characters, cementing an enduring 50-year engineering baseline.

Q: What happens if a single English word is longer than maxWidth?

A: When an unbreakable word exceeds the entire line width limit, the engine automatically forces a break to preserve container bounds.

Q: Does wrapping preserve existing paragraph breaks?

A: Yes. The formatter splits documents by paragraph breaks first, reflowing lines within paragraphs while preserving double-newline block spacing.

Related Tools

All processing happens locally in your browser. Your data is never uploaded to a server.
/