Git Product home page Git Product logo

html2markdown's People

Contributors

dlon avatar fufler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

html2markdown's Issues

Wrong markup

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?

Preserve <pre> line formatting

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!")

Render <pre><code> constructs as fenced code blocks

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?

Getting an AttributeError in Python 2.6 with sys.version_info.major

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

Reference-style links?

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.

Fails to encode (replace) emojis

Received this from an Apple mail client writing emojis in HTML mails. I know, I know… but the tool could handle this better.

% echo "&#55357;&#56842;" | 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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.