mobiledoc-kit
Advanced tools
Comparing version 0.11.2 to 0.12.0-0
@@ -1120,2 +1120,20 @@ 'use strict'; | ||
/** | ||
* Sets an attribute for the current active section(s). | ||
* | ||
* @param {String} key The attribute. The only valid attribute is 'text-align'. | ||
* @param {String} value The value of the attribute. | ||
* @public | ||
* @see PostEditor#setAttribute | ||
*/ | ||
}, { | ||
key: 'setAttribute', | ||
value: function setAttribute(key, value) { | ||
var _this7 = this; | ||
this.run(function (postEditor) { | ||
return postEditor.setAttribute(key, value, _this7.range); | ||
}); | ||
} | ||
/** | ||
* Finds and runs the first matching key command for the event | ||
@@ -1231,3 +1249,3 @@ * | ||
value: function insertCard(cardName) { | ||
var _this7 = this; | ||
var _this8 = this; | ||
@@ -1251,3 +1269,3 @@ var cardPayload = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
if (inEditMode) { | ||
_this7.editCard(card); | ||
_this8.editCard(card); | ||
} | ||
@@ -1267,3 +1285,3 @@ | ||
} else { | ||
var collection = _this7.post.sections; | ||
var collection = _this8.post.sections; | ||
postEditor.insertSectionBefore(collection, card, section.next); | ||
@@ -1270,0 +1288,0 @@ } |
@@ -965,2 +965,25 @@ 'use strict'; | ||
}, { | ||
key: 'setAttribute', | ||
value: function setAttribute(key, value, range) { | ||
var _this14 = this; | ||
range = (0, _utilsToRange['default'])(range); | ||
var post = this.editor.post; | ||
var attribute = 'data-md-' + key; | ||
post.walkMarkerableSections(range, function (section) { | ||
if (section.isListItem) { | ||
section = section.parent; | ||
} | ||
if (section.getAttribute(attribute) !== value) { | ||
section.setAttribute(attribute, value); | ||
_this14._markDirty(section); | ||
} | ||
}); | ||
this.setRange(range); | ||
} | ||
}, { | ||
key: '_isSameSectionType', | ||
@@ -1086,3 +1109,3 @@ value: function _isSameSectionType(section, sectionTagName) { | ||
value: function _splitListAtItem(list, item) { | ||
var _this14 = this; | ||
var _this15 = this; | ||
@@ -1108,3 +1131,3 @@ var next = list; | ||
listToAppend.join(i); | ||
_this14.removeSection(i); | ||
_this15.removeSection(i); | ||
}); | ||
@@ -1123,3 +1146,3 @@ var found = !addToPrev; | ||
if (_list.isBlank && isAttached) { | ||
_this14.removeSection(_list); | ||
_this15.removeSection(_list); | ||
} | ||
@@ -1274,6 +1297,6 @@ }); | ||
value: function removeAllSections() { | ||
var _this15 = this; | ||
var _this16 = this; | ||
this.editor.post.sections.toArray().forEach(function (section) { | ||
_this15.removeSection(section); | ||
_this16.removeSection(section); | ||
}); | ||
@@ -1284,7 +1307,7 @@ } | ||
value: function migrateSectionsFromPost(post) { | ||
var _this16 = this; | ||
var _this17 = this; | ||
post.sections.toArray().forEach(function (section) { | ||
post.sections.remove(section); | ||
_this16.insertSectionBefore(_this16.editor.post.sections, section, null); | ||
_this17.insertSectionBefore(_this17.editor.post.sections, section, null); | ||
}); | ||
@@ -1295,3 +1318,3 @@ } | ||
value: function _scheduleListRemovalIfEmpty(listSection) { | ||
var _this17 = this; | ||
var _this18 = this; | ||
@@ -1303,3 +1326,3 @@ this.addCallback(CALLBACK_QUEUES.BEFORE_COMPLETE, function () { | ||
if (isAttached && listSection.isBlank) { | ||
_this17.removeSection(listSection); | ||
_this18.removeSection(listSection); | ||
} | ||
@@ -1306,0 +1329,0 @@ }); |
'use strict'; | ||
var _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'); } }; })(); | ||
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 _get = function get(_x3, _x4, _x5) { var _again = true; _function: while (_again) { var object = _x3, property = _x4, receiver = _x5; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x3 = parent; _x4 = property; _x5 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _get = function get(_x4, _x5, _x6) { var _again = true; _function: while (_again) { var object = _x4, property = _x5, receiver = _x6; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x4 = parent; _x5 = property; _x6 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
@@ -23,2 +25,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _attributable = require('./_attributable'); | ||
var VALID_LIST_SECTION_TAGNAMES = ['ul', 'ol'].map(_utilsDomUtils.normalizeTagName); | ||
@@ -35,6 +39,8 @@ | ||
function ListSection() { | ||
var tagName = arguments.length <= 0 || arguments[0] === undefined ? DEFAULT_TAG_NAME : arguments[0]; | ||
var _this = this; | ||
var tagName = arguments.length <= 0 || arguments[0] === undefined ? DEFAULT_TAG_NAME : arguments[0]; | ||
var items = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var attributes = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
@@ -48,2 +54,11 @@ _classCallCheck(this, ListSection); | ||
(0, _attributable.attributable)(this); | ||
Object.entries(attributes).forEach(function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 2); | ||
var k = _ref2[0]; | ||
var v = _ref2[1]; | ||
return _this.setAttribute(k, v); | ||
}); | ||
this.items = new _utilsLinkedList['default']({ | ||
@@ -50,0 +65,0 @@ adoptItem: function adoptItem(i) { |
'use strict'; | ||
var _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'); } }; })(); | ||
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 _get = function get(_x4, _x5, _x6) { var _again = true; _function: while (_again) { var object = _x4, property = _x5, receiver = _x6; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x4 = parent; _x5 = property; _x6 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _get = function get(_x5, _x6, _x7) { var _again = true; _function: while (_again) { var object = _x5, property = _x6, receiver = _x7; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x5 = parent; _x6 = property; _x7 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
@@ -19,2 +21,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _attributable = require('./_attributable'); | ||
// valid values of `tagName` for a MarkupSection | ||
@@ -37,3 +41,7 @@ var VALID_MARKUP_SECTION_TAGNAMES = ['aside', 'blockquote', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'].map(_utilsDomUtils.normalizeTagName); | ||
var tagName = arguments.length <= 0 || arguments[0] === undefined ? DEFAULT_TAG_NAME : arguments[0]; | ||
var _this = this; | ||
var markers = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var attributes = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
@@ -43,2 +51,12 @@ _classCallCheck(this, MarkupSection); | ||
_get(Object.getPrototypeOf(MarkupSection.prototype), 'constructor', this).call(this, _types.MARKUP_SECTION_TYPE, tagName, markers); | ||
(0, _attributable.attributable)(this); | ||
Object.entries(attributes).forEach(function (_ref) { | ||
var _ref2 = _slicedToArray(_ref, 2); | ||
var k = _ref2[0]; | ||
var v = _ref2[1]; | ||
return _this.setAttribute(k, v); | ||
}); | ||
this.isMarkupSection = true; | ||
@@ -45,0 +63,0 @@ } |
@@ -110,5 +110,6 @@ 'use strict'; | ||
var isGenerated = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; | ||
var attributes = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
tagName = (0, _utilsDomUtils.normalizeTagName)(tagName); | ||
var section = new _modelsMarkupSection['default'](tagName, markers); | ||
var section = new _modelsMarkupSection['default'](tagName, markers, attributes); | ||
if (isGenerated) { | ||
@@ -125,5 +126,6 @@ section.isGenerated = true; | ||
var items = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var attributes = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2]; | ||
tagName = (0, _utilsDomUtils.normalizeTagName)(tagName); | ||
var section = new _modelsListSection['default'](tagName, items); | ||
var section = new _modelsListSection['default'](tagName, items, attributes); | ||
section.builder = this; | ||
@@ -130,0 +132,0 @@ return section; |
@@ -139,3 +139,5 @@ 'use strict'; | ||
value: function appendSection(post, section) { | ||
if (section.isBlank || section.isMarkerable && trim(section.text) === '') { | ||
if (section.isBlank || section.isMarkerable && trim(section.text) === "" && !(0, _utilsArrayUtils.any)(section.markers, function (marker) { | ||
return marker.isAtom; | ||
})) { | ||
return; | ||
@@ -142,0 +144,0 @@ } |
@@ -9,2 +9,4 @@ 'use strict'; | ||
var _4 = require('./0-3-2'); | ||
var _renderersMobiledoc02 = require('../../renderers/mobiledoc/0-2'); | ||
@@ -16,2 +18,4 @@ | ||
var _renderersMobiledoc032 = require('../../renderers/mobiledoc/0-3-2'); | ||
var _utilsAssert = require('../../utils/assert'); | ||
@@ -33,2 +37,4 @@ | ||
return new _3['default'](builder).parse(mobiledoc); | ||
case _renderersMobiledoc032.MOBILEDOC_VERSION: | ||
return new _4['default'](builder).parse(mobiledoc); | ||
default: | ||
@@ -35,0 +41,0 @@ (0, _utilsAssert['default'])('Unknown version of mobiledoc parser requested: ' + version, false); |
@@ -93,3 +93,3 @@ 'use strict'; | ||
// parser-plugin-handled elements | ||
if (_this2.state.section.isMarkerable && !_this2.state.text) { | ||
if (_this2.state.section.isMarkerable && !_this2.state.text && !_this2.state.section.text) { | ||
_this2.state.section = null; | ||
@@ -280,3 +280,5 @@ } else { | ||
// avoid creating empty markup sections, especially useful for indented source | ||
if (state.section.isMarkerable && !state.section.text.trim()) { | ||
if (state.section.isMarkerable && !state.section.text.trim() && !(0, _utilsArrayUtils.any)(state.section.markers, function (marker) { | ||
return marker.isAtom; | ||
})) { | ||
state.section = null; | ||
@@ -283,0 +285,0 @@ state.text = ''; |
@@ -95,2 +95,8 @@ 'use strict'; | ||
function setSectionAttributesOnElement(section, element) { | ||
section.eachAttribute(function (key, value) { | ||
element.setAttribute(key, value); | ||
}); | ||
} | ||
function renderMarkupSection(section) { | ||
@@ -105,2 +111,4 @@ var element = undefined; | ||
setSectionAttributesOnElement(section, element); | ||
return element; | ||
@@ -110,3 +118,7 @@ } | ||
function renderListSection(section) { | ||
return document.createElement(section.tagName); | ||
var element = document.createElement(section.tagName); | ||
setSectionAttributesOnElement(section, element); | ||
return element; | ||
} | ||
@@ -113,0 +125,0 @@ |
@@ -9,5 +9,7 @@ 'use strict'; | ||
var _4 = require('./0-3-2'); | ||
var _utilsAssert = require('../../utils/assert'); | ||
var MOBILEDOC_VERSION = _3.MOBILEDOC_VERSION; | ||
var MOBILEDOC_VERSION = _4.MOBILEDOC_VERSION; | ||
@@ -22,6 +24,8 @@ exports.MOBILEDOC_VERSION = MOBILEDOC_VERSION; | ||
return _2['default'].render(post); | ||
case _3.MOBILEDOC_VERSION: | ||
return _3['default'].render(post); | ||
case undefined: | ||
case null: | ||
case _3.MOBILEDOC_VERSION: | ||
return _3['default'].render(post); | ||
case _4.MOBILEDOC_VERSION: | ||
return _4['default'].render(post); | ||
default: | ||
@@ -28,0 +32,0 @@ (0, _utilsAssert['default'])('Unknown version of mobiledoc renderer requested: ' + version, false); |
@@ -161,8 +161,16 @@ 'use strict'; | ||
var headMarker = head.section.markers.detect(firstNotMatchingDetect, head.marker, true); | ||
headMarker = headMarker && headMarker.next || head.marker; | ||
var headMarker = headSection.markers.detect(firstNotMatchingDetect, head.marker, true); | ||
if (!headMarker && detectMarker(headSection.markers.head)) { | ||
headMarker = headSection.markers.head; | ||
} else { | ||
headMarker = headMarker.next || head.marker; | ||
} | ||
var headPosition = new _position['default'](headSection, headSection.offsetOfMarker(headMarker)); | ||
var tailMarker = tail.section.markers.detect(firstNotMatchingDetect, tail.marker); | ||
tailMarker = tailMarker && tailMarker.prev || tail.marker; | ||
if (!tailMarker && detectMarker(headSection.markers.tail)) { | ||
tailMarker = headSection.markers.tail; | ||
} else { | ||
tailMarker = tailMarker.prev || tail.marker; | ||
} | ||
var tailPosition = new _position['default'](tail.section, tail.section.offsetOfMarker(tailMarker) + tailMarker.length); | ||
@@ -169,0 +177,0 @@ |
'use strict'; | ||
exports['default'] = '0.11.2'; | ||
exports['default'] = '0.12.0-0'; |
{ | ||
"name": "mobiledoc-kit", | ||
"version": "0.11.2", | ||
"version": "0.12.0-0", | ||
"description": "A toolkit for building WYSIWYG editors with Mobiledoc", | ||
"repository": "https://github.com/bustle/mobiledoc-kit", | ||
"scripts": { | ||
"start": "./node_modules/.bin/broccoli serve --host 0.0.0.0", | ||
"test:ci": "npm run build:docs && npm run build && ./node_modules/.bin/testem ci -f testem-ci.js", | ||
"test": "npm run build:docs && npm run build && ./node_modules/.bin/testem ci -f testem.js", | ||
"build": "rm -rf dist && ./node_modules/.bin/broccoli build dist", | ||
"build:docs": "./node_modules/.bin/jsdoc -c ./.jsdoc", | ||
"start": "broccoli serve --host 0.0.0.0", | ||
"test:ci": "npm run build:docs && npm run build && testem ci -f testem-ci.js", | ||
"test": "npm run build:docs && npm run build && testem ci -f testem.js", | ||
"build": "rm -rf dist && broccoli build dist", | ||
"build:docs": "jsdoc -c ./.jsdoc", | ||
"build:website": "npm run build && npm run build:docs && ./bin/build-website.sh", | ||
"deploy:website": "./bin/deploy-website.sh", | ||
"update-changelog": "./node_modules/.bin/conventional-changelog -i CHANGELOG.md -r 0 -s", | ||
"update-changelog": "conventional-changelog -i CHANGELOG.md -r 0 -s", | ||
"version": "npm run update-changelog && git add CHANGELOG.md", | ||
@@ -40,4 +40,4 @@ "prepublish": "npm run build" | ||
"dependencies": { | ||
"mobiledoc-dom-renderer": "0.6.5", | ||
"mobiledoc-text-renderer": "0.3.2" | ||
"mobiledoc-dom-renderer": "0.7.0", | ||
"mobiledoc-text-renderer": "0.4.0" | ||
}, | ||
@@ -44,0 +44,0 @@ "devDependencies": { |
@@ -957,2 +957,14 @@ import Tooltip from '../views/tooltip'; | ||
/** | ||
* Sets an attribute for the current active section(s). | ||
* | ||
* @param {String} key The attribute. The only valid attribute is 'text-align'. | ||
* @param {String} value The value of the attribute. | ||
* @public | ||
* @see PostEditor#setAttribute | ||
*/ | ||
setAttribute(key, value) { | ||
this.run(postEditor => postEditor.setAttribute(key, value, this.range)); | ||
} | ||
/** | ||
* Finds and runs the first matching key command for the event | ||
@@ -959,0 +971,0 @@ * |
@@ -815,2 +815,21 @@ import Position from '../utils/cursor/position'; | ||
setAttribute(key, value, range) { | ||
range = toRange(range); | ||
let { post } = this.editor; | ||
let attribute = `data-md-${key}`; | ||
post.walkMarkerableSections(range, section => { | ||
if (section.isListItem) { | ||
section = section.parent; | ||
} | ||
if (section.getAttribute(attribute) !== value) { | ||
section.setAttribute(attribute, value); | ||
this._markDirty(section); | ||
} | ||
}); | ||
this.setRange(range); | ||
} | ||
_isSameSectionType(section, sectionTagName) { | ||
@@ -817,0 +836,0 @@ return section.isListItem ? |
@@ -7,2 +7,3 @@ import LinkedList from '../utils/linked-list'; | ||
import assert from '../utils/assert'; | ||
import { attributable } from './_attributable'; | ||
@@ -16,3 +17,3 @@ export const VALID_LIST_SECTION_TAGNAMES = [ | ||
export default class ListSection extends Section { | ||
constructor(tagName=DEFAULT_TAG_NAME, items=[]) { | ||
constructor(tagName=DEFAULT_TAG_NAME, items=[], attributes={}) { | ||
super(LIST_SECTION_TYPE); | ||
@@ -23,2 +24,5 @@ this.tagName = tagName; | ||
attributable(this); | ||
Object.entries(attributes).forEach(([k,v]) => this.setAttribute(k, v)); | ||
this.items = new LinkedList({ | ||
@@ -25,0 +29,0 @@ adoptItem: i => { |
@@ -5,2 +5,3 @@ import Markerable from './_markerable'; | ||
import { MARKUP_SECTION_TYPE } from './types'; | ||
import { attributable } from './_attributable'; | ||
@@ -37,4 +38,8 @@ // valid values of `tagName` for a MarkupSection | ||
const MarkupSection = class MarkupSection extends Markerable { | ||
constructor(tagName=DEFAULT_TAG_NAME, markers=[]) { | ||
constructor(tagName=DEFAULT_TAG_NAME, markers=[], attributes={}) { | ||
super(MARKUP_SECTION_TYPE, tagName, markers); | ||
attributable(this); | ||
Object.entries(attributes).forEach(([k,v]) => this.setAttribute(k, v)); | ||
this.isMarkupSection = true; | ||
@@ -41,0 +46,0 @@ } |
@@ -81,5 +81,5 @@ import Atom from '../models/atom'; | ||
*/ | ||
createMarkupSection(tagName=DEFAULT_MARKUP_SECTION_TAG_NAME, markers=[], isGenerated=false) { | ||
createMarkupSection(tagName=DEFAULT_MARKUP_SECTION_TAG_NAME, markers=[], isGenerated=false, attributes={}) { | ||
tagName = normalizeTagName(tagName); | ||
const section = new MarkupSection(tagName, markers); | ||
const section = new MarkupSection(tagName, markers, attributes); | ||
if (isGenerated) { | ||
@@ -92,5 +92,5 @@ section.isGenerated = true; | ||
createListSection(tagName=DEFAULT_LIST_SECTION_TAG_NAME, items=[]) { | ||
createListSection(tagName=DEFAULT_LIST_SECTION_TAG_NAME, items=[], attributes={}) { | ||
tagName = normalizeTagName(tagName); | ||
const section = new ListSection(tagName, items); | ||
const section = new ListSection(tagName, items, attributes); | ||
section.builder = this; | ||
@@ -97,0 +97,0 @@ return section; |
@@ -19,2 +19,3 @@ import { | ||
import { | ||
any, | ||
detect, | ||
@@ -132,3 +133,8 @@ forEach | ||
appendSection(post, section) { | ||
if (section.isBlank || (section.isMarkerable && trim(section.text) === '')) { | ||
if ( | ||
section.isBlank || | ||
(section.isMarkerable && | ||
trim(section.text) === "" && | ||
!any(section.markers, marker => marker.isAtom)) | ||
) { | ||
return; | ||
@@ -135,0 +141,0 @@ } |
import MobiledocParser_0_2 from './0-2'; | ||
import MobiledocParser_0_3 from './0-3'; | ||
import MobiledocParser_0_3_1 from './0-3-1'; | ||
import MobiledocParser_0_3_2 from './0-3-2'; | ||
@@ -8,2 +9,3 @@ import { MOBILEDOC_VERSION as MOBILEDOC_VERSION_0_2 } from 'mobiledoc-kit/renderers/mobiledoc/0-2'; | ||
import { MOBILEDOC_VERSION as MOBILEDOC_VERSION_0_3_1 } from 'mobiledoc-kit/renderers/mobiledoc/0-3-1'; | ||
import { MOBILEDOC_VERSION as MOBILEDOC_VERSION_0_3_2 } from 'mobiledoc-kit/renderers/mobiledoc/0-3-2'; | ||
import assert from 'mobiledoc-kit/utils/assert'; | ||
@@ -25,2 +27,4 @@ | ||
return new MobiledocParser_0_3_1(builder).parse(mobiledoc); | ||
case MOBILEDOC_VERSION_0_3_2: | ||
return new MobiledocParser_0_3_2(builder).parse(mobiledoc); | ||
default: | ||
@@ -27,0 +31,0 @@ assert(`Unknown version of mobiledoc parser requested: ${version}`, |
@@ -33,2 +33,3 @@ import { | ||
import { | ||
any, | ||
forEach, | ||
@@ -101,3 +102,3 @@ contains | ||
// parser-plugin-handled elements | ||
if (this.state.section.isMarkerable && !this.state.text) { | ||
if (this.state.section.isMarkerable && !this.state.text && !this.state.section.text) { | ||
this.state.section = null; | ||
@@ -293,3 +294,7 @@ } else { | ||
// avoid creating empty markup sections, especially useful for indented source | ||
if (state.section.isMarkerable && !state.section.text.trim()) { | ||
if ( | ||
state.section.isMarkerable && | ||
!state.section.text.trim() && | ||
!any(state.section.markers, marker => marker.isAtom) | ||
) { | ||
state.section = null; | ||
@@ -296,0 +301,0 @@ state.text = ''; |
@@ -82,2 +82,8 @@ import CardNode from 'mobiledoc-kit/models/card-node'; | ||
function setSectionAttributesOnElement(section, element) { | ||
section.eachAttribute((key, value) => { | ||
element.setAttribute(key, value); | ||
}); | ||
} | ||
function renderMarkupSection(section) { | ||
@@ -92,2 +98,4 @@ let element; | ||
setSectionAttributesOnElement(section, element); | ||
return element; | ||
@@ -97,3 +105,7 @@ } | ||
function renderListSection(section) { | ||
return document.createElement(section.tagName); | ||
let element = document.createElement(section.tagName); | ||
setSectionAttributesOnElement(section, element); | ||
return element; | ||
} | ||
@@ -100,0 +112,0 @@ |
import MobiledocRenderer_0_2, { MOBILEDOC_VERSION as MOBILEDOC_VERSION_0_2 } from './0-2'; | ||
import MobiledocRenderer_0_3, { MOBILEDOC_VERSION as MOBILEDOC_VERSION_0_3 } from './0-3'; | ||
import MobiledocRenderer_0_3_1, { MOBILEDOC_VERSION as MOBILEDOC_VERSION_0_3_1 } from './0-3-1'; | ||
import MobiledocRenderer_0_3_2, { MOBILEDOC_VERSION as MOBILEDOC_VERSION_0_3_2 } from './0-3-2'; | ||
import assert from 'mobiledoc-kit/utils/assert'; | ||
export const MOBILEDOC_VERSION = MOBILEDOC_VERSION_0_3_1; | ||
export const MOBILEDOC_VERSION = MOBILEDOC_VERSION_0_3_2; | ||
@@ -15,6 +16,8 @@ export default { | ||
return MobiledocRenderer_0_3.render(post); | ||
case MOBILEDOC_VERSION_0_3_1: | ||
return MobiledocRenderer_0_3_1.render(post); | ||
case undefined: | ||
case null: | ||
case MOBILEDOC_VERSION_0_3_1: | ||
return MobiledocRenderer_0_3_1.render(post); | ||
case MOBILEDOC_VERSION_0_3_2: | ||
return MobiledocRenderer_0_3_2.render(post); | ||
default: | ||
@@ -21,0 +24,0 @@ assert(`Unknown version of mobiledoc renderer requested: ${version}`, false); |
@@ -144,8 +144,16 @@ import Position from './position'; | ||
let headMarker = head.section.markers.detect(firstNotMatchingDetect, head.marker, true); | ||
headMarker = (headMarker && headMarker.next) || head.marker; | ||
let headMarker = headSection.markers.detect(firstNotMatchingDetect, head.marker, true); | ||
if (!headMarker && detectMarker(headSection.markers.head)) { | ||
headMarker = headSection.markers.head; | ||
} else { | ||
headMarker = headMarker.next || head.marker; | ||
} | ||
let headPosition = new Position(headSection, headSection.offsetOfMarker(headMarker)); | ||
let tailMarker = tail.section.markers.detect(firstNotMatchingDetect, tail.marker); | ||
tailMarker = (tailMarker && tailMarker.prev) || tail.marker; | ||
if (!tailMarker && detectMarker(headSection.markers.tail)) { | ||
tailMarker = headSection.markers.tail; | ||
} else { | ||
tailMarker = tailMarker.prev || tail.marker; | ||
} | ||
let tailPosition = new Position(tail.section, tail.section.offsetOfMarker(tailMarker) + tailMarker.length); | ||
@@ -152,0 +160,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3514016
176
50018
+ Addedmobiledoc-dom-renderer@0.7.0(transitive)
+ Addedmobiledoc-text-renderer@0.4.0(transitive)
- Removedmobiledoc-dom-renderer@0.6.5(transitive)
- Removedmobiledoc-text-renderer@0.3.2(transitive)
Updatedmobiledoc-dom-renderer@0.7.0