Add line break and indent to subcommand descriptions
This commit is contained in:
parent
ef3b148147
commit
0acfb4b819
@ -36,15 +36,17 @@ module Formatter
|
|||||||
# Wraps text to fit within a given number of columns using regular expressions that:
|
# Wraps text to fit within a given number of columns using regular expressions that:
|
||||||
#
|
#
|
||||||
# 1. convert hard-wrapped paragraphs to a single line
|
# 1. convert hard-wrapped paragraphs to a single line
|
||||||
# 2. find any option descriptions longer than a pre-set length and wrap between words
|
# 2. add line break and indent to subcommand descriptions
|
||||||
|
# 3. find any option descriptions longer than a pre-set length and wrap between words
|
||||||
# with a hanging indent, without breaking any words that overflow
|
# with a hanging indent, without breaking any words that overflow
|
||||||
# 3. wrap any remaining description lines that need wrapping with the same indent
|
# 4. wrap any remaining description lines that need wrapping with the same indent
|
||||||
# 4. wrap all lines to the given width.
|
# 5. wrap all lines to the given width.
|
||||||
# @see https://macromates.com/blog/2006/wrapping-text-with-regular-expressions/
|
# @see https://macromates.com/blog/2006/wrapping-text-with-regular-expressions/
|
||||||
def wrap(s, width = 172)
|
def wrap(s, width = 172)
|
||||||
desc = OPTION_DESC_WIDTH
|
desc = OPTION_DESC_WIDTH
|
||||||
indent = width - desc
|
indent = width - desc
|
||||||
s.gsub(/(?<=\S) *\n(?=\S)/, " ")
|
s.gsub(/(?<=\S) *\n(?=\S)/, " ")
|
||||||
|
.gsub(/([`>)\]]:) /, "\\1\n ")
|
||||||
.gsub(/^( +-.+ +(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n" + " " * indent)
|
.gsub(/^( +-.+ +(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n" + " " * indent)
|
||||||
.gsub(/^( {#{indent}}(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n" + " " * indent)
|
.gsub(/^( {#{indent}}(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n" + " " * indent)
|
||||||
.gsub(/(.{1,#{width}})( +|$)\n?/, "\\1\n")
|
.gsub(/(.{1,#{width}})( +|$)\n?/, "\\1\n")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user