Skip to content

Instantly share code, notes, and snippets.

@catrope
Created September 28, 2011 22:06
Show Gist options
  • Save catrope/1249390 to your computer and use it in GitHub Desktop.
Save catrope/1249390 to your computer and use it in GitHub Desktop.
es.DocumentModel.newFromPlainObject
/* Output (copypaste to Firebug to view):
{"data":[{"type":"document","node":null},{"type":"heading","attributes":{"level":1},"node":null},"T","h","i","s"," ","i","s"," ","a"," ",["h",{"type":"italic"}],["e",{"type":"italic"}],["a",{"type":"italic"}],["d",{"type":"italic"}],["i",{"type":"italic"}],["n",{"type":"italic"}],["g",{"type":"italic"}]," ","(","l","e","v","e","l"," ","1",")",{"type":"/heading","node":null},{"type":"heading","attributes":{"level":2},"node":null},"T","h","i","s"," ","i","s"," ","a"," ",["h",{"type":"italic"}],["e",{"type":"italic"}],["a",{"type":"italic"}],["d",{"type":"italic"}],["i",{"type":"italic"}],["n",{"type":"italic"}],["g",{"type":"italic"}]," ","(","l","e","v","e","l"," ","2",")",{"type":"/heading","node":null},{"type":"heading","attributes":{"level":3},"node":null},"T","h","i","s"," ","i","s"," ","a"," ",["h",{"type":"italic"}],["e",{"type":"italic"}],["a",{"type":"italic"}],["d",{"type":"italic"}],["i",{"type":"italic"}],["n",{"type":"italic"}],["g",{"type":"italic"}]," ","(","l","e","v","e","l"," ","3",")",{"type":"/heading","node":null},{"type":"heading","attributes":{"level":4},"node":null},"T","h","i","s"," ","i","s"," ","a"," ",["h",{"type":"italic"}],["e",{"type":"italic"}],["a",{"type":"italic"}],["d",{"type":"italic"}],["i",{"type":"italic"}],["n",{"type":"italic"}],["g",{"type":"italic"}]," ","(","l","e","v","e","l"," ","4",")",{"type":"/heading","node":null},{"type":"heading","attributes":{"level":5},"node":null},"T","h","i","s"," ","i","s"," ","a"," ",["h",{"type":"italic"}],["e",{"type":"italic"}],["a",{"type":"italic"}],["d",{"type":"italic"}],["i",{"type":"italic"}],["n",{"type":"italic"}],["g",{"type":"italic"}]," ","(","l","e","v","e","l"," ","5",")",{"type":"/heading","node":null},{"type":"heading","attributes":{"level":6},"node":null},"T","h","i","s"," ","i","s"," ","a"," ",["h",{"type":"italic"}],["e",{"type":"italic"}],["a",{"type":"italic"}],["d",{"type":"italic"}],["i",{"type":"italic"}],["n",{"type":"italic"}],["g",{"type":"italic"}]," ","(","l","e","v","e","l"," ","6",")",{"type":"/heading","node":null},{"type":"paragraph","node":null},["I",{"type":"bold"}],["n",{"type":"bold"}],[" ",{"type":"bold"}],["t",{"type":"bold"}],["e",{"type":"bold"}],["x",{"type":"bold"}],["t",{"type":"bold"}],[" ",{"type":"bold"}],["d",{"type":"bold"}],["i",{"type":"bold"}],["s",{"type":"bold"}],["p",{"type":"bold"}],["l",{"type":"bold"}],["a",{"type":"bold"}],["y",{"type":"bold"}],","," ",["l",{"type":"italic"}],["i",{"type":"italic"}],["n",{"type":"italic"}],["e",{"type":"italic"}],[" ",{"type":"italic"}],["w",{"type":"italic"},{"type":"xlink","data":{"href":"#"}}],["r",{"type":"italic"},{"type":"xlink","data":{"href":"#"}}],["a",{"type":"italic"},{"type":"xlink","data":{"href":"#"}}],["p",{"type":"italic"},{"type":"xlink","data":{"href":"#"}}],[" ",{"type":"xlink","data":{"href":"#"}}],["i",{"type":"xlink","data":{"href":"#"}}],["s",{"type":"xlink","data":{"href":"#"}}]," ","t","h","e"," ","f","e","a","t","u","r","e"," ","o","f"," ","c","o","n","t","i","n","u","i","n","g"," ","o","n"," ","a"," ","n","e","w"," ","l","i","n","e"," ","w","h","e","n"," ","a"," ","l","i","n","e"," ","i","s"," ","f","u","l","l",","," ","s","u","c","h"," ","t","h","a","t"," ","e","a","c","h"," ","l","i","n","e"," ","f","i","t","s"," ","i","n"," ","t","h","e"," ","v","i","e","w","a","b","l","e"," ","w","i","n","d","o","w",","," ","a","l","l","o","w","i","n","g"," ","t","e","x","t"," ","t","o"," ","b","e"," ","r","e","a","d"," ","f","r","o","m"," ","t","o","p"," ","t","o"," ","b","o","t","t","o","m"," ","w","i","t","h","o","u","t"," ","a","n","y"," ","h","o","r","i","z","o","n","t","a","l"," ","s","c","r","o","l","l","i","n","g",".","\n","W","o","r","d"," ","w","r","a","p"," ","i","s"," ","t","h","e"," ","a","d","d","i","t","i","o","n","a","l"," ","f","e","a","t","u","r","e"," ","o","f"," ","m","o","s","t"," ","t","e","x","t"," ","e","d","i","t","o","r","s",","," ","w","o","r","d"," ","p","r","o","c","e","s","s","o","r","s",","," ","a","n","d"," ","w","e","b"," ","b","r","o","w","s","e","r","s",","," ","o","f"," ","b","r","e","a","k","i","n","g"," ","l","i","n","e","s"," ","b","e","t","w","e","e","n"," ","a","n","d"," ","n","o","t"," ","w","i","t","h","i","n"," ","w","o","r","d","s",","," ","e","x","c","e","p","t"," ","w","h","e","n"," ","a"," ","s","i","n","g","l","e"," ","w","o","r","d"," ","i","s"," ","l","o","n","g","e","r"," ","t","h","a","n"," ","a"," ","l","i","n","e",".",{"type":"/paragraph","node":null},{"type":"paragraph","node":null},"I","t"," ","i","s"," ","u","s","u","a","l","l","y"," ","d","o","n","e"," ","o","n"," ","t","h","e"," ","f","l","y"," ","w","h","e","n"," ","v","i","e","w","i","n","g"," ","o","r"," ","p","r","i","n","t","i","n","g"," ","a"," ","d","o","c","u","m","e","n","t",","," ","s","o"," ","n","o"," ","l","i","n","e"," ","b","r","e","a","k"," ","c","o","d","e"," ","i","s"," ","m","a","n","u","a","l","l","y"," ","e","n","t","e","r","e","d",","," ","o","r"," ","s","t","o","r","e","d",".",[" ",{"type":"template","data":{"html":"<sup><small><a href=\"#\">[citation needed]</a></small></sup>"}}]," ","I","f"," ","t","h","e"," ","u","s","e","r"," ","c","h","a","n","g","e","s"," ","t","h","e"," ","m","a","r","g","i","n","s",","," ","t","h","e"," ","e","d","i","t","o","r"," ","w","i","l","l"," ","e","i","t","h","e","r"," ","a","u","t","o","m","a","t","i","c","a","l","l","y"," ","r","e","p","o","s","i","t","i","o","n"," ","t","h","e"," ","l","i","n","e"," ","b","r","e","a","k","s"," ","t","o"," ","e","n","s","u","r","e"," ","t","h","a","t"," ","a","l","l"," ","t","h","e"," ","t","e","x","t"," ","w","i","l","l"," ","\"","f","l","o","w","\""," ","w","i","t","h","i","n"," ","t","h","e"," ","m","a","r","g","i","n","s"," ","a","n","d"," ","r","e","m","a","i","n"," ","v","i","s","i","b","l","e",","," ","o","r"," ","p","r","o","v","i","d","e"," ","t","h","e"," ","t","y","p","i","s","t"," ","s","o","m","e"," ","c","o","n","v","e","n","i","e","n","t"," ","w","a","y"," ","t","o"," ","r","e","p","o","s","i","t","i","o","n"," ","t","h","e"," ","l","i","n","e"," ","b","r","e","a","k","s",".","\n","A"," ","s","o","f","t"," ","r","e","t","u","r","n"," ","i","s"," ","t","h","e"," ","b","r","e","a","k"," ","r","e","s","u","l","t","i","n","g"," ","f","r","o","m"," ","l","i","n","e"," ","w","r","a","p"," ","o","r"," ","w","o","r","d"," ","w","r","a","p",","," ","w","h","e","r","e","a","s"," ","a"," ","h","a","r","d"," ","r","e","t","u","r","n"," ","i","s"," ","a","n"," ","i","n","t","e","n","t","i","o","n","a","l"," ","b","r","e","a","k",","," ","c","r","e","a","t","i","n","g"," ","a"," ","n","e","w"," ","p","a","r","a","g","r","a","p","h",".",{"type":"/paragraph","node":null},{"type":"paragraph","node":null},"T","h","e"," ","s","o","f","t"," ","r","e","t","u","r","n","s"," ","a","r","e"," ","u","s","u","a","l","l","y"," ","p","l","a","c","e","d"," ","a","f","t","e","r"," ","t","h","e"," ","e","n","d","s"," ","o","f"," ","c","o","m","p","l","e","t","e"," ","w","o","r","d","s",","," ","o","r"," ","a","f","t","e","r"," ","t","h","e"," ","p","u","n","c","t","u","a","t","i","o","n"," ","t","h","a","t"," ","f","o","l","l","o","w","s"," ","c","o","m","p","l","e","t","e"," ","w","o","r","d","s","."," ","H","o","w","e","v","e","r",","," ","w","o","r","d"," ","w","r","a","p"," ","m","a","y"," ","a","l","s","o"," ","o","c","c","u","r"," ","f","o","l","l","o","w","i","n","g"," ","a"," ","h","y","p","h","e","n",".","\n","W","o","r","d"," ","w","r","a","p"," ","f","o","l","l","o","w","i","n","g"," ","h","y","p","h","e","n","s"," ","i","s"," ","s","o","m","e","t","i","m","e","s"," ","n","o","t"," ","d","e","s","i","r","e","d",","," ","a","n","d"," ","c","a","n"," ","b","e"," ","a","v","o","i","d","e","d"," ","b","y"," ","u","s","i","n","g"," ","a"," ","s","o","-","c","a","l","l","e","d"," ","n","o","n","-","b","r","e","a","k","i","n","g"," ","h","y","p","h","e","n"," ","i","n","s","t","e","a","d"," ","o","f"," ","a"," ","r","e","g","u","l","a","r"," ","h","y","p","h","e","n","."," ","O","n"," ","t","h","e"," ","o","t","h","e","r"," ","h","a","n","d",","," ","w","h","e","n"," ","u","s","i","n","g"," ","w","o","r","d"," ","p","r","o","c","e","s","s","o","r","s",","," ","i","n","v","i","s","i","b","l","e"," ","h","y","p","h","e","n","s",","," ","c","a","l","l","e","d"," ","s","o","f","t"," ","h","y","p","h","e","n","s",","," ","c","a","n"," ","a","l","s","o"," ","b","e"," ","i","n","s","e","r","t","e","d"," ","i","n","s","i","d","e"," ","w","o","r","d","s"," ","s","o"," ","t","h","a","t"," ","w","o","r","d"," ","w","r","a","p"," ","c","a","n"," ","o","c","c","u","r"," ","f","o","l","l","o","w","i","n","g"," ","t","h","e"," ","s","o","f","t"," ","h","y","p","h","e","n","s",".","\n","S","o","m","e","t","i","m","e","s",","," ","w","o","r","d"," ","w","r","a","p"," ","i","s"," ","n","o","t"," ","d","e","s","i","r","a","b","l","e"," ","b","e","t","w","e","e","n"," ","w","o","r","d","s","."," ","I","n"," ","s","u","c","h"," ","c","a","s","e","s",","," ","w","o","r","d"," ","w","r","a","p"," ","c","a","n"," ","u","s","u","a","l","l","y"," ","b","e"," ","a","v","o","i","d","e","d"," ","b","y"," ","u","s","i","n","g"," ","a"," ","h","a","r","d"," ","s","p","a","c","e"," ","o","r"," ","n","o","n","-","b","r","e","a","k","i","n","g"," ","s","p","a","c","e"," ","b","e","t","w","e","e","n"," ","t","h","e"," ","w","o","r","d","s",","," ","i","n","s","t","e","a","d"," ","o","f"," ","r","e","g","u","l","a","r"," ","s","p","a","c","e","s",".","\n","O","c","c","a","s","i","o","n","a","l","l","y","T","h","e","r","e","A","r","e","W","o","r","d","s","T","h","a","t","A","r","e","S","o","L","o","n","g","T","h","e","y","E","x","c","e","e","d","T","h","e","W","i","d","t","h","O","f","T","h","e","L","i","n","e","A","n","d","E","n","d","U","p","W","r","a","p","p","i","n","g","B","e","t","w","e","e","n","M","u","l","t","i","p","l","e","L","i","n","e","s",".","\n","T","e","x","t"," ","m","i","g","h","t"," ","h","a","v","e","\t","t","a","b","s","\t","i","n"," ","i","t"," ","t","o","o","."," ","N","o","t"," ","a","l","l"," ","t","e","x","t"," ","w","i","l","l"," ","e","n","d"," ","i","n"," ","a"," ","l","i","n","e"," ","b","r","e","a","k","i","n","g"," ","c","h","a","r","a","c","t","e","r",{"type":"/paragraph","node":null},{"type":"table","attributes":{"html/style":"width: 600px; border: solid 1px;"},"node":null},{"type":"tableRow","node":null},{"type":"tableCell","attributes":{"style":"border: solid 1px;"},"node":null},{"type":"paragraph","node":null},"r","o","w"," ","1"," ","&"," ","c","e","l","l"," ","1",{"type":"/paragraph","node":null},{"type":"/tableCell","node":null},{"type":"tableCell","attributes":{"style":"border: solid 1px;"},"node":null},{"type":"paragraph","node":null},"r","o","w"," ","1"," ","&"," ","c","e","l","l"," ","2",{"type":"/paragraph","node":null},{"type":"/tableCell","node":null},{"type":"/tableRow","node":null},{"type":"tableRow","node":null},{"type":"tableCell","attributes":{"style":"border: solid 1px;"},"node":null},{"type":"paragraph","node":null},"r","o","w"," ","2"," ","&"," ","c","e","l","l"," ","1",{"type":"/paragraph","node":null},{"type":"/tableCell","node":null},{"type":"tableCell","attributes":{"style":"border: solid 1px;"},"node":null},{"type":"paragraph","node":null},"r","o","w"," ","2"," ","&"," ","c","e","l","l"," ","2",{"type":"/paragraph","node":null},{"type":"table","attributes":{"style":"width: 150px; border: solid 1px;"},"node":null},{"type":"tableRow","node":null},{"type":"tableCell","attributes":{"style":"border: solid 1px;"},"node":null},{"type":"paragraph","node":null},"#","1"," ","#","1"," ","#","1",{"type":"/paragraph","node":null},{"type":"/tableCell","node":null},{"type":"tableCell","attributes":{"style":"border: solid 1px;"},"node":null},{"type":"paragraph","node":null},"#","2"," ","#","2"," ","#","2",{"type":"/paragraph","node":null},{"type":"/tableCell","node":null},{"type":"/tableRow","node":null},{"type":"tableRow","node":null},{"type":"tableCell","attributes":{"style":"border: solid 1px;"},"node":null},{"type":"paragraph","node":null},"#","3"," ","#","3"," ","#","3",{"type":"/paragraph","node":null},{"type":"/tableCell","node":null},{"type":"tableCell","attributes":{"style":"border: solid 1px;"},"node":null},{"type":"paragraph","node":null},"#","4"," ","#","4"," ","#","4",{"type":"/paragraph","node":null},{"type":"/tableCell","node":null},{"type":"/tableRow","node":null},{"type":"/table","node":null},{"type":"list","attributes":{"style":"number"},"node":null},{"type":"listItem","node":null},"F","i","r","s","t"," ","i","t","e","m",{"type":"/listItem","node":null},{"type":"listItem","node":null},["S",{"type":"italic"}],["e",{"type":"italic"}],["c",{"type":"italic"}],["o",{"type":"italic"}],["n",{"type":"italic"}],["d",{"type":"italic"}]," ","i","t","e","m",{"type":"/listItem","node":null},{"type":"listItem","node":null},["T",{"type":"bold"}],["h",{"type":"bold"}],["i",{"type":"bold"}],["r",{"type":"bold"}],["d",{"type":"bold"}]," ","i","t","e","m",{"type":"/listItem","node":null},{"type":"listItem","node":null},"F","o","u","r","t","h"," ",["i",{"type":"ilink","data":{"title":"User:JohnDoe"}}],["t",{"type":"ilink","data":{"title":"User:JohnDoe"}}],["e",{"type":"ilink","data":{"title":"User:JohnDoe"}}],["m",{"type":"ilink","data":{"title":"User:JohnDoe"}}],{"type":"/listItem","node":null},{"type":"/list","node":null},{"type":"/tableCell","node":null},{"type":"/tableRow","node":null},{"type":"/table","node":null},{"type":"list","attributes":{"style":"number"},"node":null},{"type":"listItem","node":null},"O","p","e","r","a","t","i","n","g"," ","S","y","s","t","e","m","s",{"type":"/listItem","node":null},{"type":"listItem","node":null},["S",{"type":"italic"}],["e",{"type":"italic"}],["c",{"type":"italic"}],["o",{"type":"italic"}],["n",{"type":"italic"}],["d",{"type":"italic"}]," ","i","t","e","m",{"type":"/listItem","node":null},{"type":"listItem","node":null},["T",{"type":"bold"}],["h",{"type":"bold"}],["i",{"type":"bold"}],["r",{"type":"bold"}],["d",{"type":"bold"}]," ","i","t","e","m",{"type":"/listItem","node":null},{"type":"listItem","node":null},"F","o","u","r","t","h"," ",["i",{"type":"ilink","data":{"title":"User:JohnDoe"}}],["t",{"type":"ilink","data":{"title":"User:JohnDoe"}}],["e",{"type":"ilink","data":{"title":"User:JohnDoe"}}],["m",{"type":"ilink","data":{"title":"User:JohnDoe"}}],{"type":"/listItem","node":null},{"type":"/list","node":null},{"type":"/document","node":null}]}
*/
// To test, run flatModel = es.DocumentModel.newFromPlainText( wikiDOM );
es = {};
es.DocumentModel = function( data ) { this.data = data; }
es.DocumentModel.newFromPlainObject = function( obj ) {
/*
* Flatten a node and its children into a data array, recursively.
*
* @param obj {Object} A plain node object //TODO where do we document this whole structure?
* @return {Array} Array to append the flattened version of obj to
*/
function flattenNode( obj ) {
var i, data = [];
// Open element
// TODO do we need to copy the attributes object or can we use a reference?
data.push( { 'type': obj.type, 'attributes': obj.attributes, 'node': null } );
if ( obj.content !== undefined ) {
// Add content
data = data.concat( es.ContentModel.newFromPlainObject( obj.content ).data );
} else {
// Add children. Only do this if there is no content property
for ( i = 0; i < obj.children.length; i++ ) {
//TODO figure out if all this concatting is inefficent. I think it is
data = data.concat( flattenNode( obj.children[i] ) );
}
}
// Close element // TODO do we need attributes here or not?
data.push( { 'type': '/' + obj.type, 'node': null } );
return data;
}
return new es.DocumentModel( flattenNode( obj ) );
};
// Support stuff
es.ContentModel = function( data ) { this.data = data; }
es.ContentModel.newFromPlainObject = function( obj ) {
var data,
attributes;
if ( !$.isPlainObject( obj ) ) {
// Use empty content
data = [];
} else {
// Convert string to array of characters
data = obj.text.split('');
// Render annotations
if ( $.isArray( obj.annotations ) ) {
$.each( obj.annotations, function( i, src ) {
// Build simplified annotation object
var dst = { 'type': src.type };
if ( 'data' in src ) {
dst.data = es.copyObject( src.data );
}
// Apply annotation to range
if ( src.range.start < 0 ) {
// TODO: This is invalid data! Throw error?
src.range.start = 0;
}
if ( src.range.end > data.length ) {
// TODO: This is invalid data! Throw error?
src.range.end = data.length;
}
for ( var i = src.range.start; i < src.range.end; i++ ) {
// Auto-convert to array
typeof data[i] === 'string' && ( data[i] = [data[i]] );
// Append
data[i].push( dst );
}
} );
}
}
return new es.ContentModel( data );
};
es.copyObject = function( source ) {
var destination = {};
var key;
for ( key in source ) {
sourceValue = source[key];
sourceType = typeof sourceValue;
if ( sourceType === 'string' || sourceType === 'number' ) {
destination[key] = sourceValue;
} else if ( $.isPlainObject( sourceValue ) ) {
destination[key] = es.copyObject( sourceValue );
}
}
return destination;
};
// Test data
wikiDOM = {
'type': 'document',
'children': [
{
'type': 'heading',
'attributes': { 'level': 1 },
'content': {
'text': 'This is a heading (level 1)',
'annotations': [
{
'type': 'italic',
'range': {
'start': 10,
'end': 17
}
}
]
}
},
{
'type': 'heading',
'attributes': { 'level': 2 },
'content': {
'text': 'This is a heading (level 2)',
'annotations': [
{
'type': 'italic',
'range': {
'start': 10,
'end': 17
}
}
]
}
},
{
'type': 'heading',
'attributes': { 'level': 3 },
'content': {
'text': 'This is a heading (level 3)',
'annotations': [
{
'type': 'italic',
'range': {
'start': 10,
'end': 17
}
}
]
}
},
{
'type': 'heading',
'attributes': { 'level': 4 },
'content': {
'text': 'This is a heading (level 4)',
'annotations': [
{
'type': 'italic',
'range': {
'start': 10,
'end': 17
}
}
]
}
},
{
'type': 'heading',
'attributes': { 'level': 5 },
'content': {
'text': 'This is a heading (level 5)',
'annotations': [
{
'type': 'italic',
'range': {
'start': 10,
'end': 17
}
}
]
}
},
{
'type': 'heading',
'attributes': { 'level': 6 },
'content': {
'text': 'This is a heading (level 6)',
'annotations': [
{
'type': 'italic',
'range': {
'start': 10,
'end': 17
}
}
]
}
},
{
'type': 'paragraph',
'content': {
'text': 'In text display, line wrap is the feature of continuing on a new line when a line is full, such that each line fits in the viewable window, allowing text to be read from top to bottom without any horizontal scrolling.\nWord wrap is the additional feature of most text editors, word processors, and web browsers, of breaking lines between and not within words, except when a single word is longer than a line.',
'annotations': [
// 'In text display' should be bold
{ 'type': 'bold', 'range': { 'start': 0, 'end': 15 } },
// 'line wrap' should be italic
{ 'type': 'italic', 'range': { 'start': 17, 'end': 26 } },
// 'wrap is' should be a link to '#'
{
'type': 'xlink',
'data': { 'href': '#' },
'range': { 'start': 22, 'end': 29 }
},
]
}
},
{
'type': 'paragraph',
'content': {
'text': 'It is usually done on the fly when viewing or printing a document, so no line break code is manually entered, or stored. If the user changes the margins, the editor will either automatically reposition the line breaks to ensure that all the text will "flow" within the margins and remain visible, or provide the typist some convenient way to reposition the line breaks.\nA soft return is the break resulting from line wrap or word wrap, whereas a hard return is an intentional break, creating a new paragraph.',
'annotations': [
// '[citation needed]' should be super
{
'type': 'template',
'data': {
'html': '<sup><small><a href="#">[citation needed]</a></small></sup>'
},
'range': { 'start': 120, 'end': 121 }
}
]
}
},
{
'type': 'paragraph',
'content': { 'text': 'The soft returns are usually placed after the ends of complete words, or after the punctuation that follows complete words. However, word wrap may also occur following a hyphen.\nWord wrap following hyphens is sometimes not desired, and can be avoided by using a so-called non-breaking hyphen instead of a regular hyphen. On the other hand, when using word processors, invisible hyphens, called soft hyphens, can also be inserted inside words so that word wrap can occur following the soft hyphens.\nSometimes, word wrap is not desirable between words. In such cases, word wrap can usually be avoided by using a hard space or non-breaking space between the words, instead of regular spaces.\nOccasionallyThereAreWordsThatAreSoLongTheyExceedTheWidthOfTheLineAndEndUpWrappingBetweenMultipleLines.\nText might have\ttabs\tin it too. Not all text will end in a line breaking character' }
},
{
'type': 'table',
'attributes': { 'html/style': 'width: 600px; border: solid 1px;' },
'children': [
{
'type': 'tableRow',
'children': [
{
'type': 'tableCell',
'attributes': { 'style': 'border: solid 1px;' },
'children': [
{
'type': 'paragraph',
'content': { 'text': 'row 1 & cell 1' }
}
]
},
{
'type': 'tableCell',
'attributes': { 'style': 'border: solid 1px;' },
'children': [
{
'type': 'paragraph',
'content': { 'text': 'row 1 & cell 2' }
}
]
}
]
},
{
'type': 'tableRow',
'children': [
{
'type': 'tableCell',
'attributes': { 'style': 'border: solid 1px;' },
'children': [
{
'type': 'paragraph',
'content': { 'text': 'row 2 & cell 1' }
}
]
},
{
'type': 'tableCell',
'attributes': { 'style': 'border: solid 1px;' },
'children': [
{
'type': 'paragraph',
'content': { 'text': 'row 2 & cell 2' }
},
{
'type': 'table',
'attributes': { 'style': 'width: 150px; border: solid 1px;' },
'children': [
{
'type': 'tableRow',
'children': [
{
'type': 'tableCell',
'attributes': { 'style': 'border: solid 1px;' },
'children': [
{
'type': 'paragraph',
'content': { 'text': '#1 #1 #1' }
}
]
},
{
'type': 'tableCell',
'attributes': { 'style': 'border: solid 1px;' },
'children': [
{
'type': 'paragraph',
'content': { 'text': '#2 #2 #2' }
}
]
}
]
},
{
'type': 'tableRow',
'children': [
{
'type': 'tableCell',
'attributes': { 'style': 'border: solid 1px;' },
'children': [
{
'type': 'paragraph',
'content': { 'text': '#3 #3 #3' }
}
]
},
{
'type': 'tableCell',
'attributes': { 'style': 'border: solid 1px;' },
'children': [
{
'type': 'paragraph',
'content': { 'text': '#4 #4 #4' }
}
]
}
]
}
]
},
{
'type': 'list',
'attributes': { 'style': 'number' },
'children': [
{
'type': 'listItem',
'content': { 'text': 'First item' },
'children': [ // WTF?!?
{
'style': 'bullet',
'items': [
{ 'content': { 'text': 'First subitem' } },
{ 'content': { 'text': 'Second subitem' } }
]
}
]
},
{
'type': 'listItem',
'content': {
'text': 'Second item',
'annotations': [
{
'type': 'italic',
'range': {
'start': 0,
'end': 6
}
}
]
}
},
{
'type': 'listItem',
'content': {
'text': 'Third item',
'annotations': [
{
'type': 'bold',
'range': {
'start': 0,
'end': 5
}
}
]
}
},
{
'type': 'listItem',
'content': {
'text': 'Fourth item',
'annotations': [
{
'type': 'ilink',
'range': {
'start': 7,
'end': 11
},
'data': { 'title': 'User:JohnDoe' }
}
]
}
}
]
}
]
}
]
}
]
},
{
'type': 'list',
'attributes': { 'style': 'number' },
'children': [
{
'type': 'listItem',
'content': { 'text': 'Operating Systems' },
'children': [ // WTF?!?
{
'attributes': { 'style': 'bullet' },
'children': [
{
'type': 'listItem',
'content': { 'text': 'Linux' },
'children': [ // WTF?!?
{
'attributes': { 'style': 'bullet' },
'children': [
{
'type': 'listItem',
'content': { 'text': 'Ubuntu' },
'children': [ //WTF?!?
{
'attributes': { 'style': 'bullet' },
'children': [
{
'type': 'listItem',
'content': {
'text': 'Desktop: Intuitive office apps, safe and fast web browsing, and seamless integration. Ubuntu brings the very best technologies straight to the desktop.',
'annotations': [
// "[citation needed 2]" should be super
{
'type': 'template',
'data': {
'html': '<sup><small><a href="#">[citation needed 2]</a></small></sup>'
},
'range': { 'start': 85, 'end': 86 }
}
]
}
},
{ 'type': 'listItem', 'content': { 'text': 'Server: Secure, fast and powerful, Ubuntu Server is transforming IT environments worldwide. Realise the full potential of your infrastructure with a reliable, easy-to-integrate technology platform. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. Lorem ipsum.. ' } },
{ 'type': 'listItem', 'content': { 'text': 'Cloud: Ubuntu cloud computing puts you in control of your IT infrastructure. It helps you access computing power as and when you need it so you can meet user demand more effectively.' } }
]
}
]
},
{ 'type': 'listItem', 'content': { 'text': 'Fedora' } },
{ 'type': 'listItem', 'content': { 'text': 'Gentoo' } }
]
}
]
},
{ 'type': 'listItem', 'content': { 'text': 'Windows' } },
{ 'type': 'listItem', 'content': { 'text': 'Mac' } }
]
}
]
},
{
'type': 'listItem',
'content': {
'text': 'Second item',
'annotations': [
{
'type': 'italic',
'range': {
'start': 0,
'end': 6
}
}
]
}
},
{
'type': 'listItem',
'content': {
'text': 'Third item',
'annotations': [
{
'type': 'bold',
'range': {
'start': 0,
'end': 5
}
}
]
}
},
{
'type': 'listItem',
'content': {
'text': 'Fourth item',
'annotations': [
{
'type': 'ilink',
'range': {
'start': 7,
'end': 11
},
'data': { 'title': 'User:JohnDoe' }
}
]
}
}
]
}
] };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment