Created
July 13, 2020 01:44
-
-
Save hyrious/08ca0927365185c2b50eec8c01f70215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
doctype html | |
head | |
meta(charset='utf-8') | |
meta(name="viewport" content="width=device-width") | |
title diff | |
script(src='https://cdn.jsdelivr.net/gh/google/diff-match-patch@master/javascript/diff_match_patch.js') | |
style. | |
#app { | |
background-color: white; | |
color: black; | |
position: absolute; | |
left: 0; right: 0; | |
top: 0; bottom: 0; | |
} | |
.row { | |
display: flex; | |
} | |
.col { | |
flex: 1; | |
} | |
body | |
main#app.row | |
textarea#left.col | |
textarea#right.col | |
#result.col | |
script. | |
var l = document.querySelector('#left') | |
var r = document.querySelector('#right') | |
var a = document.querySelector('#result') | |
l.oninput = r.oninput = function() { | |
var diff = new diff_match_patch() | |
var d = diff.diff_main(l.value, r.value) | |
diff.diff_cleanupSemantic(d) | |
var html = diff.diff_prettyHtml(d) | |
a.innerHTML = html | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const pug = require('pug'); | |
const fs = require('fs-extra'); | |
const minify = require('html-minifier').minify; | |
async function work(file) { | |
const exist = await fs.pathExists(file); | |
if (!exist) return; | |
const text = await fs.readFile(file); | |
const rawhtml = pug.render(text); | |
const html = minify(rawhtml, { | |
caseSensitive: false, | |
collapseBooleanAttributes: true, | |
collapseInlineTagWhitespace: false, | |
collapseWhitespace: true, | |
conservativeCollapse: false, | |
decodeEntities: true, | |
html5: true, | |
includeAutoGeneratedTags: false, | |
keepClosingSlash: false, | |
minifyCSS: true, | |
minifyJS: true, | |
preserveLineBreaks: false, | |
preventAttributesEscaping: false, | |
processConditionalComments: true, | |
processScripts: ['text/html'], | |
removeAttributeQuotes: true, | |
removeComments: true, | |
removeEmptyAttributes: true, | |
removeEmptyElements: false, | |
removeOptionalTags: true, | |
removeRedundantAttributes: true, | |
removeScriptTypeAttributes: true, | |
removeStyleLinkTypeAttributes: true, | |
removeTagWhitespace: true, | |
sortAttributes: true, | |
sortClassName: true, | |
trimCustomFragments: true, | |
useShortDoctype: true, | |
}); | |
const target = path.join( | |
path.dirname(file), | |
path.basename(file, path.extname(file)) + '.html' | |
); | |
await fs.writeFile(target, html); | |
console.info(file, '->', target, 'ok'); | |
} | |
async function main() { | |
try { | |
const files = await fs.readdir('.'); | |
const pugs = files.filter(e => path.extname(e) === '.pug'); | |
await Promise.all(pugs.map(work)); | |
} catch (err) { | |
console.error(err.msg); | |
console.error(err.filename, err.line, err.column); | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment