Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Indent ¶
Indent indents each line in input with a string. A line is a set of runes followed by a newline. The first line is indented with indent. Subsequent lines either use the same indent or use a "hanging indent" (an indent using spaces with length equal to indent) depending on the setting of hanging. All leading and trailing whitespace is stripped.
Example ¶
// A single, indented line. fmt.Println(wordwrap.Indent("leader: ", false, "A single line, indented with the leader.")) fmt.Println() // Indent multiple lines without a hanging indent. lines := ` The first line has a leader. The second line also has a leader.` fmt.Println(wordwrap.Indent("leader: ", false, lines)) fmt.Println() // Indent multiple lines without hanging indent. lines = ` The first line has a leader. The second line has a hanging indent.` fmt.Println(wordwrap.Indent("leader: ", true, lines)) fmt.Println()
Output: leader: A single line, indented with the leader. leader: The first line has a leader. leader: The second line also has a leader. leader: The first line has a leader. The second line has a hanging indent.
func IndentWithWrap ¶
IndentWithWrap wraps text on the limit column boundary but adds an indent to each line.
func Wrap ¶
Wrap word-wraps text on the "limit" column boundary. Multiple whitespace is consolidated into a single space or newline. Leading blank lines and all trailing whitespace is stripped. Empty lines, or lines starting with whitespace are untouched, so you can include "codeblocks" and/or break text into paragraphs. Text is returned unchanged if limit <= 0.
Example usage:
Wrap(10, "This string would be split onto several new lines")
Example ¶
// Wrap a single line at column 15. fmt.Println(wordwrap.Wrap(15, "Now is the time for all good men to come to the aid of their country.")) fmt.Println() // Wrap a paragraph at colume 15. paragraph := ` Have you ever watched a crab on the shore crawling backward in search of the Atlantic Ocean, and missing? That's the way the mind of man operates -- H. L. Mencken` fmt.Println(wordwrap.Wrap(15, paragraph)) fmt.Println() // Wrap multiple paragraphs at column 15. Paragraphs are // separated by one of more blank lines. multiParagraph := ` Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.` fmt.Println(wordwrap.Wrap(15, multiParagraph)) fmt.Println() // Multiparagraphs with indented text wrapped at column 15. indented := ` The quick brown fox jumped over the lazy dog. This text is not wrapped at all even though it goes past 15 columns. Now is the time for all good men to come to the aid of their country.` fmt.Println(wordwrap.Wrap(15, indented))
Output: Now is the time for all good men to come to the aid of their country. Have you ever watched a crab on the shore crawling backward in search of the Atlantic Ocean, and missing? That's the way the mind of man operates -- H. L. Mencken Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. The quick brown fox jumped over the lazy dog. This text is not wrapped at all even though it goes past 15 columns. Now is the time for all good men to come to the aid of their country.
Types ¶
This section is empty.