neocotic / europa

Library for converting HTML into valid Markdown
MIT License
159 stars 24 forks source link

Option to allow inline HTML #11

Open neocotic opened 11 years ago

neocotic commented 11 years ago

When enabled (via the options) the parser should only clean specified HTML elements (i.e. remove all of their attributes) instead of replacing them with Markdown. When "cleaning" an element, all of its children will also be "cleaned" by the parser instead of converted into Markdown.

This functionality will be extremely useful when using tables.

The option should allow users to specify an array of specific tags;

md html, inline: ['p', 'table']

In this example it would "clean" all <p> and <table> tags, along with all their children.

neocotic commented 11 years ago

This won't be included in the next release as it'll require a lot of work to ensure "cleaned" elements (and especially their children) are formatted as you'd expect (e.g. indentation).

jaredly commented 11 years ago

I would appreciate having inline html that can't be converted to markdown left intact.

toddb commented 10 years ago

+1 @jaredly about leaving raw

Currently, I don't want to change all tables, only some (due to size). I am wondering if we could have the inline option css selector based?

neocotic commented 10 years ago

@jaredly A lot of elements that can't be converted are just removed (e.g. <object>) or have their contents rendered (e.g. <div>). This is best in the majority of cases as lots of these elements could exist if this tool was used to parse a full page's HTML. This option will be used to provide exceptions instead of changing all funcitonality. Perhaps another - separate - option could be added for what you're describing, if I'm understanding you correctly.

@toddb Great idea! I'll definitely consider that when looking at implementing this.

toddb commented 10 years ago

It does seem to me that the first (experimental) versions of this feature could be 'buyer beware' - if you include raw html you should have cleaned it first. In practice, this is what I am doing with tidy and some custom cleaning because my html is so raw. (I am doing one-off migration of content and suspect this isn't your key use case)

katowulf commented 10 years ago

Fwiw, I'm currently using this lib because it strips all HTML which can't be converted. I'm using it to convert Word docs into Markdown, so it's a long process with lots of crazy tags.

So if an option is added to keep inline HTML, I would really appreciate this being optional.

Also, thanks so much for this lib! :star2: