From cccde8c35b1090ac96c8073fa0d53efed649a916 Mon Sep 17 00:00:00 2001 From: Chris Andrejewski Date: Sat, 23 Sep 2017 10:47:53 -0400 Subject: [PATCH] Fix to handle colons in CSS values --- docs/dist/himalaya.js | 2 +- docs/dist/himalaya.js.map | 2 +- src/formats/v0.js | 2 +- test/formats/v0.js | 19 +++++++++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/dist/himalaya.js b/docs/dist/himalaya.js index 10f63c3..496d699 100644 --- a/docs/dist/himalaya.js +++ b/docs/dist/himalaya.js @@ -147,7 +147,7 @@ function formatAttributes(attributes) { function formatStyles(str) { return str.trim().split(';').map(function (rule) { - return rule.trim().split(':'); + return splitHead(rule.trim(), ':'); }).reduce(function (styles, keyValue) { var _keyValue = _slicedToArray(keyValue, 2), rawKey = _keyValue[0], diff --git a/docs/dist/himalaya.js.map b/docs/dist/himalaya.js.map index 1afe52e..8716ab5 100644 --- a/docs/dist/himalaya.js.map +++ b/docs/dist/himalaya.js.map @@ -1 +1 @@ -{"version":3,"names":[],"mappings":"","sources":["himalaya.js"],"sourcesContent":["(function(f){if(typeof exports===\"object\"&&typeof module!==\"undefined\"){module.exports=f()}else if(typeof define===\"function\"&&define.amd){define([],f)}else{var g;if(typeof window!==\"undefined\"){g=window}else if(typeof global!==\"undefined\"){g=global}else if(typeof self!==\"undefined\"){g=self}else{g=this}g.himalaya = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o= 0 ? lookupIndex : len + lookupIndex;\n while (searchIndex < len) {\n var element = array[searchIndex++];\n if (element === searchElement) return true;\n if (isNaNElement && isRealNaN(element)) return true;\n }\n\n return false;\n}\n\n},{}],2:[function(require,module,exports){\n'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i[\"return\"]) _i[\"return\"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError(\"Invalid attempt to destructure non-iterable instance\"); } }; }(); /*\n This format adheres to the v0 ASP spec.\n */\n\n\nexports.default = format;\nexports.capitalize = capitalize;\nexports.camelCase = camelCase;\nexports.castValue = castValue;\nexports.unquote = unquote;\nexports.splitHead = splitHead;\nexports.formatAttributes = formatAttributes;\nexports.formatStyles = formatStyles;\n\nvar _compat = require('../compat');\n\nfunction format(nodes) {\n return nodes.map(function (node) {\n var type = capitalize(node.type);\n if (type === 'Element') {\n var tagName = node.tagName.toLowerCase();\n var attributes = formatAttributes(node.attributes);\n var children = format(node.children);\n return { type: type, tagName: tagName, attributes: attributes, children: children };\n }\n\n return { type: type, content: node.content };\n });\n}\n\nfunction capitalize(str) {\n return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\nfunction camelCase(str) {\n return str.split('-').reduce(function (str, word) {\n return str + word.charAt(0).toUpperCase() + word.slice(1);\n });\n}\n\nfunction castValue(str) {\n if (typeof str !== 'string') return str;\n if (str === '') return str;\n var num = +str;\n if (!isNaN(num)) return num;\n return str;\n}\n\nfunction unquote(str) {\n var car = str.charAt(0);\n var end = str.length - 1;\n var isQuoteStart = car === '\"' || car === \"'\";\n if (isQuoteStart && car === str.charAt(end)) {\n return str.slice(1, end);\n }\n return str;\n}\n\nfunction splitHead(str, sep) {\n var idx = str.indexOf(sep);\n if (idx === -1) return [str];\n return [str.slice(0, idx), str.slice(idx + sep.length)];\n}\n\nfunction formatAttributes(attributes) {\n return attributes.reduce(function (attrs, pair) {\n var _splitHead = splitHead(pair.trim(), '='),\n _splitHead2 = _slicedToArray(_splitHead, 2),\n key = _splitHead2[0],\n value = _splitHead2[1];\n\n value = value ? unquote(value) : key;\n if (key === 'class') {\n attrs.className = value.split(' ');\n } else if (key === 'style') {\n attrs.style = formatStyles(value);\n } else if ((0, _compat.startsWith)(key, 'data-')) {\n attrs.dataset = attrs.dataset || {};\n var prop = camelCase(key.slice(5));\n attrs.dataset[prop] = castValue(value);\n } else {\n attrs[camelCase(key)] = castValue(value);\n }\n return attrs;\n }, {});\n}\n\nfunction formatStyles(str) {\n return str.trim().split(';').map(function (rule) {\n return rule.trim().split(':');\n }).reduce(function (styles, keyValue) {\n var _keyValue = _slicedToArray(keyValue, 2),\n rawKey = _keyValue[0],\n rawValue = _keyValue[1];\n\n if (rawValue) {\n var key = camelCase(rawKey.trim());\n var value = castValue(rawValue.trim());\n styles[key] = value;\n }\n return styles;\n }, {});\n}\n\n},{\"../compat\":1}],3:[function(require,module,exports){\n'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.parseDefaults = undefined;\nexports.parse = parse;\n\nvar _lexer = require('./lexer');\n\nvar _lexer2 = _interopRequireDefault(_lexer);\n\nvar _parser = require('./parser');\n\nvar _parser2 = _interopRequireDefault(_parser);\n\nvar _v = require('./formats/v0');\n\nvar _v2 = _interopRequireDefault(_v);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\n/*\n Tags which contain arbitrary non-parsed content\n For example: