News for hackers. Stuff that matters.
Re:Show HN: Convert HTML to markdown with python by krstf13 on Monday May 29, 2017 @06:56AM (#14438497)
You should use HTML.parser and focus on the conversion to markdown. The way you parse HTML in the convert function is very inefficient and can easily produce incorrect results with valid HTML (e.g. <p class="some>stuff">some text</p> )
Re:Show HN: Convert HTML to markdown with python by williamstein on Sunday May 28, 2017 @12:51PM (#14435129)
Since this is "Show HN", what is the motivation you have for doing this? There's no motivation or background in the linked README.
Re:Show HN: Convert HTML to markdown with python by gaojiuli on Sunday May 28, 2017 @11:10PM (#14437168)
When crawling online articles such as news, blogs, etc. I want to save them in markdown files but not databases.
Re:Show HN: Convert HTML to markdown with python by Bino on Sunday May 28, 2017 @01:10PM (#14435216)
Wouldn't it make sense to escape markdown syntax in the HTML? In HTML which you're converting from. * has not special meaning.

<p>foo</p>

Re:Show HN: Convert HTML to markdown with python by gaojiuli on Sunday May 28, 2017 @11:19PM (#14437194)
Tomd has the ability of converting the HTML that converted from markdown. If a HTML can't be described by markdown, tomd can't convert it.
Re:Show HN: Convert HTML to markdown with python by jwilk on Sunday May 28, 2017 @01:18PM (#14435241)
How is it better than https://alir3z4.github.io/html2text/ ?
Re:Show HN: Convert HTML to markdown with python by gaojiuli on Sunday May 28, 2017 @11:12PM (#14437175)
Maybe the number of lines of code is less. And the logic of tomd is easier to understand.
Re:Show HN: Convert HTML to markdown with python by roryisok on Sunday May 28, 2017 @02:54PM (#14435597)
Nice to see projects that convert HTML to markdown. Projects to convert in the other direction (md to html) are far more common. Parsing HTML is tough
Re:Show HN: Convert HTML to markdown with python by 4e1a on Sunday May 28, 2017 @08:04PM (#14436666)
I completely agree. I had made something similar in lua and it was very fun and I found many md to html converters, but not the other way around. HTML parsing is what made me 'pause' development on that tool.
Re:Show HN: Convert HTML to markdown with python by confounded on Sunday May 28, 2017 @02:56PM (#14435607)
Pandoc may be of interest.
Re:Show HN: Convert HTML to markdown with python by gaojiuli on Sunday May 28, 2017 @11:21PM (#14437202)
Tomd is a python tool. Pandoc is a haskell tool.
Re:Show HN: Convert HTML to markdown with python by cyphar on Sunday May 28, 2017 @11:43PM (#14437283)
Yes. Though pandoc handles more formats and doesn't parse HTML using regex. And it supports more features.

In general the language something is written in isn't necessarily a benefit by itself. Is there a reason why you prefer Python when there already exists another tool written in another language?

Re:Show HN: Convert HTML to markdown with python by gaojiuli on Monday May 29, 2017 @12:07AM (#14437360)
When crawling online articles such as news, blogs, etc. I want to save them in markdown files but not databases. For instance, I can download my wordpress blogs as markdown files with requests and tomd in a single python script without configering another language environment.
Re:Show HN: Convert HTML to markdown with python by confounded on Wednesday May 31, 2017 @01:30PM (#14454329)
You don't need a Haskell interpreter, it's shipped as a compiled CLI by most good package managers. There are also Python wrappers. Regardless, I'm very glad your tool is working, it looks cool.