New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

h2m

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h2m - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

bin/h2m-cli.js

14

index.js

@@ -100,3 +100,3 @@ var posthtml = require('posthtml')

case 'a':
txt = getTextInNode(node) || node.attrs.href
txt = getTextInNode(node) || (node.attrs && node.attrs.href)
if (txt) {

@@ -108,3 +108,3 @@ text.push(`[${txt}](${node.attrs.href})`)

case 'img':
if (node.attrs.src) {
if (node.attrs && node.attrs.src) {
text.push(` ![${(node.attrs.title || node.attrs.alt || node.attrs.src).trim()}](${node.attrs.src}) `)

@@ -115,2 +115,4 @@ }

default:
text.push(getTextInNode(node))
node.content = []

@@ -173,3 +175,3 @@ }

case 'img':
if (node.attrs.src) {
if (node.attrs && node.attrs.src) {
md.push(`![${(node.attrs.title || node.attrs.alt || node.attrs.src).trim()}](${node.attrs.src})`)

@@ -185,3 +187,3 @@ }

case 'ul':
text = node.content.filter(function (node) {
text = node.content && node.content.filter(function (node) {
return typeof node == 'object' && node.tag == 'li'

@@ -191,3 +193,5 @@ }).map(function (node, index) {

}).join('\n')
md.push(`\n\n${text}`)
if (text) {
md.push(`\n\n${text}`)
}
node.content = []

@@ -194,0 +198,0 @@ break

{
"name": "h2m",
"version": "0.3.1",
"version": "0.4.0",
"description": "Transform HTML to markdown base on posthtml.",

@@ -8,5 +8,9 @@ "main": "index.js",

"test": "mocha && npm run coverage",
"istanbul": "istanbul cover ./node_modules/mocha/bin/_mocha",
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
"build": "browserify browser.js -o dist/h2m.js"
},
"bin": {
"h2m": "bin/h2m-cli.js"
},
"keywords": [

@@ -28,4 +32,6 @@ "posthtml",

"dependencies": {
"commander": "^2.9.0",
"posthtml": "^0.8.1",
"posthtml-parser": "^0.1.1"
"posthtml-parser": "^0.1.1",
"request": "^2.67.0"
},

@@ -32,0 +38,0 @@ "devDependencies": {

@@ -29,2 +29,47 @@ # h2m

## CLI
### install
```bash
$ npm install h2m -g
```
### usage
```
$h2m -h
Usage: h2m [options] <file>
Options:
-h, --help output usage information
-V, --version output the version number
```
Convert a local file:
```bash
$ h2m index.html
converting HTML to Markdown
made by [@island205](https://github.com/island205)
Can't be convert? welcome to submit an [issue](https://github.com/island205/h2m/issues/new).
```
Convert an online url:
```bash
$ h2m https://baidu.com
```
Save result:
```bash
$ h2m https://google.com > google.md
```
## Support

@@ -31,0 +76,0 @@

@@ -32,2 +32,3 @@ var h2m = require('../index')

expect(h2m('<a href="http://island205.github.io/h2m/"></a>')).to.equal('[http://island205.github.io/h2m/](http://island205.github.io/h2m/)')
expect(h2m('<a href="">h2m</a>')).to.equal('')
})

@@ -39,2 +40,3 @@

expect(h2m('<img src="https://raw.githubusercontent.com/island205/h2m/master/images/online-converter.png" />')).to.equal('![https://raw.githubusercontent.com/island205/h2m/master/images/online-converter.png](https://raw.githubusercontent.com/island205/h2m/master/images/online-converter.png)')
expect(h2m('<img />')).to.equal('')
})

@@ -48,2 +50,3 @@

expect(h2m(fixture('ul.html'))).to.equal(fixture('ul.md'))
expect(h2m('<ul></ul>')).to.equal('')
})

@@ -87,2 +90,24 @@

it('should parse nested inline tag', function () {
expect(h2m('<h1><a href="http://island205.github.io/h2m/">h2m</a></h1>')).to.equal('# [h2m](http://island205.github.io/h2m/)')
expect(h2m('<h1><em></em>h2m</h1>')).to.equal('# h2m')
expect(h2m('<h1><strong></strong>h2m</h1>')).to.equal('# h2m')
expect(h2m('<h1><code></code>h2m</h1>')).to.equal('# h2m')
expect(h2m('<h1><a></a>h2m</h1>')).to.equal('# h2m')
expect(h2m('<h1><img />h2m</h1>')).to.equal('# h2m')
expect(h2m('<h1><a href="http://island205.github.io/h2m/"></a></h1>')).to.equal('# [http://island205.github.io/h2m/](http://island205.github.io/h2m/)')
expect(h2m('<a href="http://island205.github.io/h2m/">h2<br/>m</a>')).to.equal('[h2\nm](http://island205.github.io/h2m/)')
expect(h2m('<a href="http://island205.github.io/h2m/">h<em>2</em>m</a>')).to.equal('[h*2*m](http://island205.github.io/h2m/)')
expect(h2m('<h2>h<strong>2</strong>m</h2>')).to.equal('## h**2**m')
expect(h2m('<h2><code>h2m</code></h2>')).to.equal('## `h2m`')
expect(h2m('<a href="http://island205.github.io/h2m/"><img title="h2m" src="https://raw.githubusercontent.com/island205/h2m/master/images/online-converter.png" /></a>')).to.equal('[![h2m](https://raw.githubusercontent.com/island205/h2m/master/images/online-converter.png)](http://island205.github.io/h2m/)')
expect(h2m('<a href="http://island205.github.io/h2m/"><img alt="h2m" src="https://raw.githubusercontent.com/island205/h2m/master/images/online-converter.png" /></a>')).to.equal('[![h2m](https://raw.githubusercontent.com/island205/h2m/master/images/online-converter.png)](http://island205.github.io/h2m/)')
expect(h2m('<a href="http://island205.github.io/h2m/"><img src="https://raw.githubusercontent.com/island205/h2m/master/images/online-converter.png" /></a>')).to.equal('[![https://raw.githubusercontent.com/island205/h2m/master/images/online-converter.png](https://raw.githubusercontent.com/island205/h2m/master/images/online-converter.png)](http://island205.github.io/h2m/)')
})
it('should ignore other unsupport tag', function () {
expect(h2m('<article>code</article>')).to.equal('code')
expect(h2m('<h2>co<i>d</i>e</h2>')).to.equal('## code')
})
})

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc