From fd91bb1f1ec19ad39058cd920e99dcb10009d095 Mon Sep 17 00:00:00 2001 From: Andi Dittrich Date: Sat, 17 May 2014 23:28:19 +0200 Subject: [PATCH] v2.2, added csharp language, line indentation bugfix --- Build/DynamicSourcefileLoader.dev.js | 2 +- Build/EnlighterJS.css | 4 +- Build/EnlighterJS.js | 67 ++++++++++- Build/EnlighterJS.yui.css | 4 +- Build/EnlighterJS.yui.js | 11 +- CHANGES.md | 7 ++ Development.phtml | 16 +++ Examples/Themes.html | 5 +- Examples/c.html | 5 +- Examples/cpp.html | 5 +- Examples/csharp.html | 165 +++++++++++++++++++++++++++ Examples/css.html | 5 +- Examples/html.html | 5 +- Examples/java.html | 5 +- Examples/js.html | 5 +- Examples/json.html | 5 +- Examples/markdown.html | 5 +- Examples/nohighlight.html | 5 +- Examples/nsis.html | 5 +- Examples/php.html | 5 +- Examples/python.html | 5 +- Examples/raw.html | 5 +- Examples/ruby.html | 5 +- Examples/sql.html | 5 +- Examples/unit.html | 16 ++- Examples/xml.html | 5 +- Resources/BootstrapTemplate.phtml | 5 +- Resources/TestcaseData/csharp.html | 45 ++++++++ Resources/TestcaseData/unit.html | 9 ++ Source/EnlighterJS.js | 8 +- Source/Language/CSharp.js | 52 +++++++++ Source/LanguageManager.js | 3 +- Util/ExampleGenerator.php | 2 +- Util/PageGenerator.php | 2 +- build.xml | 4 +- package.yml | 2 +- 36 files changed, 445 insertions(+), 64 deletions(-) create mode 100644 Examples/csharp.html create mode 100644 Resources/TestcaseData/csharp.html create mode 100644 Source/Language/CSharp.js diff --git a/Build/DynamicSourcefileLoader.dev.js b/Build/DynamicSourcefileLoader.dev.js index 8f198f1..51780d0 100644 --- a/Build/DynamicSourcefileLoader.dev.js +++ b/Build/DynamicSourcefileLoader.dev.js @@ -15,7 +15,7 @@ requires: */ window.addEvent('domready', function(){ // generated sourcefile list (space separated values) - placeholder get replaced during build process - var enlighterJsSources = "Source/EnlighterJS.js Source/SpecialLineHighlighter.js Source/Language/Generic.js Source/LanguageManager.js Source/Native/Element.EnlighterJS.js Source/Tokenizer.js Source/Token.js Source/Renderer/InlineRenderer.js Source/Renderer/BlockRenderer.js Source/Tokenizer/Lazy.js Source/Tokenizer/Xml.js Source/Util/Helper.js Source/UI/TabPane.js Source/Util/Metainit.js Source/Language/Cpp.js Source/Language/Xml.js Source/Language/Css.js Source/Language/Java.js Source/Language/Js.js Source/Language/Markdown.js Source/Language/Php.js Source/Language/Python.js Source/Language/Ruby.js Source/Language/Shell.js Source/Language/Sql.js Source/Language/Nsis.js Source/Language/Raw.js Source/Language/Template.mylang.js"; + var enlighterJsSources = "Source/EnlighterJS.js Source/SpecialLineHighlighter.js Source/Language/Generic.js Source/LanguageManager.js Source/Native/Element.EnlighterJS.js Source/Tokenizer.js Source/Token.js Source/Renderer/InlineRenderer.js Source/Renderer/BlockRenderer.js Source/Tokenizer/Lazy.js Source/Tokenizer/Xml.js Source/Util/Helper.js Source/UI/TabPane.js Source/Util/Metainit.js Source/Language/Cpp.js Source/Language/CSharp.js Source/Language/Xml.js Source/Language/Css.js Source/Language/Java.js Source/Language/Js.js Source/Language/Markdown.js Source/Language/Php.js Source/Language/Python.js Source/Language/Ruby.js Source/Language/Shell.js Source/Language/Sql.js Source/Language/Nsis.js Source/Language/Raw.js Source/Language/Template.mylang.js"; var enlighterCssSources = "Source/Themes/Base.css Source/Themes/MooTools.css Source/Themes/Enlighter.css Source/Themes/Git.css Source/Themes/Mocha.css Source/Themes/Panic.css Source/Themes/Tutti.css Source/Themes/Twilight.css"; // extract sourcefiles diff --git a/Build/EnlighterJS.css b/Build/EnlighterJS.css index ee47e14..7d22d2c 100644 --- a/Build/EnlighterJS.css +++ b/Build/EnlighterJS.css @@ -4,8 +4,8 @@ name: EnlighterJS description: Post Syntax Highlighter for MooTools - based on the famous Lighter.js license: MIT-Style X11 License -version: 2.1 -build: c9d6e6119856a2f256dcf83bd403899f/May 12 2014 +version: 2.2 +build: c9d6e6119856a2f256dcf83bd403899f/May 17 2014 authors: - Andi Dittrich (author of EnlighterJS) diff --git a/Build/EnlighterJS.js b/Build/EnlighterJS.js index eff0970..051401e 100644 --- a/Build/EnlighterJS.js +++ b/Build/EnlighterJS.js @@ -4,8 +4,8 @@ name: EnlighterJS description: Post Syntax Highlighter for MooTools - based on the famous Lighter.js license: MIT-Style X11 License -version: 2.1 -build: 7f88b90cb7de0eb75cf259da64a12e1a/May 12 2014 +version: 2.2 +build: 349e21bf9ca3eb132c7df880bf52d588/May 17 2014 authors: - Andi Dittrich (author of EnlighterJS) @@ -243,12 +243,14 @@ var EnlighterJS = new Class({ /** * Extracts the raw code from given codeblock - * @author Andi Dittrich * @return {String} The plain-text code (raw) */ getRawCode: function(reindent) { - // get the raw content - remove leading+trailing whitespaces - var code = this.originalCodeblock.get('html').trim(); + // get the raw content + var code = this.originalCodeblock.get('html'); + + // remove empty lines at the beginning+end of the codeblock + code = code.replace(/(^\s*\n|\n\s*$)/gi, ''); // cleanup ampersand ? if (this.options.ampersandCleanup===true){ @@ -572,7 +574,8 @@ EnlighterJS.LanguageManager = new Class({ 'html': 'xml', 'jquery': 'js', 'mootools': 'js', - 'ext.js': 'js' + 'ext.js': 'js', + 'c#': 'csharp' }, // get language name, process aliases and default languages @@ -1487,6 +1490,58 @@ EnlighterJS.Language.cpp = new Class({ }); /* --- +description: C Sharp Language patterns. + +license: MIT-style + +authors: + - Joshua Maag + +requires: + - Core/1.4.5 + +provides: [EnlighterJS.Language.csharp] +... +*/ +EnlighterJS.Language.csharp = new Class ({ + + Extends: EnlighterJS.Language.generic, + + setupLanguage: function(){ + this.keywords = { + reserved: { + csv: "as, base, break, case, catch, checked, continue, default, do, else, event, explicit, false, finally, fixed, for, foreach, goto, if, implicit, internal, is, lock, namespace, new, null, operator, params, private, protected, public, ref, return, sizeof, stackalloc, switch, this, throw, true, try, typeof, unchecked, using, void, while", + alias: 'kw1' + }, + keywords: { + csv: "abstract, async, class, const, delegate, dynamic, event, extern, in, interface, out, override, readonly, sealed, static, unsafe, virtual, volatile", + alias: 'kw3' + }, + primitives: { + csv: "bool, byte, char, decimal, double, enum, float, int, long, sbyte, short, struct, uint, ulong, ushort, object, string", + alias: 'kw2' + }, + internal: { + csv: "System", + alias: 'kw4' + } + }, + + this.patterns = { + 'slashComments': { pattern: this.common.slashComments, alias: 'co1'}, + 'multiComments': { pattern: this.common.multiComments, alias: 'co2'}, + 'chars': { pattern: this.common.singleQuotedString, alias: 'st0' }, + 'strings': { pattern: this.common.doubleQuotedString, alias: 'st1' }, + 'numbers': { pattern: /\b((([0-9]+)?\.)?[0-9_]+([e][-+]?[0-9]+)?|0x[A-F0-9]+|0b[0-1_]+)\b/gim, alias: 'nu0' }, + 'brackets': { pattern: this.common.brackets, alias: 'br0' }, + 'functionCalls': { pattern: this.common.functionCalls, alias: 'me0'}, + 'methodCalls': { pattern: this.common.methodCalls, alias: 'me1'} + }; + + } +}); +/* +--- description: XML language. license: MIT-style diff --git a/Build/EnlighterJS.yui.css b/Build/EnlighterJS.yui.css index 77eb94e..7941c64 100644 --- a/Build/EnlighterJS.yui.css +++ b/Build/EnlighterJS.yui.css @@ -6,8 +6,8 @@ name: EnlighterJS description: Post Syntax Highlighter for MooTools - based on the famous Lighter.js license: MIT-Style X11 License -version: 2.1 -build: c9d6e6119856a2f256dcf83bd403899f/May 12 2014 +version: 2.2 +build: c9d6e6119856a2f256dcf83bd403899f/May 17 2014 authors: - Andi Dittrich (author of EnlighterJS) diff --git a/Build/EnlighterJS.yui.js b/Build/EnlighterJS.yui.js index 39ce1ae..b22c15d 100644 --- a/Build/EnlighterJS.yui.js +++ b/Build/EnlighterJS.yui.js @@ -6,8 +6,8 @@ name: EnlighterJS description: Post Syntax Highlighter for MooTools - based on the famous Lighter.js license: MIT-Style X11 License -version: 2.1 -build: 7f88b90cb7de0eb75cf259da64a12e1a/May 12 2014 +version: 2.2 +build: 349e21bf9ca3eb132c7df880bf52d588/May 17 2014 authors: - Andi Dittrich (author of EnlighterJS) @@ -29,13 +29,13 @@ var EnlighterJS=new Class({Implements:Options,options:{language:"generic",theme: var g=(this.options.forceTheme?null:this.originalCodeblock.get("data-enlighter-theme"))||this.options.theme||"Enlighter";var f=new EnlighterJS.SpecialLineHighlighter(this.originalCodeblock.get("data-enlighter-highlight"),this.originalCodeblock.get("data-enlighter-lineoffset"));language=new EnlighterJS.Language[d](this.getRawCode(true));var a=this.renderer.render(language,f,{lineOffset:(this.originalCodeblock.get("data-enlighter-lineoffset")||null),lineNumbers:this.originalCodeblock.get("data-enlighter-linenumbers")}); a.addClass(g.toLowerCase()+"EnlighterJS").addClass("EnlighterJS");a.set("id","EnlighterJS_"+String.uniqueID());if(this.options.rawButton===true&&this.options.renderer=="Block"){if(this.container){this.container.grab(a)}else{this.container=new Element("div");this.container.grab(a);this.container.inject(this.originalCodeblock,"after")}this.container.addClass("EnlighterJSWrapper").addClass(g.toLowerCase()+"EnlighterJSWrapper"); var e=new Element("pre",{text:this.getRawCode(false),styles:{display:"none"}});this.container.grab(e);var c=true;this.container.grab(new Element("div",{"class":"EnlighterJSRawButton",events:{click:function(){if(c){a.setStyle("display","none");e.setStyle("display","block");c=false}else{a.setStyle("display","block");e.setStyle("display","none");c=true}}}}))}else{if(this.container){this.container.grab(a) -}else{a.inject(this.originalCodeblock,"after");this.container=a}}this.isRendered=true}else{if(this.isRendered){this.originalCodeblock.setStyle("display","inherit");this.container.setStyle("display","none")}}return this},light:function(){return this.enlight(true)},unlight:function(){return this.enlight(false)},getRawCode:function(a){var c=this.originalCodeblock.get("html").trim();if(this.options.ampersandCleanup===true){c=c.replace(/&/gim,"&") -}c=c.replace(/</gim,"<").replace(/>/gim,">").replace(/ /gim," ");if(a===true){var b=this.options.indent.toInt();if(b>-1){c=c.replace(/(\t*)/gim,function(e,g,f,d){return(new Array(b*g.length+1)).join(" ")})}}return c}});EnlighterJS.Language={};EnlighterJS.Renderer={};EnlighterJS.Util={};EnlighterJS.UI={};EnlighterJS.SpecialLineHighlighter=new Class({specialLines:{},initialize:function(d,c){if(d==null||d.length==0){return +}else{a.inject(this.originalCodeblock,"after");this.container=a}}this.isRendered=true}else{if(this.isRendered){this.originalCodeblock.setStyle("display","inherit");this.container.setStyle("display","none")}}return this},light:function(){return this.enlight(true)},unlight:function(){return this.enlight(false)},getRawCode:function(a){var c=this.originalCodeblock.get("html");c=c.replace(/(^\s*\n|\n\s*$)/gi,""); +if(this.options.ampersandCleanup===true){c=c.replace(/&/gim,"&")}c=c.replace(/</gim,"<").replace(/>/gim,">").replace(/ /gim," ");if(a===true){var b=this.options.indent.toInt();if(b>-1){c=c.replace(/(\t*)/gim,function(e,g,f,d){return(new Array(b*g.length+1)).join(" ")})}}return c}});EnlighterJS.Language={};EnlighterJS.Renderer={};EnlighterJS.Util={};EnlighterJS.UI={};EnlighterJS.SpecialLineHighlighter=new Class({specialLines:{},initialize:function(d,c){if(d==null||d.length==0){return }var b=(c!=null&&c.toInt()>1?c.toInt()-1:0);var a=d.split(",");a.each(function(h,e){var j=h.match(/([0-9]+)-([0-9]+)/);if(j!=null){var k=j[1].toInt()-b;var g=j[2].toInt()-b;if(g>k){for(var f=k;f<=g;f++){this.specialLines["l"+f]=true}}}else{this.specialLines["l"+(h.toInt()-b)]=true}}.bind(this))},isSpecialLine:function(a){return(this.specialLines["l"+a]||false)}});EnlighterJS.Language.generic=new Class({tokenizerType:"Lazy",tokenizer:null,code:null,patterns:{},keywords:{},delimiters:{start:null,end:null},common:{slashComments:/(?:^|[^\\])\/\/.*$/gm,poundComments:/#.*$/gm,multiComments:/\/\*[\s\S]*?\*\//gm,aposStrings:/'[^'\\]*(?:\\.[^'\\]*)*'/gm,quotedStrings:/"[^"\\]*(?:\\.[^"\\]*)*"/gm,multiLineSingleQuotedStrings:/'[^'\\]*(?:\\.[^'\\]*)*'/gm,multiLineDoubleQuotedStrings:/"[^"\\]*(?:\\.[^"\\]*)*"/gm,multiLineStrings:/'[^'\\]*(?:\\.[^'\\]*)*'|"[^"\\]*(?:\\.[^"\\]*)*"/gm,singleQuotedString:/'[^'\\\r\n]*(?:\\.[^'\\\r\n]*)*'/gm,doubleQuotedString:/"[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*"/gm,strings:/'[^'\\\r\n]*(?:\\.[^'\\\r\n]*)*'|"[^"\\\r\n]*(?:\\.[^"\\\r\n]*)*"/gm,properties:/\.([\w]+)\s*/gi,methodCalls:/\.([\w]+)\s*\(/gm,functionCalls:/\b([\w]+)\s*\(/gm,brackets:/\{|\}|\(|\)|\[|\]/g,numbers:/\b((?:(\d+)?\.)?[0-9]+|0x[0-9A-F]+)\b/gi},initialize:function(a){this.setupLanguage(); this.aliases={};this.rules={};this.code=a;this.tokenizer=new EnlighterJS.Tokenizer[this.tokenizerType]();if(this.delimiters.start){this.addRule("delimBeg",this.delimiters.start,"de1")}if(this.delimiters.end){this.addRule("delimEnd",this.delimiters.end,"de2")}Object.each(this.keywords,function(c,b){if(c.csv!=""){this.addRule(b,this.csvToRegExp(c.csv,c.mod||"g"),c.alias)}},this);Object.each(this.patterns,function(b,c){this.addRule(c,b.pattern,b.alias) },this)},setupLanguage:function(){},getTokens:function(){return this.tokenizer.getTokens(this,this.code)},getRules:function(){return this.rules},hasDelimiters:function(){return this.delimiters.start&&this.delimiters.end},addRule:function(c,b,a){this.rules[c]=b;this.addAlias(c,a)},addAlias:function(b,a){this.aliases[b]=a||b},csvToRegExp:function(a,b){return new RegExp("\\b("+a.replace(/,\s*/g,"|")+")\\b",b) },delimToRegExp:function(d,b,a,e,f){d=d.escapeRegExp();if(b){b=b.escapeRegExp()}a=(a)?a.escapeRegExp():d;var c=(b)?d+"[^"+a+b+"\\n]*(?:"+b+".[^"+a+b+"\\n]*)*"+a:d+"[^"+a+"\\n]*"+a;return new RegExp(c+(f||""),e||"")},strictRegExp:function(){var b="(";for(var a=0;a)/gim,alias:"co1"},cdata:{pattern:/(?:\<|<)!\[CDATA\[[\s\S]*?\]\](?:\>|>)/gim,alias:"st1"},closingTags:{pattern:/(?:\<|<)\/[A-Z][A-Z0-9]*?(?:\>|>)/gi,alias:"kw1"},doctype:{pattern:/(?:\<|<)!DOCTYPE[\s\S]+?(?:\>|>)/gim,alias:"st2"},version:{pattern:/(?:\<|<)\?xml[\s\S]+?\?(?:\>|>)/gim,alias:"kw2"}} }});EnlighterJS.Language.css=new Class({Extends:EnlighterJS.Language.generic,setupLanguage:function(){this.keywords={css1:{csv:"background-attachment, background-color, background-image, background-position, background-repeat, background, border-bottom, border-bottom-width, border-color, border-left, border-left-width, border-right, border-right-width, border-style, border-top, border-top-width, border-width, border, clear, color, display, float, font-family, font-size, font-style, font-variant, font-weight, font, height, letter-spacing, line-height, list-style-image, list-style-position, list-style-type, list-style, margin-bottom, margin-left, margin-right, margin-top, margin, padding-bottom, padding-left, padding-right, padding-top, padding, text-align, text-decoration, text-indent, text-transform, vertical-align, white-space, width, word-spacing",alias:"kw1"},css2:{csv:"azimuth, border-bottom-color, border-bottom-style, border-collapse, border-left-color, border-left-style, border-right-color, border-right-style, border-spacing, border-top-color, border-top-style, bottom, caption-side, clip, content, counter-increment, counter-reset, cue, cue-after, cue-before, cursor, direction, elevation, empty-cells, left, max-height, max-width, min-height, min-width, orphans, outline, outline-color, outline-style, outline-width, overflow, page-break-after, page-break-before, page-break-inside, pause, pause-after, pause-before, pitch, pitch-range, play-during, position, quotes, richness, right, speak, speak-header, speak-numeral, speak-punctuation, speech-rate, stress, table-layout, top, unicode-bidi, visibility, voice-family, volume, widows, z-index",alias:"kw1"},css3:{csv:"alignment-adjust, alignment-baseline, appearance, background-break, background-clip, background-origin, background-size, baseline-shift, binding, bookmark-label, bookmark-level, bookmark-target, border-bottom-left-radius, border-bottom-right-radius, border-break, border-image, border-length, border-radius, border-top-left-radius, border-top-right-radius, box-align, box-direction, box-flex, box-flex-group, box-lines, box-orient, box-pack, box-shadow, box-sizing, color-profile, column-break-after, column-break-before, column-count, column-fill, column-gap, column-rule, column-rule-color, column-rule-style, column-rule-width, column-span, column-width, columns, crop, display-model, display-role, dominant-baseline, drop-initial-after-adjust, drop-initial-after-align, drop-initial-before-adjust, drop-initial-before-align, drop-initial-size, drop-initial-value, fit, fit-position, float-offset, font-effect, font-emphasize, font-emphasize-position, font-emphasize-style, font-size-adjust, font-smooth, font-stretch, grid-columns, grid-rows, hanging-punctuation, hyphenate-after, hyphenate-before, hyphenate-character, hyphenate-lines, hyphenate-resource, hyphens, icon, image-orientation, image-resolution, inline-box-align, line-stacking, line-stacking-ruby, line-stacking-shift, line-stacking-strategy, mark, mark-after, mark-before, marker-offset, marks, marquee-direction, marquee-play-count, marquee-speed, marquee-style, move-to, nav-down, nav-index, nav-left, nav-right, nav-up, opacity, outline-offset, overflow-style, overflow-x, overflow-y, page, page-policy, phonemes, presentation-level, punctuation-trim, rendering-intent, resize, rest, rest-after, rest-before, rotation, rotation-point, ruby-align, ruby-overhang, ruby-position, ruby-span, size, string-set, tab-side, target, target-name, target-new, target-position, text-align-last, text-emphasis, text-height, text-justify, text-outline, text-replace, text-shadow, text-wrap, voice-balance, voice-duration, voice-pitch, voice-pitch-range, voice-rate, voice-stress, voice-volume, white-space-collapse, word-break, word-wrap",alias:"kw2"},values:{csv:"100, 200, 300, 400, 500, 600, 700, 800, 900, above, absolute, always, aqua, armenian, auto, avoid, baseline, below, bidi-override, black, blink, block, blue, bold, bolder, both, bottom, break-all, break-strict, break-word, break, capitalize, caption, center, circle, cjk-ideographic, close-quote, collapse, compact, condensed, crop, cross, crosshair, dashed, decimal-leading-zero, decimal, default, disc, dotted, double, e-resize, embed, expanded, extra-condensed, extra-expanded, fixed, fuchsia, georgian, gray, green, groove, hand, hebrew, help, hidden, hide, higher, hiragana-iroha, hiragana, icon, inherit, inline-table, inline, inset, inside, invert, italic, justify, katakana-iroha, katakana, keep-all, konq-center, landscape, large, larger, left, level, light, lighter, lime, line-through, list-item, loose, loud, lower-alpha, lower-greek, lower-latin, lower-roman, lowercase, lower, ltr, marker, maroon, medium, menu, message-box, middle, mix, move, n-resize, narrower, navy, ne-resize, never, no-close-quote, no-open-quote, no-repeat, none, normal, nowrap, nw-resize, oblique, olive, open-quote, outset, outside, overline, pointer, portrait, pre-wrap, pre, purple, red, relative, repeat, repeat-x, repeat-y, ridge, right, rtl, run-in, s-resize, scroll, se-resize, semi-condensed, semi-expanded, separate, show, silver, small-caps, small-caption, smaller, small, solid, square, static-position, static, status-bar, sub, super, sw-resize, table-caption, table-cell, table-column-group, table-column, table-footer-group, table-header-group, table-row, table-row-group, table, teal, text-bottom, text-top, text, thick, thin, top, transparent, ultra-condensed, ultra-expanded, underline, upper-alpha, upper-latin, upper-roman, uppercase, visible, w-resize, wait, white, wider, x-large, x-small, xx-large, xx-small, yellow",alias:"kw3"}}; this.patterns={multiComments:{pattern:this.common.multiComments,alias:"co1"},strings:{pattern:this.common.strings,alias:"st0"},selectors:{pattern:/([^\}\n]+)\{/gi,alias:"se0"},uri:{pattern:/url\s*\([^\)]*\)/gi,alias:"kw4"},units:{pattern:/\b(\d+[\.\d+]?\s*(px|pt|em|ex|cm|in|mm|pc|%)?)/gi,alias:"nu0"},hexColors:{pattern:/(#[A-F0-9]{3}([A-F0-9]{3})?)\b/gi,alias:"kw3"},rgbColors:{pattern:/(rgb\s*\(([1-2]?[0-9]{2}(\,\s*)?){3}\))/g,alias:"kw3"}}; diff --git a/CHANGES.md b/CHANGES.md index 6b9ac6c..d265fed 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +### Version 2.2 ## +* Added language support for C# (csharp) [provided by Joshua Maag](https://github.com/joshmaag) +* Added C# language example +* Added language alias "c#" for language csharp +* Changed: using YUI compressed file within Examples+PublicHtml pages +* Bugfix: Indentation of first line got lost - thanks to [cdonts](http://wordpress.org/support/topic/no-indentation-in-the-first-line?replies=2) + ### Version 2.1 ### * Added Changelog to doc pages * Added Inline Highlighting example to the Theme-Demo page diff --git a/Development.phtml b/Development.phtml index db55410..74c5408 100644 --- a/Development.phtml +++ b/Development.phtml @@ -113,6 +113,22 @@ consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

+
+
+
+
+
+	alert('hello world');
+	new FX.scroll(args);
+	}
+
+// other stuff	
+
+  
+  
+   
+
+

Single JS Testcode

 window.addEvent('domready', function(){
diff --git a/Examples/Themes.html b/Examples/Themes.html
index baf16a9..88d0a35 100644
--- a/Examples/Themes.html
+++ b/Examples/Themes.html
@@ -16,13 +16,13 @@
 	
 
 	
-	
+	
 	
 	
 	
 
 	
-		
+		
 
 	
 
@@ -55,6 +55,7 @@
 							
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/c.html b/Examples/c.html index 6252de0..686e1f3 100644 --- a/Examples/c.html +++ b/Examples/c.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/cpp.html b/Examples/cpp.html index b44145e..d510783 100644 --- a/Examples/cpp.html +++ b/Examples/cpp.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/csharp.html b/Examples/csharp.html new file mode 100644 index 0000000..2ef51d6 --- /dev/null +++ b/Examples/csharp.html @@ -0,0 +1,165 @@ + + + + + + + + + + + Language Example: CSharp | EnlighterJS + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    + +

    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor +System.out.println("Hello World!"); invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. +

    + +
    +// Source: https://en.wikipedia.org/wiki/C_Sharp_syntax#Attributes
    +public class EdibleAttribute : Attribute
    +{
    +    public EdibleAttribute() : base()
    +    {
    + 
    +    }
    + 
    +    public EdibleAttribute(bool isNotPoisonous)
    +    {
    +        this.IsPoisonous = !isNotPoisonous;
    +    }
    + 
    +    public bool IsPoisonous { get; set; }
    +}
    +
    +
    +// Source:  https://en.wikipedia.org/wiki/C_Sharp_syntax#Events
    +public class MainWindow : System.Windows.Controls.Window
    +{
    +    private Button button1;
    + 
    +    public MainWindow()
    +    {
    +        button1 = new Button();
    +        button1.Text = "Click me!";
    + 
    +        /* Subscribe to the event */
    +        button1.ClickEvent += button1_OnClick;
    + 
    +        /* Alternate syntax that is considered old: 
    +           button1.MouseClick += new MouseEventHandler(button1_OnClick); */
    +    }
    + 
    +    protected void button1_OnClick(object sender, MouseEventArgs e)
    +    {
    +        MessageBox.Show("Clicked!");
    +    }
    +}
    +
    + +
    + + + +
    + + + + + + + + \ No newline at end of file diff --git a/Examples/css.html b/Examples/css.html index 865f38b..70d26ff 100644 --- a/Examples/css.html +++ b/Examples/css.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/html.html b/Examples/html.html index 61d1dba..1dfcad1 100644 --- a/Examples/html.html +++ b/Examples/html.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/java.html b/Examples/java.html index 7631688..31e2cda 100644 --- a/Examples/java.html +++ b/Examples/java.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/js.html b/Examples/js.html index 42b7f0d..a44ae31 100644 --- a/Examples/js.html +++ b/Examples/js.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/json.html b/Examples/json.html index 63c5fd5..90126db 100644 --- a/Examples/json.html +++ b/Examples/json.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/markdown.html b/Examples/markdown.html index d9a4350..e1b2209 100644 --- a/Examples/markdown.html +++ b/Examples/markdown.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/nohighlight.html b/Examples/nohighlight.html index d69d8d2..5aebc4d 100644 --- a/Examples/nohighlight.html +++ b/Examples/nohighlight.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/nsis.html b/Examples/nsis.html index 748ebf0..ec86599 100644 --- a/Examples/nsis.html +++ b/Examples/nsis.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/php.html b/Examples/php.html index 24d6218..d5023a6 100644 --- a/Examples/php.html +++ b/Examples/php.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/python.html b/Examples/python.html index 50fd4e5..86de2f6 100644 --- a/Examples/python.html +++ b/Examples/python.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/raw.html b/Examples/raw.html index 1096b75..6711723 100644 --- a/Examples/raw.html +++ b/Examples/raw.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/ruby.html b/Examples/ruby.html index c6b28d6..a3f9b0b 100644 --- a/Examples/ruby.html +++ b/Examples/ruby.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/sql.html b/Examples/sql.html index bd43531..651ba9e 100644 --- a/Examples/sql.html +++ b/Examples/sql.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Examples/unit.html b/Examples/unit.html index b1a911a..427db14 100644 --- a/Examples/unit.html +++ b/Examples/unit.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • @@ -97,7 +98,16 @@

    -

    Line-Offset 4

    +

    Line indentation of first line shouldn't removed

    +
    +	alert('hello world');
    +	new FX.scroll(args);
    +	}
    +
    +// other stuff	
    +
    + +

    Line-Offset 4

    alert('hello world');

    Line-Offset 4; Force Linenumbers OFF

    diff --git a/Examples/xml.html b/Examples/xml.html index 4b20e9a..c873448 100644 --- a/Examples/xml.html +++ b/Examples/xml.html @@ -16,13 +16,13 @@ - + - + @@ -55,6 +55,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Resources/BootstrapTemplate.phtml b/Resources/BootstrapTemplate.phtml index 8c9d820..ac91621 100644 --- a/Resources/BootstrapTemplate.phtml +++ b/Resources/BootstrapTemplate.phtml @@ -16,13 +16,13 @@ - + - + @@ -56,6 +56,7 @@
  • Java
  • Python
  • C++
  • +
  • C#
  • C
  • Ruby
  • NSIS
  • diff --git a/Resources/TestcaseData/csharp.html b/Resources/TestcaseData/csharp.html new file mode 100644 index 0000000..1f61c40 --- /dev/null +++ b/Resources/TestcaseData/csharp.html @@ -0,0 +1,45 @@ +

    Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor +System.out.println("Hello World!"); invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet. +

    + +
    +// Source: https://en.wikipedia.org/wiki/C_Sharp_syntax#Attributes
    +public class EdibleAttribute : Attribute
    +{
    +    public EdibleAttribute() : base()
    +    {
    + 
    +    }
    + 
    +    public EdibleAttribute(bool isNotPoisonous)
    +    {
    +        this.IsPoisonous = !isNotPoisonous;
    +    }
    + 
    +    public bool IsPoisonous { get; set; }
    +}
    +
    +
    +// Source:  https://en.wikipedia.org/wiki/C_Sharp_syntax#Events
    +public class MainWindow : System.Windows.Controls.Window
    +{
    +    private Button button1;
    + 
    +    public MainWindow()
    +    {
    +        button1 = new Button();
    +        button1.Text = "Click me!";
    + 
    +        /* Subscribe to the event */
    +        button1.ClickEvent += button1_OnClick;
    + 
    +        /* Alternate syntax that is considered old: 
    +           button1.MouseClick += new MouseEventHandler(button1_OnClick); */
    +    }
    + 
    +    protected void button1_OnClick(object sender, MouseEventArgs e)
    +    {
    +        MessageBox.Show("Clicked!");
    +    }
    +}
    +
    \ No newline at end of file diff --git a/Resources/TestcaseData/unit.html b/Resources/TestcaseData/unit.html index 5ad31eb..ec12b1e 100644 --- a/Resources/TestcaseData/unit.html +++ b/Resources/TestcaseData/unit.html @@ -1,3 +1,12 @@ +

    Line indentation of first line shouldn't removed

    +
    +	alert('hello world');
    +	new FX.scroll(args);
    +	}
    +
    +// other stuff	
    +
    +

    Line-Offset 4

    alert('hello world');
    diff --git a/Source/EnlighterJS.js b/Source/EnlighterJS.js index 482a9b9..29cad1c 100644 --- a/Source/EnlighterJS.js +++ b/Source/EnlighterJS.js @@ -221,12 +221,14 @@ var EnlighterJS = new Class({ /** * Extracts the raw code from given codeblock - * @author Andi Dittrich * @return {String} The plain-text code (raw) */ getRawCode: function(reindent) { - // get the raw content - remove leading+trailing whitespaces - var code = this.originalCodeblock.get('html').trim(); + // get the raw content + var code = this.originalCodeblock.get('html'); + + // remove empty lines at the beginning+end of the codeblock + code = code.replace(/(^\s*\n|\n\s*$)/gi, ''); // cleanup ampersand ? if (this.options.ampersandCleanup===true){ diff --git a/Source/Language/CSharp.js b/Source/Language/CSharp.js new file mode 100644 index 0000000..86647af --- /dev/null +++ b/Source/Language/CSharp.js @@ -0,0 +1,52 @@ +/* +--- +description: C Sharp Language patterns. + +license: MIT-style + +authors: + - Joshua Maag + +requires: + - Core/1.4.5 + +provides: [EnlighterJS.Language.csharp] +... +*/ +EnlighterJS.Language.csharp = new Class ({ + + Extends: EnlighterJS.Language.generic, + + setupLanguage: function(){ + this.keywords = { + reserved: { + csv: "as, base, break, case, catch, checked, continue, default, do, else, event, explicit, false, finally, fixed, for, foreach, goto, if, implicit, internal, is, lock, namespace, new, null, operator, params, private, protected, public, ref, return, sizeof, stackalloc, switch, this, throw, true, try, typeof, unchecked, using, void, while", + alias: 'kw1' + }, + keywords: { + csv: "abstract, async, class, const, delegate, dynamic, event, extern, in, interface, out, override, readonly, sealed, static, unsafe, virtual, volatile", + alias: 'kw3' + }, + primitives: { + csv: "bool, byte, char, decimal, double, enum, float, int, long, sbyte, short, struct, uint, ulong, ushort, object, string", + alias: 'kw2' + }, + internal: { + csv: "System", + alias: 'kw4' + } + }, + + this.patterns = { + 'slashComments': { pattern: this.common.slashComments, alias: 'co1'}, + 'multiComments': { pattern: this.common.multiComments, alias: 'co2'}, + 'chars': { pattern: this.common.singleQuotedString, alias: 'st0' }, + 'strings': { pattern: this.common.doubleQuotedString, alias: 'st1' }, + 'numbers': { pattern: /\b((([0-9]+)?\.)?[0-9_]+([e][-+]?[0-9]+)?|0x[A-F0-9]+|0b[0-1_]+)\b/gim, alias: 'nu0' }, + 'brackets': { pattern: this.common.brackets, alias: 'br0' }, + 'functionCalls': { pattern: this.common.functionCalls, alias: 'me0'}, + 'methodCalls': { pattern: this.common.methodCalls, alias: 'me1'} + }; + + } +}); diff --git a/Source/LanguageManager.js b/Source/LanguageManager.js index d8a2bb3..a7da991 100644 --- a/Source/LanguageManager.js +++ b/Source/LanguageManager.js @@ -43,7 +43,8 @@ EnlighterJS.LanguageManager = new Class({ 'html': 'xml', 'jquery': 'js', 'mootools': 'js', - 'ext.js': 'js' + 'ext.js': 'js', + 'c#': 'csharp' }, // get language name, process aliases and default languages diff --git a/Util/ExampleGenerator.php b/Util/ExampleGenerator.php index c7f97ad..83f7f4f 100644 --- a/Util/ExampleGenerator.php +++ b/Util/ExampleGenerator.php @@ -18,7 +18,7 @@ function cdnbase($file){ // === Language Examples ================================================= $languages = array( - 'C', 'Cpp', 'CSS', 'HTML', 'Java', 'js', 'JSON', 'MarkDown', 'NSIS', 'PHP', 'Python', 'Ruby', 'SQL', 'Unit', 'XML', 'RAW', 'NoHighlight' + 'C', 'Cpp', 'CSharp', 'CSS', 'HTML', 'Java', 'js', 'JSON', 'MarkDown', 'NSIS', 'PHP', 'Python', 'Ruby', 'SQL', 'Unit', 'XML', 'RAW', 'NoHighlight' ); foreach ($languages as $lang){ $langContent = file_get_contents('Resources/TestcaseData/'.strtolower($lang).'.html'); diff --git a/Util/PageGenerator.php b/Util/PageGenerator.php index ee1035b..52b2cfb 100644 --- a/Util/PageGenerator.php +++ b/Util/PageGenerator.php @@ -46,7 +46,7 @@ function cdnbase($file){ // === Language Examples ================================================= $languages = array( - 'C', 'Cpp', 'CSS', 'HTML', 'Java', 'js', 'JSON', 'MarkDown', 'NSIS', 'PHP', 'Python', 'Ruby', 'SQL', 'Unit', 'XML', 'RAW', 'NoHighlight' + 'C', 'Cpp', 'CSharp', 'CSS', 'HTML', 'Java', 'js', 'JSON', 'MarkDown', 'NSIS', 'PHP', 'Python', 'Ruby', 'SQL', 'Unit', 'XML', 'RAW', 'NoHighlight' ); foreach ($languages as $lang){ $langContent = file_get_contents('Resources/TestcaseData/'.strtolower($lang).'.html'); diff --git a/build.xml b/build.xml index bcf879a..9ba9c05 100644 --- a/build.xml +++ b/build.xml @@ -15,7 +15,7 @@ - + @@ -32,7 +32,7 @@ - + diff --git a/package.yml b/package.yml index 563a680..1276a53 100644 --- a/package.yml +++ b/package.yml @@ -5,4 +5,4 @@ category: Interface tags: [parser, syntax highlighter] demo: http://enlighterjs.andidittrich.de/Themes.html docs: http://enlighterjs.andidittrich.de -current: v2.1 \ No newline at end of file +current: v2.2 \ No newline at end of file