Propchange: bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/codemirror.js ------------------------------------------------------------------------------ svn:eol-style = native
Added: bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/livesyntaxhighlight.js URL: http://svn.apache.org/viewvc/bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/livesyntaxhighlight.js?rev=1524352&view=auto ============================================================================== --- bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/livesyntaxhighlight.js (added) +++ bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/livesyntaxhighlight.js Wed Sep 18 09:36:49 2013 @@ -0,0 +1,45 @@ +//Defining a class for livesyntaxhighlight related stuff. +livesyntaxhighlight = { + twidth : "", + theight : "", + cmwidth : "", + cmheight : "", + editor : null, + //Initializing function + init : function () { + twidth = $('#text').width(); + theight = $('#text').height(); + editor = CodeMirror.fromTextArea(document.getElementById("text"), { + lineNumbers: true, + matchBrackets: true, + continueComments: "Enter", + extraKeys: {"Ctrl-Q": "toggleComment"} + }); + console.log($('#text').width() + ' '+ $('#text').height()); + livesyntaxhighlight.resizeCodeMirror(); + editor.refresh(); + $(window).resize(livesyntaxhighlight.resizeCodeMirror); + }, + resizeCodeMirror : function (){ + console.log($('#text').width() + ' '+ $('#text').height()); + var spanwidth = $('.span12').width()/2 - 15; + cmwidth = window.twidth; + if ($('.span12').width() > 688 && document.getElementById('sidebyside').checked) + cmwidth = spanwidth; + else cmwidth = 2 * (spanwidth +15); + cmheight = $('#text').height(); + // if(document.getElementById('preview')) + // cmheight = $('#preview').height(); + editor.setSize(cmwidth, cmheight); + editor.refresh(); + } +}; +// Invoked initially to initialize the editor +$(document).ready(function (){ + livesyntaxhighlight.init(); +}); +// To adjust the height of the editor +$("#editrows").change(function(){ + var twidth = livesyntaxhighlight.cmwidth; + editor.setSize(twidth, this.options[this.selectedIndex].value*13); +}); \ No newline at end of file Propchange: bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/livesyntaxhighlight.js ------------------------------------------------------------------------------ svn:eol-style = native Added: bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/wikimarkup.js URL: http://svn.apache.org/viewvc/bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/wikimarkup.js?rev=1524352&view=auto ============================================================================== --- bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/wikimarkup.js (added) +++ bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/wikimarkup.js Wed Sep 18 09:36:49 2013 @@ -0,0 +1,330 @@ +CodeMirror.defineMode('wikimarkup', function(config) { + function inBlock(style, terminator, returnTokenizer) { + return function(stream, state) { + while (!stream.eol()) { + if (stream.match(terminator)) { + state.tokenize = inText; + break; + } + stream.next(); + } + + if (returnTokenizer) state.tokenize = returnTokenizer; + + return style; + }; + } + + function inLine(style) { + return function(stream, state) { + while(!stream.eol()) { + stream.next(); + } + state.tokenize = inText; + return style; + }; + } + + function inText(stream, state) { + function chain(parser) { + state.tokenize = parser; + return parser(stream, state); + } + + var sol = stream.sol(); + var ch = stream.next(); + + //non start of line + switch (ch) { //switch is generally much faster than if, so it is used here + case "{": //plugin + stream.eat("/"); + stream.eatSpace(); + var tagName = ""; + var c; + while ((c = stream.eat(/[^\s\u00a0=\"\'\/?(}]/))) tagName += c; + state.tokenize = inPlugin; + return "tag"; + break; + case '*': //bold or wikicreole or bold italic + if(stream.eat('*')){ + if(stream.eat('/') && stream.eat('/')){ + return chain(inBlock("strong em","//**", inText)); //wikicreole + } + else if(stream.eat("'") && stream.eat("'")){ + return chain(inBlock("strong em","''**", inText)); //bold italic + } + else + return chain(inBlock("strong","**", inText)); + } + break; + case "'": //bold or italics + if (stream.eat("'")) { + if (stream.eat("'")) + return chain(inBlock("strong", "'''", inText));//bold + return chain(inBlock("em", "''", inText)); + } + break; +// case "'": //italics +// if (stream.eat("'")) { +// // Italic text +// return chain(inBlock("em", "''", inText)); +// } +// break; + case "(":// Wiki Link + if (stream.eat("(")) { + return chain(inBlock("variable-2", "))", inText)); + } + break; + case "[":// Weblink + return chain(inBlock("variable-3", "]", inText)); + break; + case "|": //table + if (stream.eat("|")) { + if(stream.eat("=")) + return chain(inBlock("header comment","=||", inText)); + else if(stream.eat("|") ) + return chain(inBlock("comment", "||")); + } + break; + case "~": + if (stream.eat("=")) {//titleBar + return chain(inBlock("header string", "=-", inText)); + } else if (stream.eat("~")) {//deleted + return chain(inBlock("error wm-deleted", "~~", inText)); + } + break; + case "_": //underline + if (stream.match("_")) { + return chain(inBlock("wm-underline", "__", inText)); + } + break; + case ":": + if (stream.eat(":")) { + return chain(inBlock("comment", "::")); + } + break; + case "^": //superscript + return chain(inBlock("wm-superscript", "^")); + break; + case "~": //np + if (stream.match("np~")) { + return chain(inBlock("meta", "~/np~")); + } + break; + case ",": //subscript + if (stream.eat(",")){ + return chain(inBlock("wm-subscript", ",,")); + } + break; + case "=": //headers + if (stream.match("==")){ + return chain(inBlock("wm-header3","===")); + } + else if (stream.match("=")){ + return chain(inBlock("wm-header2","==")); + } + else + return chain(inBlock("wm-header1","=")); + break; + + } + + //start of line types + if (sol) { + switch (ch) { + case "!": //escaping Markup + return chain(inLine("string")); + break; + case "*": //unordered list line item, or <li /> at start of line + case "-": //ordered list line item, or <li /> at start of line + return chain(inLine("wm-listitem bracket")); + break; + } + } + + //stream.eatWhile(/[&{]/); was eating up plugins, turned off to act less like html and more like wikimarkup + return null; + } + + var indentUnit = config.indentUnit; + + // Return variables for tokenizers + var pluginName, type; + function inPlugin(stream, state) { + var ch = stream.next(); + var peek = stream.peek(); + + if (ch == "}") { + state.tokenize = inText; + //type = ch == ")" ? "endPlugin" : "selfclosePlugin"; inPlugin + return "tag"; + } else if (ch == "(" || ch == ")") { + return "bracket"; + } else if (ch == "=") { + type = "equals"; + + if (peek == ">") { + ch = stream.next(); + peek = stream.peek(); + } + + //here we detect values directly after equal character with no quotes + if (!/[\'\"]/.test(peek)) { + state.tokenize = inAttributeNoQuote(); + } + //end detect values + + return "operator"; + } else if (/[\'\"]/.test(ch)) { + state.tokenize = inAttribute(ch); + return state.tokenize(stream, state); + } else { + stream.eatWhile(/[^\s\u00a0=\"\'\/?]/); + return "keyword"; + } + } + + function inAttribute(quote) { + return function(stream, state) { + while (!stream.eol()) { + if (stream.next() == quote) { + state.tokenize = inPlugin; + break; + } + } + return "string"; + }; + } + + function inAttributeNoQuote() { + return function(stream, state) { + while (!stream.eol()) { + var ch = stream.next(); + var peek = stream.peek(); + if (ch == " " || ch == "," || /[ )}]/.test(peek)) { + state.tokenize = inPlugin; + break; + } + } + return "string"; + }; + } + + var curState, setStyle; + function pass() { + for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]); + } + + function cont() { + pass.apply(null, arguments); + return true; + } + + function pushContext(pluginName, startOfLine) { + var noIndent = curState.context && curState.context.noIndent; + curState.context = { + prev: curState.context, + pluginName: pluginName, + indent: curState.indented, + startOfLine: startOfLine, + noIndent: noIndent + }; + } + + function popContext() { + if (curState.context) curState.context = curState.context.prev; + } + + function element(type) { + if (type == "openPlugin") {curState.pluginName = pluginName; return cont(attributes, endplugin(curState.startOfLine));} + else if (type == "closePlugin") { + var err = false; + if (curState.context) { + err = curState.context.pluginName != pluginName; + popContext(); + } else { + err = true; + } + if (err) setStyle = "error"; + return cont(endcloseplugin(err)); + } + else if (type == "string") { + if (!curState.context || curState.context.name != "!cdata") pushContext("!cdata"); + if (curState.tokenize == inText) popContext(); + return cont(); + } + else return cont(); + } + + function endplugin(startOfLine) { + return function(type) { + if ( + type == "selfclosePlugin" || + type == "endPlugin" + ) + return cont(); + if (type == "endPlugin") {pushContext(curState.pluginName, startOfLine); return cont();} + return cont(); + }; + } + + function endcloseplugin(err) { + return function(type) { + if (err) setStyle = "error"; + if (type == "endPlugin") return cont(); + return pass(); + }; + } + + function attributes(type) { + if (type == "keyword") {setStyle = "attribute"; return cont(attributes);} + if (type == "equals") return cont(attvalue, attributes); + return pass(); + } + function attvalue(type) { + if (type == "keyword") {setStyle = "string"; return cont();} + if (type == "string") return cont(attvaluemaybe); + return pass(); + } + function attvaluemaybe(type) { + if (type == "string") return cont(attvaluemaybe); + else return pass(); + } + return { + startState: function() { + return {tokenize: inText, cc: [], indented: 0, startOfLine: true, pluginName: null, context: null}; + }, + token: function(stream, state) { + if (stream.sol()) { + state.startOfLine = true; + state.indented = stream.indentation(); + } + if (stream.eatSpace()) return null; + + setStyle = type = pluginName = null; + var style = state.tokenize(stream, state); + if ((style || type) && style != "comment") { + curState = state; + while (true) { + var comb = state.cc.pop() || element; + if (comb(type || style)) break; + } + } + state.startOfLine = false; + return setStyle || style; + }, + indent: function(state, textAfter) { + var context = state.context; + if (context && context.noIndent) return 0; + if (context && /^{\//.test(textAfter)) + context = context.prev; + while (context && !context.startOfLine) + context = context.prev; + if (context) return context.indent + indentUnit; + else return 0; + }, + electricChars: "/" + }; +}); + +CodeMirror.defineMIME("text/wikimarkup", "wikimarkup"); Propchange: bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/bhlivesyntaxhighlight/htdocs/js/wikimarkup.js ------------------------------------------------------------------------------ svn:eol-style = native Added: bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/setup.py URL: http://svn.apache.org/viewvc/bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/setup.py?rev=1524352&view=auto ============================================================================== --- bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/setup.py (added) +++ bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/setup.py Wed Sep 18 09:36:49 2013 @@ -0,0 +1,19 @@ +"""setup for live syntax highlighting""" +from setuptools import setup, find_packages + +setup( + name = 'BloodhoundLiveSyntaxHighlight', + version = '0.1', + description = "Live Syntax Highlighting support in wiki editors for \ + Apache(TM) Bloodhound.", + author = "Apache Bloodhound", + license = "Apache License v2", + url = "http://bloodhound.apache.org/", + packages = ['bhlivesyntaxhighlight'], + package_data = {'bhlivesyntaxhighlight' : ['htdocs/js/*.js', + 'htdocs/css/*.css','templates/*.html']}, + entry_points = {'trac.plugins': [ + 'bhlivesyntaxhighlight = \ + bhlivesyntaxhighlight.bhlivesyntaxhighlight', + ],}, +) \ No newline at end of file Propchange: bloodhound/branches/livesyntaxhighlighting/bloodhound_livesyntaxhighlighting/setup.py ------------------------------------------------------------------------------ svn:eol-style = native