diff --git a/dist/parser/elements/a.js b/dist/parser/elements/a.js index 93cc0868..49dc32a1 100644 --- a/dist/parser/elements/a.js +++ b/dist/parser/elements/a.js @@ -36,7 +36,7 @@ var H1 = function (_BaseElement) { value: function getDefaultStyles() { return { color: 'blue', - text_decoration: 'underline' + textDecoration: 'underline' }; } }, { diff --git a/dist/parser/elements/h1.js b/dist/parser/elements/h1.js index 7dae82cb..773fd05f 100644 --- a/dist/parser/elements/h1.js +++ b/dist/parser/elements/h1.js @@ -35,8 +35,8 @@ var H1 = function (_BaseElement) { return { display: 'block', color: 'black', - font_weight: 'bold', - font_size: '2em' + fontWeight: 'bold', + fontSize: '2em' }; } }, { diff --git a/dist/parser/elements/h2.js b/dist/parser/elements/h2.js index 27c7b02f..dd9f9ff5 100644 --- a/dist/parser/elements/h2.js +++ b/dist/parser/elements/h2.js @@ -35,8 +35,8 @@ var H2 = function (_BaseElement) { return { display: 'block', color: 'black', - font_weight: 'bold', - font_size: '1.5em' + fontWeight: 'bold', + fontSize: '1.5em' }; } }, { diff --git a/dist/parser/elements/h3.js b/dist/parser/elements/h3.js index f71a9c28..b03757a7 100644 --- a/dist/parser/elements/h3.js +++ b/dist/parser/elements/h3.js @@ -35,8 +35,8 @@ var H3 = function (_BaseElement) { return { display: 'block', color: 'black', - font_weight: 'bold', - font_size: '1.17em' + fontWeight: 'bold', + fontSize: '1.17em' }; } }, { diff --git a/dist/parser/elements/h4.js b/dist/parser/elements/h4.js index 74256ce7..4d2defea 100644 --- a/dist/parser/elements/h4.js +++ b/dist/parser/elements/h4.js @@ -35,8 +35,8 @@ var H4 = function (_BaseElement) { return { display: 'block', color: 'black', - font_weight: 'bold', - font_size: '1.17em' + fontWeight: 'bold', + fontSize: '1.17em' }; } }, { diff --git a/dist/parser/elements/h5.js b/dist/parser/elements/h5.js index 5acf186c..a7d001ff 100644 --- a/dist/parser/elements/h5.js +++ b/dist/parser/elements/h5.js @@ -35,8 +35,8 @@ var H5 = function (_BaseElement) { return { display: 'block', color: 'black', - font_weight: 'bold', - font_size: '.83em' + fontWeight: 'bold', + fontSize: '.83em' }; } }, { diff --git a/dist/parser/elements/h6.js b/dist/parser/elements/h6.js index 3eac29ff..c058aae5 100644 --- a/dist/parser/elements/h6.js +++ b/dist/parser/elements/h6.js @@ -35,8 +35,8 @@ var H6 = function (_BaseElement) { return { display: 'block', color: 'black', - font_weight: 'bold', - font_size: '.67em' + fontWeight: 'bold', + fontSize: '.67em' }; } }, { diff --git a/dist/parser/elements/p.js b/dist/parser/elements/p.js index 0a75d1be..94d61c2a 100644 --- a/dist/parser/elements/p.js +++ b/dist/parser/elements/p.js @@ -35,7 +35,7 @@ var P = function (_BaseElement) { return { display: 'block', color: 'black', - margin_left: '8px' + marginLeft: '8px' }; } }, { diff --git a/dist/parser/elements/text.js b/dist/parser/elements/text.js index f89391b1..a2865717 100644 --- a/dist/parser/elements/text.js +++ b/dist/parser/elements/text.js @@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _BaseElement2 = require('./BaseElement'); @@ -28,14 +30,57 @@ var Text = function (_BaseElement) { } _createClass(Text, [{ + key: 'getOffset', + value: function getOffset(property) { + var node = this.node; + + + if (property) { + var marginRegex = /\d+/g; + var marginMatch = property.match(marginRegex).map(function (m) { + return parseInt(m); + }); + + switch (marginMatch.length) { + case 2: + return { top: marginMatch[0], bottom: marginMatch[0], left: marginMatch[1], right: marginMatch[1] }; + case 4: + return { top: marginMatch[0], bottom: marginMatch[2], left: marginMatch[3], right: marginMatch[1] }; + default: + return { top: marginMatch[0], bottom: marginMatch[0], left: marginMatch[0], right: marginMatch[0] }; + } + } + + return { top: 0, bottom: 0, left: 0, right: 0 }; + } + }, { + key: 'getFontSize', + value: function getFontSize() { + var node = this.node; + + + if (node.style.fontSize) { + var regex = /^(\d+(?:\.\d+)?)(.*)$/; + var fontSizeMatch = node.style.fontSize.match(regex); + + return parseInt(fontSizeMatch[1]); + } + + return 0; + } + }, { key: 'render', value: function render() { var node = this.node; + var margin = this.getOffset(node.style.margin); + var padding = this.getOffset(node.style.padding); + var lineHeight = margin.top + margin.bottom + padding.top + padding.bottom + this.getFontSize(); + return { markup: '%c' + node.markup, - style: node.style + style: _extends({}, node.style, { lineHeight: lineHeight + 'px' }) }; } }]); diff --git a/package.json b/package.json index a7533dbb..8eb9468a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-log", - "version": "1.2.1", + "version": "1.3.0", "description": "React for the Console", "main": "dist/index.js", "files": [