Initial Commit! Working Code!
This commit is contained in:
1 parent
46d6b796e4
commit
5b73ee74fe
6 files changed
+268
No files matched your search
@@ -182,3 +182,8 @@ xcuserdata/
|
||||
*.moved-aside
|
||||
*.xccheckout
|
||||
*.xcscmblueprint
|
||||
|
||||
|
||||
app.js
|
||||
|
||||
public_html
|
||||
@@ -1,2 +1,10 @@
|
||||
# lint-neo-yt
|
||||
Linter!
|
||||
|
||||
### Live Demo
|
||||
http://lint.neo.yt
|
||||
|
||||
### Installation Instructions
|
||||
* `git clone`
|
||||
* ensure `public_html` is in your vhost document root
|
||||
* run `npm run-script build`
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
CSS Boilerplate
|
||||
*/
|
||||
|
||||
@import url('./node_modules/bootstrap/dist/css/bootstrap.min.css');
|
||||
@import url('./node_modules/bootswatch/darkly/bootstrap.min.css');
|
||||
@import url('./node_modules/highlight.js/styles/default.css');
|
||||
@import url('./node_modules/highlight.js/styles/monokai-sublime.css');
|
||||
|
||||
pre {
|
||||
outline: 1px solid #767676;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
padding-top: 50px;
|
||||
}
|
||||
|
||||
textarea#input, code#output {
|
||||
width: 100%;
|
||||
height: 25em;
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Lint!</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-fixed-top navbar-default">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="#">Linter</a>
|
||||
</div>
|
||||
<div id="navbar" class="collapse navbar-collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li id="html_tab" class="active"><a href="#">HTML</a></li>
|
||||
<li id="json_tab"><a href="#">JSON</a></li>
|
||||
<li id="xml_tab"><a href="#">XML</a></li>
|
||||
</ul>
|
||||
</div><!-- /.nav-collapse -->
|
||||
</div><!-- /.container -->
|
||||
</nav>
|
||||
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-9">
|
||||
<h1 id="header">HTML Lint</h1>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-9">
|
||||
<p>
|
||||
<div class="input">
|
||||
<textarea id="input"></textarea>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="output">
|
||||
<pre><code id="output" class="hljs" contenteditable="true"></code></pre>
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div><!-- /.container -->
|
||||
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Created by neo on 3/6/17.
|
||||
* @function require
|
||||
*/
|
||||
|
||||
// can't get browserify-shim to work right
|
||||
// let's just make it work here
|
||||
window.$ = window.jQuery = require('jquery');
|
||||
|
||||
// include bootstrap css and javascript
|
||||
require('./app.css');
|
||||
require('bootstrap');
|
||||
|
||||
|
||||
$('window').ready(function () {
|
||||
// use hasher for application page management
|
||||
var hasher = require('hasher');
|
||||
|
||||
// include highlight.js for display purposes
|
||||
var hljs = require('highlight.js');
|
||||
hljs.configure({
|
||||
tabReplace: ' '
|
||||
});
|
||||
|
||||
// use HTML Lint (will display later)
|
||||
var htmlLint = require('htmllint');
|
||||
|
||||
// JSON linting!
|
||||
var jsonLint = function (json) {
|
||||
if (typeof json != 'string') {
|
||||
return JSON.stringify(json, undefined, 4);
|
||||
} else {
|
||||
return jsonLint(JSON.parse(json));
|
||||
}
|
||||
};
|
||||
|
||||
// (x|ht)ml beautifying!
|
||||
// function stolen from https://gist.github.com/sente/1083506
|
||||
var xmlBeautify = function(xml) {
|
||||
var formatted = '';
|
||||
var reg = /(>)(<)(\/*)/g;
|
||||
var pad = 0;
|
||||
|
||||
xml.replace("\t", ' ');
|
||||
xml = xml.replace(reg, '$1\r\n$2$3');
|
||||
|
||||
$.each(xml.split('\r\n'), function(index, node) {
|
||||
var indent = 0;
|
||||
if (node.match( /.+<\/\w[^>]*>$/ )) {
|
||||
indent = 0;
|
||||
} else if (node.match( /^<\/\w/ )) {
|
||||
if (pad != 0) {
|
||||
pad -= 1;
|
||||
}
|
||||
} else if (node.match( /^<\w([^>]*[^\/])?>.*$/ )) {
|
||||
indent = 1;
|
||||
} else {
|
||||
indent = 0;
|
||||
}
|
||||
|
||||
var padding = '';
|
||||
for (var i = 0; i < pad; i++) {
|
||||
padding += ' ';
|
||||
}
|
||||
|
||||
formatted += padding + node + '\r\n';
|
||||
pad += indent;
|
||||
});
|
||||
|
||||
return formatted;
|
||||
};
|
||||
|
||||
// hasher page changer function
|
||||
var changeType = function(type) {
|
||||
if (type == '') {
|
||||
hasher.setHash('html');
|
||||
}
|
||||
switch (type) {
|
||||
case "html":
|
||||
case "xml":
|
||||
case "json":
|
||||
$("#navbar").find(">ul>li.active").removeClass("active");
|
||||
$("#"+type+"_tab").addClass('active');
|
||||
|
||||
$("#header").text(type.toUpperCase() + ' Linter');
|
||||
|
||||
hasher.setHash(type);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// hasher setup (now that the functions exist)
|
||||
hasher.prependHash = "!";
|
||||
hasher.changed.add(changeType);
|
||||
hasher.initialized.add(changeType);
|
||||
hasher.init();
|
||||
|
||||
// hook into the navbar tabs and use hasher for them
|
||||
$("#navbar").find(">ul>li").click(function(e) {
|
||||
e.preventDefault();
|
||||
changeType(this.id.replace('_tab', ''));
|
||||
});
|
||||
|
||||
|
||||
// main I/O
|
||||
var input = $('#input');
|
||||
var output = $('#output');
|
||||
|
||||
// function main ()
|
||||
input.change(function() {
|
||||
switch(hasher.getHash()) {
|
||||
case "html":
|
||||
case "xml":
|
||||
try {
|
||||
output.html(hljs.highlightAuto(xmlBeautify(input.val())).value);
|
||||
} catch (e) {
|
||||
output.html("Error: Unable to parse " + hasher.getHash() + " <br>" + e);
|
||||
}
|
||||
htmlLint(input.val()).then(function (out) {
|
||||
console.log(out);
|
||||
}, function(error) {
|
||||
console.log(error);
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
});
|
||||
break;
|
||||
case "json":
|
||||
try {
|
||||
output.html(hljs.highlightAuto(jsonLint(input.val())).value);
|
||||
} catch (e) {
|
||||
output.html("Error: Unable to parse JSON <br>" + e);
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "lint-neo-yt",
|
||||
"version": "1.0.0",
|
||||
"description": "Neo's Linter",
|
||||
"main": "js/app.js",
|
||||
"scripts": {
|
||||
"prebuild": "npm install",
|
||||
"build": "browserify -g uglifyify -o app.js index.js",
|
||||
"postbuild": "mkdir -p public_html/ && cp app.js public_html/ && cp index.html public_html/"
|
||||
},
|
||||
"author": "Amrit Panesar <neo@neo.yt>",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/Neo-Desktop/lint-neo-yt",
|
||||
"devDependencies": {
|
||||
"bootstrap": "^3.3.7",
|
||||
"bootswatch": "^3.3.7",
|
||||
"browserify": "^14.1.0",
|
||||
"browserify-css": "^0.10.0",
|
||||
"browserify-shim": "^3.8.13",
|
||||
"bulkify": "^1.4.2",
|
||||
"hasher": "^1.2.0",
|
||||
"highlight.js": "^9.9.0",
|
||||
"htmllint": "^0.6.0",
|
||||
"jquery": "^3.1.1",
|
||||
"uglifyify": "^3.0.4"
|
||||
},
|
||||
"browserify": {
|
||||
"transform": [
|
||||
"browserify-css",
|
||||
"browserify-shim"
|
||||
]
|
||||
},
|
||||
"browserify-css": {
|
||||
"autoInject": true,
|
||||
"minify": true,
|
||||
"rootDir": "./",
|
||||
"autoInjectOptions": {
|
||||
"verbose": true,
|
||||
"insertAt": "bottom"
|
||||
}
|
||||
},
|
||||
"browserify-shim": {}
|
||||
}
|
||||
Reference in new issue
Block a user