dlon / html2markdown Goto Github PK
View Code? Open in Web Editor NEWConservatively convert html to markdown
License: MIT License
Conservatively convert html to markdown
License: MIT License
not support python3?
When I try to convert HTML, then I get the wrong output.
Example:
In [1]: a = '<blockquote><a href="url_address">text</a></blockquote>'
In [2]: html2markdown.convert(a)
Out[2]: ' [text](url_address'
But if I add whitespace before closing tag, then everything works fine except for a space at the beginning of a line:
In [1]: a = '<blockquote><a href="url_address">text</a> </blockquote>'
In [2]: html2markdown.convert(a)
Out[2]: ' [text](url_address)'
Maybe you know how to fix it?
Converting code blocks with formatting seems to strip line breaks and indentation. E.g. when attempting to convert this HTML:
<pre><code>import random
num = random.randint(1, 10)
guess = None
while guess != num:
guess = input("guess a number between 1 and 10: ")
guess = int(guess)
if guess == num:
print("congratulations! you won!")
break
else:
print("nope, sorry. try again!")</code></pre>
It turns into the following Markdown:
import random
num = random.randint(1, 10) guess = None
while guess != num: guess = input("guess a number between 1 and 10: ") guess = int(guess) if guess == num: print("congratulations! you won!") break else: print("nope, sorry. try again!")
Markdown that uses backticks to indicate code blocks instead of indentation has the advantage that it is very easy to add language-identifier information to it, e.g.:
```python
print("hello")
```
Is there an option to convert <pre><code>
HTML into fenced code blocks, or would you be interested to add it?
In Python 2.6 sys.version_info
doesn't have a major
attribute.
Here is the stack trace and output:
>>> import html2markdown
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/data/rally_jira_sync/venv/lib/python2.6/site-packages/html2markdown.py", line 10, in <module>
if sys.version_info.major > 2:
AttributeError: 'tuple' object has no attribute 'major'
>>> import sys
>>> sys.version_info
(2, 6, 6, 'final', 0)
>>> sys.version_info.major
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'major'
>>> dir(sys.version_info)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']
The line in question could be changed from:
if sys.version_info.major > 2:
To:
if sys.version_info[0] > 2:
To support Python 2.6.
Not sure how supported this library is, but just submitting the issue to see if I get a reply.
Thanks
This is great. Are reference-style links on the roadmap? Inline works great for bulk conversions, this would be more of a nice-to-have thing.
Received this from an Apple mail client writing emojis in HTML mails. I know, I know… but the tool could handle this better.
% echo "��" | html2markdown - windows-1252
Traceback (most recent call last):
File "/usr/bin/html2markdown", line 33, in <module>
sys.exit(load_entry_point('html2text==2020.1.16', 'console_scripts', 'html2text')())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/html2text/cli.py", line 306, in main
sys.stdout.write(h.handle(html))
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 0-1: surrogates not allowed
For a start, it would help to know a bit more about where the error occurs, i.e. maybe print some context?
Or have something like --encode-errors=replace
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.