added site files
This commit is contained in:
parent
a6f70a6c78
commit
329148c253
253 changed files with 30486 additions and 0 deletions
120
EnlighterJS/Source/Renderer/BlockRenderer.js
Normal file
120
EnlighterJS/Source/Renderer/BlockRenderer.js
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
---
|
||||
description: Renders the generated Tokens into li-elements, grabbed into a outer ul/ol-container.
|
||||
|
||||
license: MIT-style X11
|
||||
|
||||
authors:
|
||||
- Andi Dittrich
|
||||
|
||||
requires:
|
||||
- Core/1.4.5
|
||||
|
||||
provides: [EnlighterJS.Renderer.BlockRenderer]
|
||||
...
|
||||
*/
|
||||
EJS.Renderer.BlockRenderer = new Class({
|
||||
Implements: Options,
|
||||
|
||||
options : {
|
||||
hover : 'hoverEnabled',
|
||||
oddClassname: 'odd',
|
||||
evenClassname: 'even',
|
||||
showLinenumbers: true
|
||||
},
|
||||
|
||||
textFilter: null,
|
||||
|
||||
initialize : function(options, textFilter){
|
||||
this.setOptions(options);
|
||||
this.textFilter = textFilter;
|
||||
},
|
||||
|
||||
/**
|
||||
* Renders the generated Tokens
|
||||
*
|
||||
* @param {Language} language The Language used when parsing.
|
||||
* @param {SpecialLineHighlighter} specialLines Instance to define the lines to highlight
|
||||
* @return {Element} The renderer output
|
||||
*/
|
||||
render : function(language, specialLines, localOptions){
|
||||
// elememt shortcut
|
||||
var _el = EJS.Dom.Element;
|
||||
|
||||
// create new outer container element - use ol tag if lineNumbers are enabled. element attribute settings are priorized
|
||||
var container = null;
|
||||
if (localOptions.lineNumbers != null){
|
||||
container = new _el((localOptions.lineNumbers.toLowerCase() === 'true') ? 'ol' : 'ul');
|
||||
}else{
|
||||
container = new _el(this.options.showLinenumbers ? 'ol' : 'ul');
|
||||
}
|
||||
|
||||
// add "start" attribute ?
|
||||
if ((localOptions.lineNumbers || this.options.showLinenumbers) && localOptions.lineOffset && localOptions.lineOffset.toInt() > 1){
|
||||
container.set('start', localOptions.lineOffset);
|
||||
}
|
||||
|
||||
// line number count
|
||||
var lineCounter = 1;
|
||||
|
||||
var tokens = language.getTokens();
|
||||
|
||||
var odd = ' ' + this.options.oddClassname || '';
|
||||
var even = ' ' + this.options.evenClassname || '';
|
||||
|
||||
// current line element
|
||||
var currentLine = new _el('li', {
|
||||
'class': (specialLines.isSpecialLine(lineCounter) ? 'specialline' : '') + odd
|
||||
});
|
||||
|
||||
// output filter
|
||||
var addFragment = (function(className, text){
|
||||
currentLine.grab(new _el('span', {
|
||||
'class': className,
|
||||
'text': this.textFilter.filterOutput(text)
|
||||
}));
|
||||
}.bind(this));
|
||||
|
||||
// generate output based on ordered list of tokens
|
||||
Array.each(tokens, function(token){
|
||||
// split the token into lines
|
||||
var lines = token.text.split('\n');
|
||||
|
||||
// linebreaks found ?
|
||||
if (lines.length > 1){
|
||||
// just add the first line
|
||||
addFragment(token.alias, lines.shift());
|
||||
|
||||
// generate element for each line
|
||||
Array.each(lines, function(line, lineNumber){
|
||||
// grab old line into output container
|
||||
container.grab(currentLine);
|
||||
|
||||
// new line
|
||||
lineCounter++;
|
||||
|
||||
// create new line, add special line classes; add odd/even classes
|
||||
currentLine = new _el('li', {
|
||||
'class': (specialLines.isSpecialLine(lineCounter) ? 'specialline' : '') + (lineCounter%2==0 ? even: odd)
|
||||
});
|
||||
|
||||
// create new token-element
|
||||
addFragment(token.alias, line);
|
||||
});
|
||||
}else{
|
||||
addFragment(token.alias, token.text);
|
||||
}
|
||||
});
|
||||
|
||||
// grab last line into container
|
||||
container.grab(currentLine);
|
||||
|
||||
// highlight lines ?
|
||||
if (this.options.hover && this.options.hover != "NULL"){
|
||||
// add hover enable class
|
||||
container.addClass(this.options.hover);
|
||||
}
|
||||
|
||||
return container;
|
||||
}
|
||||
});
|
52
EnlighterJS/Source/Renderer/InlineRenderer.js
Normal file
52
EnlighterJS/Source/Renderer/InlineRenderer.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
---
|
||||
description: Compiles an array of tokens into inline elements, grabbed into a outer container.
|
||||
|
||||
license: MIT-style X11
|
||||
|
||||
authors:
|
||||
- Andi Dittrich
|
||||
|
||||
requires:
|
||||
- Core/1.4.5
|
||||
|
||||
provides: [EnlighterJS.Renderer.InlineRenderer]
|
||||
...
|
||||
*/
|
||||
EJS.Renderer.InlineRenderer = new Class({
|
||||
Implements: Options,
|
||||
|
||||
options : {
|
||||
inlineContainerTag : 'span'
|
||||
},
|
||||
|
||||
textFilter: null,
|
||||
|
||||
initialize : function(options, textFilter){
|
||||
this.setOptions(options);
|
||||
this.textFilter = textFilter;
|
||||
},
|
||||
|
||||
/**
|
||||
* Renders the generated Tokens
|
||||
*
|
||||
* @param {Language} language The Language used when parsing.
|
||||
* @param {SpecialLineHighlighter} specialLines Instance to define the lines to highlight
|
||||
* @return {Element} The renderer output
|
||||
*/
|
||||
render : function(language, specialLines, localOptions){
|
||||
// create output container element
|
||||
var container = new EJS.Dom.Element(this.options.inlineContainerTag);
|
||||
|
||||
// generate output based on ordered list of tokens
|
||||
language.getTokens().each(function(token, index){
|
||||
// create new inline element which contains the token - htmlspecialchars get escaped by mootools setText !
|
||||
container.grab(new EJS.Dom.Element('span', {
|
||||
'class': token.alias,
|
||||
'text': this.textFilter.filterOutput(token.text)
|
||||
}));
|
||||
}, this);
|
||||
|
||||
return container;
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue