Skip to content

Commit

Permalink
Merge branch 'mborsetti-py310'
Browse files Browse the repository at this point in the history
* mborsetti-py310:
  Added support Python 3.10, 3.11 and 3.12; removed older Python
  Support Python 3.10
  • Loading branch information
Alir3z4 committed Jan 16, 2024
2 parents 099c4b8 + 12706e2 commit 1e7cb73
Show file tree
Hide file tree
Showing 66 changed files with 68 additions and 90 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text eol=lf
*.bat text eol=crlf
*.png -text
*.pdf -text
33 changes: 33 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
language: python
cache: pip

matrix:
include:
- python: 3.12
env: TOXENV=black
- python: 3.12
env: TOXENV=flake8
- python: 3.12
env: TOXENV=mypy
- python: 3.12
env: TOXENV=isort
- python: 3.8
env: TOXENV=py38
- python: 3.9
env: TOXENV=py39
- python: 3.10
env: TOXENV=py310
- python: 3.11
env: TOXENV=py310
- python: 3.12
env: TOXENV=py310
- python: pypy3
env: TOXENV=pypy3

install:
- pip install tox
script:
- tox
after_success:
- pip install coveralls
- coveralls
26 changes: 12 additions & 14 deletions html2text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from typing import Dict, List, Optional, Tuple, Union

from . import config
from ._typing import OutCallback
from .elements import AnchorElement, ListElement
from .typing import OutCallback
from .utils import (
dumb_css_parser,
element_style,
Expand Down Expand Up @@ -93,20 +93,20 @@ def __init__(
self.out = out

# empty list to store output characters before they are "joined"
self.outtextlist = [] # type: List[str]
self.outtextlist: List[str] = []

self.quiet = 0
self.p_p = 0 # number of newline character to print before next output
self.outcount = 0
self.start = True
self.space = False
self.a = [] # type: List[AnchorElement]
self.astack = [] # type: List[Optional[Dict[str, Optional[str]]]]
self.maybe_automatic_link = None # type: Optional[str]
self.a: List[AnchorElement] = []
self.astack: List[Optional[Dict[str, Optional[str]]]] = []
self.maybe_automatic_link: Optional[str] = None
self.empty_link = False
self.absolute_url_matcher = re.compile(r"^[a-zA-Z+]+://")
self.acount = 0
self.list = [] # type: List[ListElement]
self.list: List[ListElement] = []
self.blockquote = 0
self.pre = False
self.startpre = False
Expand All @@ -116,19 +116,17 @@ def __init__(
self.lastWasNL = False
self.lastWasList = False
self.style = 0
self.style_def = {} # type: Dict[str, Dict[str, str]]
self.tag_stack = (
[]
) # type: List[Tuple[str, Dict[str, Optional[str]], Dict[str, str]]]
self.style_def: Dict[str, Dict[str, str]] = {}
self.tag_stack: List[Tuple[str, Dict[str, Optional[str]], Dict[str, str]]] = []
self.emphasis = 0
self.drop_white_space = 0
self.inheader = False
# Current abbreviation definition
self.abbr_title = None # type: Optional[str]
self.abbr_title: Optional[str] = None
# Last inner HTML (for abbr being defined)
self.abbr_data = None # type: Optional[str]
self.abbr_data: Optional[str] = None
# Stack of abbreviations to write later
self.abbr_list = {} # type: Dict[str, str]
self.abbr_list: Dict[str, str] = {}
self.baseurl = baseurl
self.stressed = False
self.preceding_stressed = False
Expand Down Expand Up @@ -324,7 +322,7 @@ def handle_tag(
# need the attributes of the parent nodes in order to get a
# complete style description for the current element. we assume
# that google docs export well formed html.
parent_style = {} # type: Dict[str, str]
parent_style: Dict[str, str] = {}
if start:
if self.tag_stack:
parent_style = self.tag_stack[-1][2]
Expand Down
File renamed without changes.
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ classifiers =
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
Expand All @@ -29,7 +30,7 @@ platform = OS Independent
[options]
zip_safe = False
packages = html2text
python_requires = >=3.7
python_requires = >=3.8

[options.entry_points]
console_scripts =
Expand All @@ -47,4 +48,4 @@ combine_as_imports = True
profile = black

[mypy]
python_version = 3.7
python_version = 3.8
1 change: 0 additions & 1 deletion test/abbr_tag.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
TLA xyz

*[TLA]: Three Letter Acronym

1 change: 0 additions & 1 deletion test/anchors.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ Additional hyperlink tests!
[**Bold Link**](http://some.link)
[`filename.py`](http://some.link/filename.py) [The source code is called
`magic.py`](http://some.link/magicsources.py)

1 change: 0 additions & 1 deletion test/apos_element.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
'

1 change: 0 additions & 1 deletion test/blockquote_example.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
> "The time has come", the Walrus said, "To talk of many things: Of shoes -
> and ships - and sealing wax - Of cabbages - and kings- And why the sea is
> boiling hot - And whether pigs have wings."
1 change: 0 additions & 1 deletion test/bold_long_line.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
**text** and a very long long long long long long long long long long long
long long long long long long long long long line

1 change: 1 addition & 0 deletions test/br_inside_a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[This is a test](https://example.org/)
1 change: 0 additions & 1 deletion test/break_preserved_in_blockquote.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ a

> b
> c
1 change: 0 additions & 1 deletion test/css_import_no_semicolon.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.

1 change: 0 additions & 1 deletion test/decript_tage.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
~~something~~ ~~something~~ ~~something~~

1 change: 0 additions & 1 deletion test/default_image_alt.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[![Image](images/google.png)](http://google.com)

1 change: 0 additions & 1 deletion test/doc_with_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ Header 1 | Header 2 | Header 3
---|---|---
Content 1 | Content 2 | ![200](http://lorempixel.com/200/200) Image!
Content 1 | Content 2 | ![200](http://lorempixel.com/200/200) Image!

1 change: 0 additions & 1 deletion test/doc_with_table_bypass.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ Content 2
![200](http://lorempixel.com/200/200) Image!

</td> </tr> </table>

1 change: 0 additions & 1 deletion test/emdash-para.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ Duis brisket drumstick, dolor fatback filet mignon meatloaf laboris tri-tip
speck chuck ball tip voluptate ullamco laborum.

\--

1 change: 0 additions & 1 deletion test/emphasis_preserved_whitespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ _emphasis_!
~ ~~strike~~

_em1_ _em2_

1 change: 0 additions & 1 deletion test/emphasis_whitespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ _~~si~~_
**_~~bis~~_**

.**_~~bis~~_**

1 change: 0 additions & 1 deletion test/empty-link.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
This test checks whether empty hyperlinks still appear in the markdown result.

[](http://some.link) [](http://some.link)

1 change: 0 additions & 1 deletion test/empty-title-tag.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[This is an A tag with an empty title property](test.html)

1 change: 0 additions & 1 deletion test/flip_emphasis.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*Something* __else__

1 change: 0 additions & 1 deletion test/header_tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@
######### H9

H10 H11 H12 NO number

1 change: 0 additions & 1 deletion test/horizontal_rule.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* * *

1 change: 0 additions & 1 deletion test/html-escaping.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ Escaped HTML like <div> or & should NOT remain escaped on output
...even when that escaped HTML is in a <pre> tag

`...or a <code> tag`

1 change: 0 additions & 1 deletion test/html_entities_out_of_text.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
[allas: Country Manager](http://thth)

1 change: 0 additions & 1 deletion test/images_as_html.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ src='image_with_width.jpg' height='300' alt='An image with a height attr' />
<img src='image_with_width_and_height.jpg' width='300' height='300' alt='An
image with width and height' /> <img src='image_with_width_and_height.jpg'
width='300' height='300' /> <img src='image_with_width_and_height.jpg' />

1 change: 0 additions & 1 deletion test/images_with_size.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ src='image_with_width.jpg' width='300' alt='An image with a width attr' />
/> <img src='image_with_width_and_height.jpg' width='300' height='300' alt='An
image with width and height' /> <img src='image_with_width_and_height.jpg'
width='300' height='300' /> ![](image_with_width_and_height.jpg)

1 change: 0 additions & 1 deletion test/img-tag-with-link.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ This test checks images with associated links.
[![{banana}](http://placehold.it/350x150#{banana})](http://some.link)
[![\(\[{}\]\)](http://placehold.it/350x150#\(\[{}\]\))](http://some.link)
[![](http://placehold.it/350x150#\(\[{}\]\))](http://some.link)

1 change: 0 additions & 1 deletion test/invalid_start.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
1. The ol has an invalid start
2. This should just be ignored

1 change: 0 additions & 1 deletion test/invalid_unicode.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Br

1 change: 0 additions & 1 deletion test/kbd_tag.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Press `[CTRL]+c` to copy.

1 change: 0 additions & 1 deletion test/link_titles.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[ first example](http://example.com "MyTitle")
[ second example](http://example.com)

1 change: 0 additions & 1 deletion test/list_tags_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ Drums

* something else here
* some item

1 change: 0 additions & 1 deletion test/long_lines.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd
asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd
asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd asd
asd asd asd asd asd

1 change: 0 additions & 1 deletion test/lrm_after_b.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
**b**

1 change: 0 additions & 1 deletion test/lrm_after_i.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
_Foo_

1 change: 0 additions & 1 deletion test/lrm_inside_i.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
_Foo bar_

1 change: 0 additions & 1 deletion test/mark_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ Normal text with 'pre' code block.
[/code]

Normal text continues.

1 change: 0 additions & 1 deletion test/mixed_nested_lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
1. ordered
2. ...
* end

1 change: 0 additions & 1 deletion test/nbsp.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum.

1 change: 0 additions & 1 deletion test/nbsp_unicode.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt
in culpa qui officia deserunt mollit anim id est laborum.

1 change: 0 additions & 1 deletion test/no_inline_links_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
[2]: http://example.com (Example title)

[3]: http://example.com (abc)

1 change: 0 additions & 1 deletion test/no_inline_links_images_to_alt.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
[1]: http://example.com/img.png

[2]: http://example.com

1 change: 0 additions & 1 deletion test/no_mailto_links.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Send an email to [email protected].

1 change: 0 additions & 1 deletion test/no_wrap_links.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
And [here](http://bugs.debian.org/cgi-bin/pkgreport.cgi?tag=multiarch;[email protected]) is a long link I had at hand.

1 change: 0 additions & 1 deletion test/no_wrap_links_no_inline_links.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
And [here](http://bugs.debian.org/cgi-bin/pkgreport.cgi?tag=multiarch;[email protected]) is a long link I had at hand.

1 change: 0 additions & 1 deletion test/normal.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ not a hr
\- - -

c:\tmp, \\\server\path, \\_/, foo\bar, #\\#, \\\\#

1 change: 0 additions & 1 deletion test/normal_escape_snob.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ not a hr
\- - -

c:\tmp, \\\server\path, \\\_/, foo\bar, \#\\\#, \\\\\#

2 changes: 0 additions & 2 deletions test/pad_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,3 @@ something else entirely
| A | B+C |
| A+B | C |
| A+B+C |


2 changes: 0 additions & 2 deletions test/pad_table_empty.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
| |


2 changes: 0 additions & 2 deletions test/pad_table_no_closed_tr.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
| **xxx** | **xxx** | xxxx | **xxxx** | **xxxx** | xxxx |


1 change: 0 additions & 1 deletion test/pre.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@

Ensure that HTML that starts with a crowded `<pre>` is converted to reasonable
Markdown.

1 change: 0 additions & 1 deletion test/preformatted_in_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@

* ?
* Profit!

1 change: 0 additions & 1 deletion test/protect_links.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
[foo](<http://im-a-very-very-very-very-very-very-very-very-very-very-
long/link.html>)

1 change: 0 additions & 1 deletion test/q_tag.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
"If this is a test," he said, "then it should pass".

1 change: 0 additions & 1 deletion test/rlm_inside_strong.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
**Foo bar**

1 change: 0 additions & 1 deletion test/stressed_with_html_entities.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
**hello** world ><

1 change: 0 additions & 1 deletion test/table_ignore.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ Header 1 Header 2 Header 3
Content 1 Content 2 ![200](http://lorempixel.com/200/200) Image!
Content 1 Content 2 longer ![200](http://lorempixel.com/200/200) Image!
something else entirely

Loading

0 comments on commit 1e7cb73

Please sign in to comment.