Skip to content

Instantly share code, notes, and snippets.

View prettycode's full-sized avatar

Chris prettycode

  • Seattle, WA
View GitHub Profile
@prettycode
prettycode / js2markup.htm
Last active December 16, 2015 06:49
Generate HTML from JavaScript object literals.
<!DOCTYPE html>
<html>
<head>
<title>Proof of Concept</title>
<script>
// TODO how should Arrays be handled?
// TODO strict mode (no '\n' or padding) to allow for significant whitespace (e.g. for <pre>, <textarea>)
var toHTML = function(value, name, indent) {
var pad = new Array((indent = indent || 0)).join(' ');
@prettycode
prettycode / js2xml.htm
Created April 16, 2013 05:16
JavaScript/JSON -> XHTML serializer.
<!DOCTYPE html>
<html xmlns:pretty="http://prettycode.org/xmlns/json2xml">
<head>
<title>Proof of Concept</title>
<script>
var XML = {
defaultNamespace: undefined,
stringify: function(ns, value, name) {
if (typeof ns === 'undefined') {
ns = this.defaultNamespace;
// Working example: http://www.jsfiddle.net/mUrVB/22/
(function($) {
$.fn.selection = function() {
var start = this[0].selectionStart,
end = this[0].selectionEnd;
if (start === end) {
return null;