kramdown-ansi 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +20 -0
- data/kramdown-ansi.gemspec +2 -2
- data/lib/kramdown/ansi/width.rb +8 -1
- data/lib/kramdown/version.rb +1 -1
- data/spec/kramdown/ansi/width_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6038ac6683b6c30a71839080b16df7c60c2633e53964ac57bcc7537ba5aa581e
|
|
4
|
+
data.tar.gz: 7c613274ea82fbb0d69d202545cb4d9e277981f4a6993bdcdbcfef0464b79d18
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f70b2e7878236a1c819ac5019be8f6bb7d1f1fe2a05c6e2103e607ca07cc5acd42c34ae8ec70377e7cccad915d9667b7a8741e1dc0d3142065c91333b571ad6c
|
|
7
|
+
data.tar.gz: b703677d623fc0ca36df6c4aa80d8f1199a0ee94f79dcbb517b4d80827c1434d42524810eead7aac8abb8d1082b7adea4e03811e66d6d6617ec3693ec62328fc
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-10-29 v0.9.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Added `reflow:` keyword argument to `Kramdown::ANSI::Width.wrap`. When set to
|
|
8
|
+
`false`, each line is wrapped independently, preserving original line breaks.
|
|
9
|
+
When set to `true` (the default), newlines are treated as whitespace and the
|
|
10
|
+
text is re-flowed as a single paragraph.
|
|
11
|
+
|
|
12
|
+
### Testing
|
|
13
|
+
|
|
14
|
+
- Added specs in `spec/kramdown/ansi/width_spec.rb` covering both `reflow:
|
|
15
|
+
false` (line-preserving wrap) and default `reflow: true` (paragraph reflow)
|
|
16
|
+
behavior.
|
|
17
|
+
|
|
18
|
+
### Documentation
|
|
19
|
+
|
|
20
|
+
- Updated YARD documentation for `Kramdown::ANSI::Width.wrap` to describe the
|
|
21
|
+
new `reflow:` option.
|
|
22
|
+
|
|
3
23
|
## 2026-10-29 v0.8.0
|
|
4
24
|
|
|
5
25
|
### Fixes
|
data/kramdown-ansi.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: kramdown-ansi 0.
|
|
2
|
+
# stub: kramdown-ansi 0.9.0 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "kramdown-ansi".freeze
|
|
6
|
-
s.version = "0.
|
|
6
|
+
s.version = "0.9.0".freeze
|
|
7
7
|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
9
9
|
s.require_paths = ["lib".freeze]
|
data/lib/kramdown/ansi/width.rb
CHANGED
|
@@ -54,12 +54,16 @@ module Kramdown::ANSI::Width
|
|
|
54
54
|
# @param text [String] the text to wrap
|
|
55
55
|
# @option percentage [Numeric] the percentage of terminal width to use
|
|
56
56
|
# @option length [Integer] the explicit character width to wrap to
|
|
57
|
+
# @option reflow [Boolean] when true (default), newlines are treated as
|
|
58
|
+
# whitespace and the text is re-flowed as a single paragraph; when
|
|
59
|
+
# false, each line is wrapped independently and original line breaks
|
|
60
|
+
# are preserved
|
|
57
61
|
# @return [String] the wrapped string, preserving ANSI escape sequences
|
|
58
62
|
# @raise [ArgumentError] if neither `percentage` nor `length` is provided
|
|
59
63
|
# @example
|
|
60
64
|
# Kramdown::ANSI::Width.wrap("Hello world!", percentage: 50)
|
|
61
65
|
# # => "Hello\nworld!"
|
|
62
|
-
def wrap(text, percentage: nil, length: nil)
|
|
66
|
+
def wrap(text, percentage: nil, length: nil, reflow: true)
|
|
63
67
|
percentage.nil? ^ length.nil? or
|
|
64
68
|
raise ArgumentError, "either pass percentage or length argument"
|
|
65
69
|
percentage and length ||= width(percentage:)
|
|
@@ -70,6 +74,9 @@ module Kramdown::ANSI::Width
|
|
|
70
74
|
return text
|
|
71
75
|
end
|
|
72
76
|
length = length.clamp(1..)
|
|
77
|
+
unless reflow
|
|
78
|
+
return text.lines.map { |l| wrap(l.chomp, length:, reflow: true) } * ?\n
|
|
79
|
+
end
|
|
73
80
|
length_without_ansi = 0
|
|
74
81
|
result = +''
|
|
75
82
|
text.scan(/(?<nws>\S+)|(?<ws>\s)/) do
|
data/lib/kramdown/version.rb
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# by hand; it is rewritten on every `rake version` invocation.
|
|
6
6
|
module Kramdown
|
|
7
7
|
# The current version of the Kramdown gem as a String.
|
|
8
|
-
VERSION = '0.
|
|
8
|
+
VERSION = '0.9.0'
|
|
9
9
|
VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
|
|
10
10
|
VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
|
|
11
11
|
VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
|
|
@@ -43,6 +43,18 @@ describe Kramdown::ANSI::Width do
|
|
|
43
43
|
"AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA AAAAAAAAAA"
|
|
44
44
|
)
|
|
45
45
|
end
|
|
46
|
+
|
|
47
|
+
it 'wraps each line independently with reflow: false' do
|
|
48
|
+
text = "aaaa bbbb cccc\ndddd eeee"
|
|
49
|
+
result = described_class.wrap(text, length: 9, reflow: false)
|
|
50
|
+
expect(result).to eq("aaaa bbbb\ncccc\ndddd eeee")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'reflows all lines as one paragraph by default' do
|
|
54
|
+
text = "aaaa\nbbbb cccc"
|
|
55
|
+
result = described_class.wrap(text, length: 9)
|
|
56
|
+
expect(result).to eq("aaaa\nbbbb\ncccc")
|
|
57
|
+
end
|
|
46
58
|
end
|
|
47
59
|
|
|
48
60
|
describe '.truncate' do
|