ep_context
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -23,3 +23,5 @@ { | ||
"stylesForExport" : "ep_context/index", | ||
"exportHtmlAdditionalTags" : "ep_context/index" | ||
"exportHtmlAdditionalTags" : "ep_context/index", | ||
"getLineHTMLForExport" : "ep_context/index", | ||
"exportHTMLSend" : "ep_context/index" | ||
} | ||
@@ -26,0 +28,0 @@ } |
59
index.js
var eejs = require('ep_etherpad-lite/node/eejs/'); | ||
var Changeset = require("ep_etherpad-lite/static/js/Changeset"); | ||
var sanitize = require('./sanitizer.js').sanitize; | ||
var stylesCSS = ["contextparagraph{margin-left:10px;color:green;}", | ||
"contextform{text-align:center;display:block;}", | ||
"contextsection > contextheader, contextsection > contextenum{text-align:center;display:block;}", | ||
"contextenum{font-weight:bolder;}", | ||
"contextheader{font-weight:bolder;}", | ||
"contextcongress{font-variant: small-caps;}", | ||
"contextsession{font-variant: small-caps;}", | ||
"contextsubsection{margin-left:15px;color:blue;}", | ||
"contextdistribution-code{text-align:right;display:block;}"] | ||
/******************** | ||
@@ -35,3 +47,7 @@ * UI | ||
exports.stylesForExport = function(hook, padId, cb){ | ||
cb("sub{vertical-align:sub;font-size:smaller}sub{vertical-align:sup;font-size:smaller}"); | ||
var css = ""; | ||
stylesCSS.forEach(function(style){ | ||
css += style; | ||
}); | ||
cb(css); | ||
}; | ||
@@ -43,1 +59,42 @@ | ||
}; | ||
// line, apool,attribLine,text | ||
exports.getLineHTMLForExport = function (hook, line) { | ||
var contextV = _analyzeLine(line.attribLine, line.apool); | ||
if(contextV){ | ||
var contexts = contextV.split("$"); | ||
}else{ | ||
return; | ||
} | ||
var before = ""; | ||
var after = ""; | ||
if (contexts.length) { | ||
contexts.forEach(function(contextV){ | ||
before += "<context" + contextV + ">"; | ||
after += "</context" + contextV + ">"; | ||
}); | ||
console.warn("TODO: Use a line with attributes not just a text string"); | ||
return before + line.text.substring(1) + after + "<br>"; | ||
}else{ | ||
} | ||
} | ||
// clean up HTML into something sane | ||
exports.exportHTMLSend = function(hook, html, cb){ | ||
var blockElements = ["Section", "Paragraph", "Subsection", "Form", "Distribution-code", "Congress", "Session", "Header", "Enum"]; | ||
sanitize.exec(html, blockElements, function(error, cleanedHTML){ | ||
cb(cleanedHTML); | ||
}); | ||
} | ||
function _analyzeLine(alineAttrs, apool) { | ||
var context = null; | ||
if (alineAttrs) { | ||
var opIter = Changeset.opIterator(alineAttrs); | ||
if (opIter.hasNext()) { | ||
var op = opIter.next(); | ||
context = Changeset.opAttributeValue(op, 'context', apool); | ||
} | ||
} | ||
return context; | ||
} |
{ | ||
"description": "Context for Etherpad Documents, very WIP.", | ||
"name": "ep_context", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "John McLear", |
@@ -5,4 +5,14 @@ var _, $, jQuery; | ||
var styles = ["Section", "Paragraph", "Subsection", "Form", "Distribution-code", "Congress", "Session", "Header", "Enum"]; | ||
var stylesCSS = ["contextparagraph{margin-left:10px;color:green;}", | ||
"contextform{text-align:center;display:block;}", | ||
"contextsection > contextheader, contextsection > contextenum{text-align:center;display:block;}", | ||
"contextenum{font-weight:bolder;}", | ||
"contextheader{font-weight:bolder;}", | ||
"contextcongress{font-variant: small-caps;}", | ||
"contextsession{font-variant: small-caps;}", | ||
"contextsubsection{margin-left:15px;color:blue;}", | ||
"contextdistribution-code{text-align:right;display:block;}"] | ||
/***** | ||
@@ -24,12 +34,8 @@ * Basic setup | ||
var inner = $('iframe[name="ace_outer"]').contents().find('iframe[name="ace_inner"]'); | ||
inner.contents().find("head").append("<style>contextparagraph{margin-left:10px;color:green;}</style>"); | ||
inner.contents().find("head").append("<style>contextform{text-align:center;display:block;}</style>"); | ||
inner.contents().find("head").append("<style>contextsection > contextheader, contextsection > contextenum{text-align:center;display:block;}</style>"); | ||
inner.contents().find("head").append("<style>contextenum{font-weight:bolder;}</style>"); | ||
inner.contents().find("head").append("<style>contextheader{font-weight:bolder;}</style>"); | ||
inner.contents().find("head").append("<style>contextcongress{font-variant: small-caps;}</style>"); | ||
inner.contents().find("head").append("<style>contextsession{font-variant: small-caps;}</style>"); | ||
inner.contents().find("head").append("<style>contextsubsection{margin-left:15px;color:blue;}</style>"); | ||
inner.contents().find("head").append("<style>contextdistribution-code{text-align:right;display:block;}</style>"); | ||
var head = inner.contents().find("head"); | ||
$.each(stylesCSS, function(k,css){ | ||
head.append("<style>"+css+"</style>"); | ||
}); | ||
// Selection event | ||
@@ -36,0 +42,0 @@ $('#context-selection').change(function(contextValue){ |
20239
11
542