Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html2hyperscript

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html2hyperscript - npm Package Compare versions

Comparing version 0.1.1 to 1.0.1

.travis.yml

126

index.js

@@ -1,14 +0,4 @@

#!/usr/bin/env node
var fileName = process.argv[2];
if (!fileName) {
throw new Error('supply input HTML file as first argument');
}
var fs = require('fs');
var Parser = require('htmlparser2').Parser;
var elementStack = [];
function ItemList(parent) {

@@ -49,75 +39,79 @@ this.parent = parent;

var currentItemList = new ItemList(null);
function convert(inputMarkup) {
var elementStack = [];
var currentItemList = new ItemList(null);
var parser = new Parser({
onopentag: function (name, attribs) {
currentItemList = new ItemList(currentItemList);
elementStack.unshift([ name, attribs ]);
},
ontext: function (text) {
var lines = text.split("\n");
var parser = new Parser({
onopentag: function (name, attribs) {
currentItemList = new ItemList(currentItemList);
elementStack.unshift([ name, attribs ]);
},
ontext: function (text) {
var lines = text.split("\n");
var isFirst = true;
var isFirst = true;
lines.forEach(function (line) {
var lineMatch = /^(\s*)(.*?)(\s*)$/.exec(line);
lines.forEach(function (line) {
var lineMatch = /^(\s*)(.*?)(\s*)$/.exec(line);
var preSpace = lineMatch[1],
mainText = lineMatch[2],
postSpace = lineMatch[3];
var preSpace = lineMatch[1],
mainText = lineMatch[2],
postSpace = lineMatch[3];
if (!isFirst) {
currentItemList.addSpace("\n");
}
if (!isFirst) {
currentItemList.addSpace("\n");
}
currentItemList.addSpace(preSpace);
currentItemList.addSpace(preSpace);
if (mainText.length > 0) {
currentItemList.add(JSON.stringify(mainText));
}
if (mainText.length > 0) {
currentItemList.add(JSON.stringify(mainText));
}
isFirst = false;
});
},
onclosetag: function (tagname) {
var element = elementStack.shift();
var elementContent = currentItemList.content + currentItemList.spacer;
isFirst = false;
});
},
onclosetag: function (tagname) {
var element = elementStack.shift();
var elementContent = currentItemList.content + currentItemList.spacer;
currentItemList = currentItemList.parent;
currentItemList = currentItemList.parent;
var indent = currentItemList.indent;
var indent = currentItemList.indent;
var attribs = element[1];
var attribs = element[1];
var id = attribs['id'];
var idSuffix = id !== undefined ? '#' + id : '';
delete attribs['id'];
var id = attribs['id'];
var idSuffix = id !== undefined ? '#' + id : '';
delete attribs['id'];
var classNames = attribs['class'];
var classSuffix = (classNames !== undefined ? classNames : '').split(/\s+/g).filter(function (v) { return v.length > 0; }).map(function (cls) { return '.' + cls; }).join('');
delete attribs['class'];
var classNames = attribs['class'];
var classSuffix = (classNames !== undefined ? classNames : '').split(/\s+/g).filter(function (v) { return v.length > 0; }).map(function (cls) { return '.' + cls; }).join('');
delete attribs['class'];
var attrPairs = Object.keys(attribs).map(function (k) { return JSON.stringify(k) + ': ' + JSON.stringify(attribs[k]) });
var attrPairs = Object.keys(attribs).map(function (k) { return JSON.stringify(k) + ': ' + JSON.stringify(attribs[k]) });
var item = 'h(' + JSON.stringify(element[0] + idSuffix + classSuffix) + (
attrPairs.length
? ", { attributes: {\n" + indent + ' ' + attrPairs.join(",\n" + indent + ' ') + "\n" + indent + "} }"
: ''
) + (
elementContent.length
? ', [' + (elementContent[0] === "\n" ? '' : ' ') + elementContent + (elementContent.match(/\s$/) ? '' : ' ') + ']'
: ''
) + ')';
var item = 'h(' + JSON.stringify(element[0] + idSuffix + classSuffix) + (
attrPairs.length
? ", {\n" + indent + ' ' + attrPairs.join(",\n" + indent + ' ') + "\n" + indent + "}"
: ''
) + (
elementContent.length
? ', [' + (elementContent[0] === "\n" ? '' : ' ') + elementContent + (elementContent.match(/\s$/) ? '' : ' ') + ']'
: ''
) + ')';
currentItemList.add(item);
},
oncomment: function (text) {
currentItemList.add('/*' + text + '*/', false); // @todo comment-safety
}
}, {decodeEntities: true});
currentItemList.add(item);
},
oncomment: function (text) {
currentItemList.add('/*' + text + '*/', false); // @todo comment-safety
}
}, {decodeEntities: true});
parser.write(fs.readFileSync(fileName));
parser.end();
parser.write(inputMarkup);
parser.end();
process.stdout.write(currentItemList.content);
process.stdout.write("\n");
return currentItemList.content;
}
module.exports = convert;
{
"name": "html2hyperscript",
"version": "0.1.1",
"version": "1.0.1",
"description": "Convert legacy HTML to Hyperscript (https://github.com/dominictarr/hyperscript)",

@@ -9,9 +9,8 @@ "repository": {

},
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "tap ./test"
},
"bin": {
"html2hyperscript": "./index.js"
"html2hyperscript": "./commandline.js"
},

@@ -22,3 +21,7 @@ "author": "Nick Matantsev <nick.m@myplanet.io>",

"htmlparser2": "~3.8.2"
},
"devDependencies": {
"hyperscript": "~1.4.4",
"tap": "~0.7.1"
}
}

@@ -0,1 +1,3 @@

[![Build Status](https://travis-ci.org/unframework/html2hyperscript.svg?branch=master)](https://travis-ci.org/unframework/html2hyperscript)
# Convert Legacy HTML to Hyperscript

@@ -5,2 +7,9 @@

Use this for hand-converting legacy project source code (e.g. AngularJS templates): care is taken to preserve original whitespace and even comments. For dynamic serving and CI builds check out https://github.com/alexmingoia/jsx-transform instead.
```
npm install -g html2hyperscript
html2hyperscript legacy_markup_file.html > shiny_new_syntax.js
```
See Hyperscript library: https://github.com/dominictarr/hyperscript

@@ -66,4 +75,3 @@

- publish NPM package
- online converter tool
- some tests
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