Remove home-grown xml formatting solution. Use npm packages xml-beautifier and js-beautify for html/xml formatting. Value-add CSS and JS with js-beautify

This commit is contained in:
Amrit Panesar committed 2017-03-10 14:33:24 -08:00
1 parent 5b73ee74fe
commit 4ee14a1ab2
7 files changed
+156 -86

No files matched your search

+1
View File
@@ -6,6 +6,7 @@
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<content url="file://$MODULE_DIR$/node_modules" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
+69
View File
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownProjectSettings">
<PreviewSettings splitEditorLayout="FIRST" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.0" maxImageWidth="0" showGitHubPageIfSynced="false" allowBrowsingInPreview="false" synchronizePreviewPosition="true" highlightPreviewType="LINE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true">
<PanelProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.javafx.html.panel" providerName="JavaFX WebView" />
</PanelProvider>
</PreviewSettings>
<ParserSettings>
<PegdownExtensions>
<option name="ABBREVIATIONS" value="false" />
<option name="ANCHORLINKS" value="true" />
<option name="ATXHEADERSPACE" value="false" />
<option name="AUTOLINKS" value="true" />
<option name="DEFINITIONS" value="true" />
<option name="FENCED_CODE_BLOCKS" value="true" />
<option name="FOOTNOTES" value="false" />
<option name="HARDWRAPS" value="true" />
<option name="INSERTED" value="false" />
<option name="QUOTES" value="false" />
<option name="RELAXEDHRULES" value="true" />
<option name="SMARTS" value="false" />
<option name="STRIKETHROUGH" value="true" />
<option name="SUBSCRIPT" value="false" />
<option name="SUPERSCRIPT" value="false" />
<option name="SUPPRESS_HTML_BLOCKS" value="false" />
<option name="SUPPRESS_INLINE_HTML" value="false" />
<option name="TABLES" value="true" />
<option name="TASKLISTITEMS" value="true" />
<option name="TOC" value="false" />
<option name="WIKILINKS" value="true" />
</PegdownExtensions>
<ParserOptions>
<option name="COMMONMARK_LISTS" value="false" />
<option name="DUMMY" value="false" />
<option name="EMOJI_SHORTCUTS" value="true" />
<option name="FLEXMARK_FRONT_MATTER" value="false" />
<option name="GFM_LOOSE_BLANK_LINE_AFTER_ITEM_PARA" value="false" />
<option name="GFM_TABLE_RENDERING" value="true" />
<option name="GITBOOK_URL_ENCODING" value="false" />
<option name="GITHUB_EMOJI_URL" value="false" />
<option name="GITHUB_LISTS" value="false" />
<option name="GITHUB_WIKI_LINKS" value="true" />
<option name="JEKYLL_FRONT_MATTER" value="false" />
<option name="SIM_TOC_BLANK_LINE_SPACER" value="false" />
</ParserOptions>
</ParserSettings>
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" embedUrlContent="false" addPageHeader="true">
<GeneratorProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.javafx.html.generator" providerName="JavaFx HTML Generator" />
</GeneratorProvider>
<headerTop />
<headerBottom />
<bodyTop />
<bodyBottom />
</HtmlSettings>
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssTextEnabled="false" isDynamicPageWidth="true">
<StylesheetProvider>
<provider providerId="com.vladsch.idea.multimarkdown.editor.javafx.html.css" providerName="Default JavaFx Stylesheet" />
</StylesheetProvider>
<ScriptProviders />
<cssText />
</CssSettings>
<HtmlExportSettings updateOnSave="false" parentDir="$ProjectFileDir$" targetDir="$ProjectFileDir$" cssDir="" scriptDir="" plainHtml="false" imageDir="" copyLinkedImages="false" imageUniquifyType="0" targetExt="" useTargetExt="false" noCssNoScripts="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" />
<LinkMapSettings>
<textMaps />
</LinkMapSettings>
</component>
</project>
+3
View File
@@ -0,0 +1,3 @@
<component name="MarkdownNavigator.ProfileManager">
<settings default="" pdf-export="" />
</component>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RequirejsProjectComponent">
<option name="publicPath" value="." />
<option name="configFilePath" value="index.js" />
</component>
</project>
+2
View File
@@ -22,6 +22,8 @@
<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>
<li id="js_tab"><a href="#">JavaScript</a></li>
<li id="css_tab"><a href="#">CSS</a></li>
</ul>
</div><!-- /.nav-collapse -->
</div><!-- /.container -->
+70 -85
View File
@@ -1,6 +1,5 @@
/**
* Created by neo on 3/6/17.
* @function require
*/
// can't get browserify-shim to work right
@@ -11,92 +10,101 @@ window.$ = window.jQuery = require('jquery');
require('./app.css');
require('bootstrap');
// use hasher for application page management
var hasher = require('hasher');
hasher.prependHash = '!';
// include/configure highlight.js
var hljs = require('highlight.js');
hljs.configure({
tabReplace: ' '.repeat(4)
});
// use HTML Lint (will display later)
var htmlLint = require('htmllint');
// js-beautify libraries
var beautify_js = require('js-beautify').js;
var beautify_css = require('js-beautify').css;
var beautify_html = require('js-beautify').html;
// xml-beautify library
var beautify_xml = require('xml-beautifier');
$('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') {
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');
case 'html':
case 'xml':
case 'json':
case 'js':
case 'css':
$('#navbar').find('>ul>li.active').removeClass('active');
$('#'+type+'_tab').addClass('active');
$("#header").text(type.toUpperCase() + ' Linter');
$('#header').text(type.toUpperCase() + ' Linter');
hasher.setHash(type);
break;
default:
hasher.setHash('html');
}
};
// hasher setup (now that the functions exist)
hasher.prependHash = "!";
// hasher setup (now that the function exists)
hasher.changed.add(changeType);
hasher.initialized.add(changeType);
hasher.init();
var beautify = function (type) {
var stringIn = input.val();
var stringOut = '';
try {
switch(type) {
case 'html':
htmlLint(stringIn).then(function (lintOutput) {
console.log(lintOutput);
}, function(e) {
console.log(e);
}).catch(function (e) {
console.log(e);
});
stringOut = hljs.highlightAuto(beautify_html(stringIn)).value;
break;
case 'xml':
stringOut = hljs.highlightAuto(beautify_xml(stringIn)).value;
break;
case 'json':
stringOut = hljs.highlightAuto(jsonLint(stringIn)).value;
break;
case 'js':
stringOut = hljs.highlightAuto(beautify_js(stringIn)).value;
break;
case 'css':
stringOut = hljs.highlightAuto(beautify_css(stringIn)).value;
break;
}
} catch (e) {
stringOut = 'Error: Unable to parse ' + type + '<br>' + e;
}
output.html(stringOut);
};
// hook into the navbar tabs and use hasher for them
$("#navbar").find(">ul>li").click(function(e) {
$('#navbar').find('>ul>li').click(function(e) {
e.preventDefault();
changeType(this.id.replace('_tab', ''));
});
@@ -108,30 +116,7 @@ $('window').ready(function () {
// 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;
}
beautify(hasher.getHash())
});
});
+4 -1
View File
@@ -20,9 +20,12 @@
"bulkify": "^1.4.2",
"hasher": "^1.2.0",
"highlight.js": "^9.9.0",
"html": "^1.0.0",
"htmllint": "^0.6.0",
"jquery": "^3.1.1",
"uglifyify": "^3.0.4"
"js-beautify": "^1.6.11",
"uglifyify": "^3.0.4",
"xml-beautifier": "^0.3.0"
},
"browserify": {
"transform": [