Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soffes/unmarkdown
Convert HTML to Markdown. Sometimes you just need to go the other way.
https://github.com/soffes/unmarkdown
html markdown ruby
Last synced: 3 months ago
JSON representation
Convert HTML to Markdown. Sometimes you just need to go the other way.
- Host: GitHub
- URL: https://github.com/soffes/unmarkdown
- Owner: soffes
- License: mit
- Created: 2013-12-15T05:02:09.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-02-10T17:11:22.000Z (over 4 years ago)
- Last Synced: 2024-07-24T23:54:51.584Z (4 months ago)
- Topics: html, markdown, ruby
- Language: Ruby
- Homepage:
- Size: 16.6 KB
- Stars: 133
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.markdown
- License: LICENSE
Awesome Lists containing this project
README
# Unmarkdown
Convert HTML to Markdown with Ruby.
There are several libraries that solve this, but Unmarkdown is simple. It's only [150 lines](lib/unmarkdown/parser.rb) and handles everything I threw at it with no problem. The other libraries I tried either didn't do recursion correctly or were missing some Markdown extensions I needed. Both were hard to change, so I just whipped this up in a few hours.
Enjoy!
## Installation
Add this line to your application's Gemfile:
``` ruby
gem 'unmarkdown'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install unmarkdown
## Usage
``` ruby
markdown = Unmarkdown.parse('Some HTML')
#=> Some **HTML**markdown = Unmarkdown.parse('My website is http://soff.es', autolink: true)
#=> My website is http://soff.es
```## Support
### Supported tags
* h1-h6
* blockquote
* ul, ol, li
* pre
* hr
* a
* em, i
* strong, b
* u
* mark
* code
* imgFor tags that aren't supported, their content will be added to the output. Basically it treats everything like a `
`.
### Options
All of the options default to `false`. If you'd like to turn additional things on, pass a hash with symbols as the second argument to `Unmarkdown.parse` (see example above).
* `fenced_code_blocks` — Uses three backticks before and after instead of four spaces before each line
* `allow_scripts` — By default, script tags are removed. If you set this option to `true` their original HTML will be included in the output
* `underline_headers` — By default hashes are added before headers. If you turn this option on, it will use equal signs for h1's or hypens for h2's and the rest will remain hashes.## Contributing
1. Fork it ( http://github.com/soffes/unmarkdown/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request