Alir3z4 / Alir3z4/html2text

text wrapped at 78 characters ignoring body_width setting and partially ignoring -b option

Đang mở
#315 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
2.2k
Fork
296
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I am using html2text version 2020.1.16 with Python 3.8.1. html2text wraps the text at 78 characters regardless of the setting of BODY_WIDTH in config.py or body_width in the parser. I set BODY_WIDTH = 0 in config.py, then:

>>> html = 'This line is longer than seventy-eight characters. It seems to be getting wrapped with backslash n line breaks at seventy-eight characters regardless of the body_width setting in config.py or in the parser.'
>>> len(html)
228

>>> plainmd = html2text.html2text(html)
>>> plainmd
'This line is longer than **seventy-eight** characters. It seems to be getting\nwrapped with backslash n line breaks at _seventy-eight_ characters regardless\nof the _body_width_ setting in config.py or in the parser.\n\n'
>>> len('This line is longer than **seventy-eight** characters. It seems to be getting')
77

>>> parser = html2text.HTML2Text()
>>> parser.body_width = 0
>>> parser.body_width
0
>>> plainmd = html2text.html2text(html)
>>> plainmd
'This line is longer than **seventy-eight** characters. It seems to be getting\nwrapped with backslash n line breaks at _seventy-eight_ characters regardless\nof the _body_width_ setting in config.py or in the parser.\n\n'

>>> parser.body_width = 22
>>> parser.body_width
22
>>> plainmd = html2text.html2text(html)
>>> plainmd
'This line is longer than **seventy-eight** characters. It seems to be getting\nwrapped with backslash n line breaks at _seventy-eight_ characters regardless\nof the _body_width_ setting in config.py or in the parser.\n\n'

>>> parser.body_width = 99
>>> parser.body_width
99
>>> plainmd
'This line is longer than **seventy-eight** characters. It seems to be getting\nwrapped with backslash n line breaks at _seventy-eight_ characters regardless\nof the _body_width_ setting in config.py or in the parser.\n\n'

However, at the command line, it wraps on the screen at the value specified with -b, but still puts a newline character in after 78 characters:
$ cat /tmp/test.html
This line is longer than **seventy-eight** characters. It seems to be getting\nwrapped with backslash n line breaks at _seventy-eight_ characters regardless\nof the _body_width_ setting in config.py or in the parser.
$
$ wc -l /tmp/test.html; wc -c /tmp/test.html
1 /tmp/test.html
217 /tmp/test.html
$
$ python3.8 -m html2text -b 0 /tmp/test.html
This line is longer than **seventy-eight** characters. It seems to be getting\nwrapped with backslash n line breaks at _seventy-eight_ characters regardless\nof the _body_width_ setting in config.py or in the parser.
$
$ echo 'This line is longer than **seventy-eight** characters. It seems to be getting' | wc -c
78
$
$ python3.8 -m html2text -b 22 /tmp/test.html
This line is longer
than **seventy-eight**
characters. It seems
to be getting\nwrapped
with backslash n line
breaks at _seventy-
eight_ characters
regardless\nof the
_body_width_ setting
in config.py or in the
parser.

$ python3.8 -m html2text -b 99 /tmp/test.html
This line is longer than **seventy-eight** characters. It seems to be getting\nwrapped with
backslash n line breaks at _seventy-eight_ characters regardless\nof the _body_width_ setting in
config.py or in the parser.

$

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.