Skip to content

jkramer/p6-Text-Wrap

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
t
 
 
 
 
 
 
 
 
 
 
 
 

NAME

Text::Wrap - Wrap texts.

SYNOPSIS

use Text::Wrap;

say wrap-text($some-long-text);
say wrap-text($some-long-text, :width(50));
say wrap-text($some-long-text, :paragraph(rx/\n/));
say wrap-text($text-with-very-long-word, :hard-wrap);

DESCRIPTION

Text::Wrap provides a single function wrap-text that takes arbitrary text and wraps it to form paragraphs that fit the given width. There are three optional arguments that modify its behavior.

  • :width(80) sets the maximum width of a line. The default is 80 characters. If a single word is longer than this value, a line may become longer than this in order not to wrap the line in the middle of the word. This can be changed with :hard-break.

  • :hard-break makes wrap-text break lines in the middle of words that are longer than the maximum width. It's off by default, meaning that lines may become longer than the maximum width if the text contains words that are too long to fit a line.

  • :paragraph(rx/\n ** 2..*/) takes a Regex object which is used find paragraphs in the source text in order to retain them in the result. The default is \n ** 2..* (two or more consecutive linebreaks). To discard any paragraphs from the source text, you can set this to Regex:U.

  • :prefix('') takes a string that's inserted in front of every line of the wrapped text. The length of the prefix string counts into the total line width, meaning it's subtracted from the given :width.

AUTHOR

Jonas Kramer jkramer@mark17.net

COPYRIGHT AND LICENSE

Copyright 2016 Jonas Kramer.

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages