diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9142239 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# editorconfig.org +root = true + +[*] +indent_size = 2 +indent_style = space +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3adea5b --- /dev/null +++ b/.gitignore @@ -0,0 +1,54 @@ +###Node### + +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Commenting this out is preferred by some people, see +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- +node_modules + +# Users Environment Variables +.lock-wscript + + +###OSX### + +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..85e7c0e --- /dev/null +++ b/.npmignore @@ -0,0 +1,62 @@ +###Node### + +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Commenting this out is preferred by some people, see +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- +node_modules + +# Users Environment Variables +.lock-wscript + + +###OSX### + +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# npm specific + +test +.cz.json +.travis.yml +.editorconfig diff --git a/examples/index.js b/examples/index.js new file mode 100644 index 0000000..fde44b5 --- /dev/null +++ b/examples/index.js @@ -0,0 +1,36 @@ +'use strict'; + +/** + * html-to-markdown + * Copyright(c) 2015-2015 Harminder Virk + * MIT Licensed +*/ + +var converter = require('../index'); + +var html = `
+

This is a dummy heading for Lorem guy

+

I am sub heading buddy

+

This is a paragrap buddy

+ +
    +
  1. This is ol 1
  2. +
+ +
This is a section
+
+    var name = "foo";
+  
+
+ This is super quote + In multiple lines +
+ This is bold tag + Some italic +
+` +console.log(converter.convert(html)) \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..9e79096 --- /dev/null +++ b/index.js @@ -0,0 +1,9 @@ +'use strict'; + +/** + * html-to-markdown + * Copyright(c) 2015-2015 Harminder Virk + * MIT Licensed +*/ + +module.exports = require('./src/index.js'); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..ef74e9f --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "html-to-markdown", + "version": "1.0.0", + "description": "html to markdown converter with zero dependencies", + "main": "index.js", + "directories": { + "example": "examples" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "html-to-markdown", + "markdown" + ], + "author": "amanvirk", + "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/thetutlage/html-to-markdown.git" + }, + "bugs": { + "url": "https://github.com/thetutlage/html-to-markdown/issues" + }, + "homepage": "https://github.com/thetutlage/html-to-markdown#readme" +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..c73dbb0 --- /dev/null +++ b/readme.md @@ -0,0 +1,35 @@ +# Html to markdown converter + +Html to markdown converter is a dependency free converter which replaces html with a valid markdown syntax. I have just started working on it, so all tags may not be supported. + +## Supported Platforms + +1. Web browsers. +2. NodeJs + +## Tags Supported + +1. h1,h2,h3,h4,h5,h6 +2. p +3. ul,ol +4. blockquote, +5. pre +6. bold,strong +7. italic,em + +## Converting Html Documents + +```javascript +var converter = require('html-to-markdown'); +var markdown = converter.convert('

Happy Journey

'); +``` + +## Extending to add your own formatters. + +```javascript +var converter = require('html-to-markdown'); +converter.use(function (html) { + // making required changes + // and return new html +}) +``` diff --git a/src/formatters.js b/src/formatters.js new file mode 100644 index 0000000..4bb055d --- /dev/null +++ b/src/formatters.js @@ -0,0 +1,184 @@ +'use strict'; + +/** + * html-to-markdown + * Copyright(c) 2015-2015 Harminder Virk + * MIT Licensed +*/ + +var headingRegex = /([\s\S]*?)<\/h\d*>/gim +var pRegex = /

([\s\S]*?)<\/p>/gim +var ulRegex = /