| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,108 @@ | ||
| // Because sometimes you need to mark the selected *text*. | ||
| // | ||
| // Adds an option 'styleSelectedText' which, when enabled, gives | ||
| // selected text the CSS class given as option value, or | ||
| // "CodeMirror-selectedtext" when the value is not a string. | ||
|
|
||
| (function() { | ||
| "use strict"; | ||
|
|
||
| CodeMirror.defineOption("styleSelectedText", false, function(cm, val, old) { | ||
| var prev = old && old != CodeMirror.Init; | ||
| if (val && !prev) { | ||
| cm.state.markedSelection = []; | ||
| cm.state.markedSelectionStyle = typeof val == "string" ? val : "CodeMirror-selectedtext"; | ||
| reset(cm); | ||
| cm.on("cursorActivity", onCursorActivity); | ||
| cm.on("change", onChange); | ||
| } else if (!val && prev) { | ||
| cm.off("cursorActivity", onCursorActivity); | ||
| cm.off("change", onChange); | ||
| clear(cm); | ||
| cm.state.markedSelection = cm.state.markedSelectionStyle = null; | ||
| } | ||
| }); | ||
|
|
||
| function onCursorActivity(cm) { | ||
| cm.operation(function() { update(cm); }); | ||
| } | ||
|
|
||
| function onChange(cm) { | ||
| if (cm.state.markedSelection.length) | ||
| cm.operation(function() { clear(cm); }); | ||
| } | ||
|
|
||
| var CHUNK_SIZE = 8; | ||
| var Pos = CodeMirror.Pos; | ||
|
|
||
| function cmp(pos1, pos2) { | ||
| return pos1.line - pos2.line || pos1.ch - pos2.ch; | ||
| } | ||
|
|
||
| function coverRange(cm, from, to, addAt) { | ||
| if (cmp(from, to) == 0) return; | ||
| var array = cm.state.markedSelection; | ||
| var cls = cm.state.markedSelectionStyle; | ||
| for (var line = from.line;;) { | ||
| var start = line == from.line ? from : Pos(line, 0); | ||
| var endLine = line + CHUNK_SIZE, atEnd = endLine >= to.line; | ||
| var end = atEnd ? to : Pos(endLine, 0); | ||
| var mark = cm.markText(start, end, {className: cls}); | ||
| if (addAt == null) array.push(mark); | ||
| else array.splice(addAt++, 0, mark); | ||
| if (atEnd) break; | ||
| line = endLine; | ||
| } | ||
| } | ||
|
|
||
| function clear(cm) { | ||
| var array = cm.state.markedSelection; | ||
| for (var i = 0; i < array.length; ++i) array[i].clear(); | ||
| array.length = 0; | ||
| } | ||
|
|
||
| function reset(cm) { | ||
| clear(cm); | ||
| var from = cm.getCursor("start"), to = cm.getCursor("end"); | ||
| coverRange(cm, from, to); | ||
| } | ||
|
|
||
| function update(cm) { | ||
| var from = cm.getCursor("start"), to = cm.getCursor("end"); | ||
| if (cmp(from, to) == 0) return clear(cm); | ||
|
|
||
| var array = cm.state.markedSelection; | ||
| if (!array.length) return coverRange(cm, from, to); | ||
|
|
||
| var coverStart = array[0].find(), coverEnd = array[array.length - 1].find(); | ||
| if (!coverStart || !coverEnd || to.line - from.line < CHUNK_SIZE || | ||
| cmp(from, coverEnd.to) >= 0 || cmp(to, coverStart.from) <= 0) | ||
| return reset(cm); | ||
|
|
||
| while (cmp(from, coverStart.from) > 0) { | ||
| array.shift().clear(); | ||
| coverStart = array[0].find(); | ||
| } | ||
| if (cmp(from, coverStart.from) < 0) { | ||
| if (coverStart.to.line - from.line < CHUNK_SIZE) { | ||
| array.shift().clear(); | ||
| coverRange(cm, from, coverStart.to, 0); | ||
| } else { | ||
| coverRange(cm, from, coverStart.from, 0); | ||
| } | ||
| } | ||
|
|
||
| while (cmp(to, coverEnd.to) < 0) { | ||
| array.pop().clear(); | ||
| coverEnd = array[array.length - 1].find(); | ||
| } | ||
| if (cmp(to, coverEnd.to) > 0) { | ||
| if (to.line - coverEnd.from.line < CHUNK_SIZE) { | ||
| array.pop().clear(); | ||
| coverRange(cm, coverEnd.from, to); | ||
| } else { | ||
| coverRange(cm, coverEnd.to, to); | ||
| } | ||
| } | ||
| } | ||
| })(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| // Simple command-line code highlighting tool. Reads code from stdin, | ||
| // spits html to stdout. For example: | ||
| // | ||
| // echo 'function foo(a) { return a; }' | bin/source-highlight -s javascript | ||
| // bin/source-highlight -s | ||
|
|
||
| var fs = require("fs"); | ||
|
|
||
| CodeMirror = require("../addon/runmode/runmode.node.js"); | ||
| require("../mode/meta.js"); | ||
|
|
||
| var sPos = process.argv.indexOf("-s"); | ||
| if (sPos == -1 || sPos == process.argv.length - 1) { | ||
| console.error("Usage: source-highlight -s language"); | ||
| process.exit(1); | ||
| } | ||
| var lang = process.argv[sPos + 1].toLowerCase(), modeName = lang; | ||
| CodeMirror.modeInfo.forEach(function(info) { | ||
| if (info.mime == lang) { | ||
| modeName = info.mode; | ||
| } else if (info.name.toLowerCase() == lang) { | ||
| modeName = info.mode; | ||
| lang = info.mime; | ||
| } | ||
| }); | ||
|
|
||
| function ensureMode(name) { | ||
| if (CodeMirror.modes[name] || name == "null") return; | ||
| try { | ||
| require("../mode/" + name + "/" + name + ".js"); | ||
| } catch(e) { | ||
| console.error("Could not load mode " + name + "."); | ||
| process.exit(1); | ||
| } | ||
| var obj = CodeMirror.modes[name]; | ||
| if (obj.dependencies) obj.dependencies.forEach(ensureMode); | ||
| } | ||
| ensureMode(modeName); | ||
|
|
||
| function esc(str) { | ||
| return str.replace(/[<&]/, function(ch) { return ch == "&" ? "&" : "<"; }); | ||
| } | ||
|
|
||
| var code = fs.readFileSync("/dev/stdin", "utf8"); | ||
| var curStyle = null, accum = ""; | ||
| function flush() { | ||
| if (curStyle) process.stdout.write("<span class=\"" + curStyle.replace(/(^|\s+)/g, "$1cm-") + "\">" + esc(accum) + "</span>"); | ||
| else process.stdout.write(esc(accum)); | ||
| } | ||
|
|
||
| CodeMirror.runMode(code, lang, function(text, style) { | ||
| if (style != curStyle) { | ||
| flush(); | ||
| curStyle = style; accum = text; | ||
| } else { | ||
| accum += text; | ||
| } | ||
| }); | ||
| flush(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,240 @@ | ||
| /** | ||
| * Author: Gautam Mehta | ||
| * Branched from CodeMirror's Scheme mode | ||
| */ | ||
| CodeMirror.defineMode("cobol", function () { | ||
| var BUILTIN = "builtin", COMMENT = "comment", STRING = "string", | ||
| ATOM = "atom", NUMBER = "number", KEYWORD = "keyword", MODTAG = "header", | ||
| COBOLLINENUM = "def", PERIOD = "link"; | ||
| function makeKeywords(str) { | ||
| var obj = {}, words = str.split(" "); | ||
| for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | ||
| return obj; | ||
| } | ||
| var atoms = makeKeywords("TRUE FALSE ZEROES ZEROS ZERO SPACES SPACE LOW-VALUE LOW-VALUES "); | ||
| var keywords = makeKeywords( | ||
| "ACCEPT ACCESS ACQUIRE ADD ADDRESS " + | ||
| "ADVANCING AFTER ALIAS ALL ALPHABET " + | ||
| "ALPHABETIC ALPHABETIC-LOWER ALPHABETIC-UPPER ALPHANUMERIC ALPHANUMERIC-EDITED " + | ||
| "ALSO ALTER ALTERNATE AND ANY " + | ||
| "ARE AREA AREAS ARITHMETIC ASCENDING " + | ||
| "ASSIGN AT ATTRIBUTE AUTHOR AUTO " + | ||
| "AUTO-SKIP AUTOMATIC B-AND B-EXOR B-LESS " + | ||
| "B-NOT B-OR BACKGROUND-COLOR BACKGROUND-COLOUR BEEP " + | ||
| "BEFORE BELL BINARY BIT BITS " + | ||
| "BLANK BLINK BLOCK BOOLEAN BOTTOM " + | ||
| "BY CALL CANCEL CD CF " + | ||
| "CH CHARACTER CHARACTERS CLASS CLOCK-UNITS " + | ||
| "CLOSE COBOL CODE CODE-SET COL " + | ||
| "COLLATING COLUMN COMMA COMMIT COMMITMENT " + | ||
| "COMMON COMMUNICATION COMP COMP-0 COMP-1 " + | ||
| "COMP-2 COMP-3 COMP-4 COMP-5 COMP-6 " + | ||
| "COMP-7 COMP-8 COMP-9 COMPUTATIONAL COMPUTATIONAL-0 " + | ||
| "COMPUTATIONAL-1 COMPUTATIONAL-2 COMPUTATIONAL-3 COMPUTATIONAL-4 COMPUTATIONAL-5 " + | ||
| "COMPUTATIONAL-6 COMPUTATIONAL-7 COMPUTATIONAL-8 COMPUTATIONAL-9 COMPUTE " + | ||
| "CONFIGURATION CONNECT CONSOLE CONTAINED CONTAINS " + | ||
| "CONTENT CONTINUE CONTROL CONTROL-AREA CONTROLS " + | ||
| "CONVERTING COPY CORR CORRESPONDING COUNT " + | ||
| "CRT CRT-UNDER CURRENCY CURRENT CURSOR " + | ||
| "DATA DATE DATE-COMPILED DATE-WRITTEN DAY " + | ||
| "DAY-OF-WEEK DB DB-ACCESS-CONTROL-KEY DB-DATA-NAME DB-EXCEPTION " + | ||
| "DB-FORMAT-NAME DB-RECORD-NAME DB-SET-NAME DB-STATUS DBCS " + | ||
| "DBCS-EDITED DE DEBUG-CONTENTS DEBUG-ITEM DEBUG-LINE " + | ||
| "DEBUG-NAME DEBUG-SUB-1 DEBUG-SUB-2 DEBUG-SUB-3 DEBUGGING " + | ||
| "DECIMAL-POINT DECLARATIVES DEFAULT DELETE DELIMITED " + | ||
| "DELIMITER DEPENDING DESCENDING DESCRIBED DESTINATION " + | ||
| "DETAIL DISABLE DISCONNECT DISPLAY DISPLAY-1 " + | ||
| "DISPLAY-2 DISPLAY-3 DISPLAY-4 DISPLAY-5 DISPLAY-6 " + | ||
| "DISPLAY-7 DISPLAY-8 DISPLAY-9 DIVIDE DIVISION " + | ||
| "DOWN DROP DUPLICATE DUPLICATES DYNAMIC " + | ||
| "EBCDIC EGI EJECT ELSE EMI " + | ||
| "EMPTY EMPTY-CHECK ENABLE END END. END-ACCEPT END-ACCEPT. " + | ||
| "END-ADD END-CALL END-COMPUTE END-DELETE END-DISPLAY " + | ||
| "END-DIVIDE END-EVALUATE END-IF END-INVOKE END-MULTIPLY " + | ||
| "END-OF-PAGE END-PERFORM END-READ END-RECEIVE END-RETURN " + | ||
| "END-REWRITE END-SEARCH END-START END-STRING END-SUBTRACT " + | ||
| "END-UNSTRING END-WRITE END-XML ENTER ENTRY " + | ||
| "ENVIRONMENT EOP EQUAL EQUALS ERASE " + | ||
| "ERROR ESI EVALUATE EVERY EXCEEDS " + | ||
| "EXCEPTION EXCLUSIVE EXIT EXTEND EXTERNAL " + | ||
| "EXTERNALLY-DESCRIBED-KEY FD FETCH FILE FILE-CONTROL " + | ||
| "FILE-STREAM FILES FILLER FINAL FIND " + | ||
| "FINISH FIRST FOOTING FOR FOREGROUND-COLOR " + | ||
| "FOREGROUND-COLOUR FORMAT FREE FROM FULL " + | ||
| "FUNCTION GENERATE GET GIVING GLOBAL " + | ||
| "GO GOBACK GREATER GROUP HEADING " + | ||
| "HIGH-VALUE HIGH-VALUES HIGHLIGHT I-O I-O-CONTROL " + | ||
| "ID IDENTIFICATION IF IN INDEX " + | ||
| "INDEX-1 INDEX-2 INDEX-3 INDEX-4 INDEX-5 " + | ||
| "INDEX-6 INDEX-7 INDEX-8 INDEX-9 INDEXED " + | ||
| "INDIC INDICATE INDICATOR INDICATORS INITIAL " + | ||
| "INITIALIZE INITIATE INPUT INPUT-OUTPUT INSPECT " + | ||
| "INSTALLATION INTO INVALID INVOKE IS " + | ||
| "JUST JUSTIFIED KANJI KEEP KEY " + | ||
| "LABEL LAST LD LEADING LEFT " + | ||
| "LEFT-JUSTIFY LENGTH LENGTH-CHECK LESS LIBRARY " + | ||
| "LIKE LIMIT LIMITS LINAGE LINAGE-COUNTER " + | ||
| "LINE LINE-COUNTER LINES LINKAGE LOCAL-STORAGE " + | ||
| "LOCALE LOCALLY LOCK " + | ||
| "MEMBER MEMORY MERGE MESSAGE METACLASS " + | ||
| "MODE MODIFIED MODIFY MODULES MOVE " + | ||
| "MULTIPLE MULTIPLY NATIONAL NATIVE NEGATIVE " + | ||
| "NEXT NO NO-ECHO NONE NOT " + | ||
| "NULL NULL-KEY-MAP NULL-MAP NULLS NUMBER " + | ||
| "NUMERIC NUMERIC-EDITED OBJECT OBJECT-COMPUTER OCCURS " + | ||
| "OF OFF OMITTED ON ONLY " + | ||
| "OPEN OPTIONAL OR ORDER ORGANIZATION " + | ||
| "OTHER OUTPUT OVERFLOW OWNER PACKED-DECIMAL " + | ||
| "PADDING PAGE PAGE-COUNTER PARSE PERFORM " + | ||
| "PF PH PIC PICTURE PLUS " + | ||
| "POINTER POSITION POSITIVE PREFIX PRESENT " + | ||
| "PRINTING PRIOR PROCEDURE PROCEDURE-POINTER PROCEDURES " + | ||
| "PROCEED PROCESS PROCESSING PROGRAM PROGRAM-ID " + | ||
| "PROMPT PROTECTED PURGE QUEUE QUOTE " + | ||
| "QUOTES RANDOM RD READ READY " + | ||
| "REALM RECEIVE RECONNECT RECORD RECORD-NAME " + | ||
| "RECORDS RECURSIVE REDEFINES REEL REFERENCE " + | ||
| "REFERENCE-MONITOR REFERENCES RELATION RELATIVE RELEASE " + | ||
| "REMAINDER REMOVAL RENAMES REPEATED REPLACE " + | ||
| "REPLACING REPORT REPORTING REPORTS REPOSITORY " + | ||
| "REQUIRED RERUN RESERVE RESET RETAINING " + | ||
| "RETRIEVAL RETURN RETURN-CODE RETURNING REVERSE-VIDEO " + | ||
| "REVERSED REWIND REWRITE RF RH " + | ||
| "RIGHT RIGHT-JUSTIFY ROLLBACK ROLLING ROUNDED " + | ||
| "RUN SAME SCREEN SD SEARCH " + | ||
| "SECTION SECURE SECURITY SEGMENT SEGMENT-LIMIT " + | ||
| "SELECT SEND SENTENCE SEPARATE SEQUENCE " + | ||
| "SEQUENTIAL SET SHARED SIGN SIZE " + | ||
| "SKIP1 SKIP2 SKIP3 SORT SORT-MERGE " + | ||
| "SORT-RETURN SOURCE SOURCE-COMPUTER SPACE-FILL " + | ||
| "SPECIAL-NAMES STANDARD STANDARD-1 STANDARD-2 " + | ||
| "START STARTING STATUS STOP STORE " + | ||
| "STRING SUB-QUEUE-1 SUB-QUEUE-2 SUB-QUEUE-3 SUB-SCHEMA " + | ||
| "SUBFILE SUBSTITUTE SUBTRACT SUM SUPPRESS " + | ||
| "SYMBOLIC SYNC SYNCHRONIZED SYSIN SYSOUT " + | ||
| "TABLE TALLYING TAPE TENANT TERMINAL " + | ||
| "TERMINATE TEST TEXT THAN THEN " + | ||
| "THROUGH THRU TIME TIMES TITLE " + | ||
| "TO TOP TRAILING TRAILING-SIGN TRANSACTION " + | ||
| "TYPE TYPEDEF UNDERLINE UNEQUAL UNIT " + | ||
| "UNSTRING UNTIL UP UPDATE UPON " + | ||
| "USAGE USAGE-MODE USE USING VALID " + | ||
| "VALIDATE VALUE VALUES VARYING VLR " + | ||
| "WAIT WHEN WHEN-COMPILED WITH WITHIN " + | ||
| "WORDS WORKING-STORAGE WRITE XML XML-CODE " + | ||
| "XML-EVENT XML-NTEXT XML-TEXT ZERO ZERO-FILL " ); | ||
|
|
||
| var builtins = makeKeywords("- * ** / + < <= = > >= "); | ||
| var tests = { | ||
| digit: /\d/, | ||
| digit_or_colon: /[\d:]/, | ||
| hex: /[0-9a-f]/i, | ||
| sign: /[+-]/, | ||
| exponent: /e/i, | ||
| keyword_char: /[^\s\(\[\;\)\]]/, | ||
| symbol: /[\w*+\-]/ | ||
| }; | ||
| function isNumber(ch, stream){ | ||
| // hex | ||
| if ( ch === '0' && stream.eat(/x/i) ) { | ||
| stream.eatWhile(tests.hex); | ||
| return true; | ||
| } | ||
| // leading sign | ||
| if ( ( ch == '+' || ch == '-' ) && ( tests.digit.test(stream.peek()) ) ) { | ||
| stream.eat(tests.sign); | ||
| ch = stream.next(); | ||
| } | ||
| if ( tests.digit.test(ch) ) { | ||
| stream.eat(ch); | ||
| stream.eatWhile(tests.digit); | ||
| if ( '.' == stream.peek()) { | ||
| stream.eat('.'); | ||
| stream.eatWhile(tests.digit); | ||
| } | ||
| if ( stream.eat(tests.exponent) ) { | ||
| stream.eat(tests.sign); | ||
| stream.eatWhile(tests.digit); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| return { | ||
| startState: function () { | ||
| return { | ||
| indentStack: null, | ||
| indentation: 0, | ||
| mode: false | ||
| }; | ||
| }, | ||
| token: function (stream, state) { | ||
| if (state.indentStack == null && stream.sol()) { | ||
| // update indentation, but only if indentStack is empty | ||
| state.indentation = 6 ; //stream.indentation(); | ||
| } | ||
| // skip spaces | ||
| if (stream.eatSpace()) { | ||
| return null; | ||
| } | ||
| var returnType = null; | ||
| switch(state.mode){ | ||
| case "string": // multi-line string parsing mode | ||
| var next = false; | ||
| while ((next = stream.next()) != null) { | ||
| if (next == "\"" || next == "\'") { | ||
| state.mode = false; | ||
| break; | ||
| } | ||
| } | ||
| returnType = STRING; // continue on in string mode | ||
| break; | ||
| default: // default parsing mode | ||
| var ch = stream.next(); | ||
| var col = stream.column(); | ||
| if (col >= 0 && col <= 5) { | ||
| returnType = COBOLLINENUM; | ||
| } else if (col >= 72 && col <= 79) { | ||
| stream.skipToEnd(); | ||
| returnType = MODTAG; | ||
| } else if (ch == "*" && col == 6) { // comment | ||
| stream.skipToEnd(); // rest of the line is a comment | ||
| returnType = COMMENT; | ||
| } else if (ch == "\"" || ch == "\'") { | ||
| state.mode = "string"; | ||
| returnType = STRING; | ||
| } else if (ch == "'" && !( tests.digit_or_colon.test(stream.peek()) )) { | ||
| returnType = ATOM; | ||
| } else if (ch == ".") { | ||
| returnType = PERIOD; | ||
| } else if (isNumber(ch,stream)){ | ||
| returnType = NUMBER; | ||
| } else { | ||
| if (stream.current().match(tests.symbol)) { | ||
| while (col < 71) { | ||
| if (stream.eat(tests.symbol) === undefined) { | ||
| break; | ||
| } else { | ||
| col++; | ||
| } | ||
| } | ||
| } | ||
| if (keywords && keywords.propertyIsEnumerable(stream.current().toUpperCase())) { | ||
| returnType = KEYWORD; | ||
| } else if (builtins && builtins.propertyIsEnumerable(stream.current().toUpperCase())) { | ||
| returnType = BUILTIN; | ||
| } else if (atoms && atoms.propertyIsEnumerable(stream.current().toUpperCase())) { | ||
| returnType = ATOM; | ||
| } else returnType = null; | ||
| } | ||
| } | ||
| return returnType; | ||
| }, | ||
| indent: function (state) { | ||
| if (state.indentStack == null) return state.indentation; | ||
| return state.indentStack.indent; | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| CodeMirror.defineMIME("text/x-cobol", "cobol"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>CodeMirror: COBOL mode</title> | ||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="../../addon/edit/matchbrackets.js"></script> | ||
| <script src="cobol.js"></script> | ||
| <link rel="stylesheet" href="../../theme/neat.css"> | ||
| <link rel="stylesheet" href="../../theme/elegant.css"> | ||
| <link rel="stylesheet" href="../../theme/erlang-dark.css"> | ||
| <link rel="stylesheet" href="../../theme/night.css"> | ||
| <link rel="stylesheet" href="../../theme/monokai.css"> | ||
| <link rel="stylesheet" href="../../theme/cobalt.css"> | ||
| <link rel="stylesheet" href="../../theme/eclipse.css"> | ||
| <link rel="stylesheet" href="../../theme/rubyblue.css"> | ||
| <link rel="stylesheet" href="../../theme/lesser-dark.css"> | ||
| <link rel="stylesheet" href="../../theme/xq-dark.css"> | ||
| <link rel="stylesheet" href="../../theme/xq-light.css"> | ||
| <link rel="stylesheet" href="../../theme/ambiance.css"> | ||
| <link rel="stylesheet" href="../../theme/blackboard.css"> | ||
| <link rel="stylesheet" href="../../theme/vibrant-ink.css"> | ||
| <link rel="stylesheet" href="../../theme/solarized.css"> | ||
| <link rel="stylesheet" href="../../theme/twilight.css"> | ||
| <link rel="stylesheet" href="../../theme/midnight.css"> | ||
| <link rel="stylesheet" href="../../addon/dialog/dialog.css"> | ||
| <script src="../../addon/selection/active-line.js"></script> | ||
| <script src="../../addon/search/search.js"></script> | ||
| <script src="../../addon/dialog/dialog.js"></script> | ||
| <script src="../../addon/search/searchcursor.js"></script> | ||
| <style> | ||
| .CodeMirror { | ||
| border: 1px solid #eee; | ||
| font-size : 20px; | ||
| height : auto !important; | ||
| } | ||
| .CodeMirror-activeline-background {background: #555555 !important;} | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <p> Select Theme <select onchange="selectTheme()" id="selectTheme"> | ||
| <option>default</option> | ||
| <option>ambiance</option> | ||
| <option>blackboard</option> | ||
| <option>cobalt</option> | ||
| <option>eclipse</option> | ||
| <option>elegant</option> | ||
| <option>erlang-dark</option> | ||
| <option>lesser-dark</option> | ||
| <option>midnight</option> | ||
| <option>monokai</option> | ||
| <option>neat</option> | ||
| <option>night</option> | ||
| <option>rubyblue</option> | ||
| <option>solarized dark</option> | ||
| <option>solarized light</option> | ||
| <option selected>twilight</option> | ||
| <option>vibrant-ink</option> | ||
| <option>xq-dark</option> | ||
| <option>xq-light</option> | ||
| </select> Select Font Size <select onchange="selectFontsize()" id="selectFontSize"> | ||
| <option value="13px">13px</option> | ||
| <option value="14px">14px</option> | ||
| <option value="16px">16px</option> | ||
| <option value="18px">18px</option> | ||
| <option value="20px" selected="selected">20px</option> | ||
| <option value="24px">24px</option> | ||
| <option value="26px">26px</option> | ||
| <option value="28px">28px</option> | ||
| <option value="30px">30px</option> | ||
| <option value="32px">32px</option> | ||
| <option value="34px">34px</option> | ||
| <option value="36px">36px</option> | ||
| </select> | ||
| <label for="checkBoxReadOnly">Read-only</label> | ||
| <input type="checkbox" id="checkBoxReadOnly" onchange="selectReadOnly()"> | ||
| <label for="id_tabToIndentSpace">Insert Spaces on Tab</label> | ||
| <input type="checkbox" id="id_tabToIndentSpace" onchange="tabToIndentSpace()"> | ||
| </p> | ||
| <textarea id="code" name="code"> | ||
| ---------1---------2---------3---------4---------5---------6---------7---------8 | ||
| 12345678911234567892123456789312345678941234567895123456789612345678971234567898 | ||
| 000010 IDENTIFICATION DIVISION. MODTGHERE | ||
| 000020 PROGRAM-ID. SAMPLE. | ||
| 000030 AUTHOR. TEST SAM. | ||
| 000040 DATE-WRITTEN. 5 February 2013 | ||
| 000041 | ||
| 000042* A sample program just to show the form. | ||
| 000043* The program copies its input to the output, | ||
| 000044* and counts the number of records. | ||
| 000045* At the end this number is printed. | ||
| 000046 | ||
| 000050 ENVIRONMENT DIVISION. | ||
| 000060 INPUT-OUTPUT SECTION. | ||
| 000070 FILE-CONTROL. | ||
| 000080 SELECT STUDENT-FILE ASSIGN TO SYSIN | ||
| 000090 ORGANIZATION IS LINE SEQUENTIAL. | ||
| 000100 SELECT PRINT-FILE ASSIGN TO SYSOUT | ||
| 000110 ORGANIZATION IS LINE SEQUENTIAL. | ||
| 000120 | ||
| 000130 DATA DIVISION. | ||
| 000140 FILE SECTION. | ||
| 000150 FD STUDENT-FILE | ||
| 000160 RECORD CONTAINS 43 CHARACTERS | ||
| 000170 DATA RECORD IS STUDENT-IN. | ||
| 000180 01 STUDENT-IN PIC X(43). | ||
| 000190 | ||
| 000200 FD PRINT-FILE | ||
| 000210 RECORD CONTAINS 80 CHARACTERS | ||
| 000220 DATA RECORD IS PRINT-LINE. | ||
| 000230 01 PRINT-LINE PIC X(80). | ||
| 000240 | ||
| 000250 WORKING-STORAGE SECTION. | ||
| 000260 01 DATA-REMAINS-SWITCH PIC X(2) VALUE SPACES. | ||
| 000261 01 RECORDS-WRITTEN PIC 99. | ||
| 000270 | ||
| 000280 01 DETAIL-LINE. | ||
| 000290 05 FILLER PIC X(7) VALUE SPACES. | ||
| 000300 05 RECORD-IMAGE PIC X(43). | ||
| 000310 05 FILLER PIC X(30) VALUE SPACES. | ||
| 000311 | ||
| 000312 01 SUMMARY-LINE. | ||
| 000313 05 FILLER PIC X(7) VALUE SPACES. | ||
| 000314 05 TOTAL-READ PIC 99. | ||
| 000315 05 FILLER PIC X VALUE SPACE. | ||
| 000316 05 FILLER PIC X(17) | ||
| 000317 VALUE 'Records were read'. | ||
| 000318 05 FILLER PIC X(53) VALUE SPACES. | ||
| 000319 | ||
| 000320 PROCEDURE DIVISION. | ||
| 000321 | ||
| 000330 PREPARE-SENIOR-REPORT. | ||
| 000340 OPEN INPUT STUDENT-FILE | ||
| 000350 OUTPUT PRINT-FILE. | ||
| 000351 MOVE ZERO TO RECORDS-WRITTEN. | ||
| 000360 READ STUDENT-FILE | ||
| 000370 AT END MOVE 'NO' TO DATA-REMAINS-SWITCH | ||
| 000380 END-READ. | ||
| 000390 PERFORM PROCESS-RECORDS | ||
| 000410 UNTIL DATA-REMAINS-SWITCH = 'NO'. | ||
| 000411 PERFORM PRINT-SUMMARY. | ||
| 000420 CLOSE STUDENT-FILE | ||
| 000430 PRINT-FILE. | ||
| 000440 STOP RUN. | ||
| 000450 | ||
| 000460 PROCESS-RECORDS. | ||
| 000470 MOVE STUDENT-IN TO RECORD-IMAGE. | ||
| 000480 MOVE DETAIL-LINE TO PRINT-LINE. | ||
| 000490 WRITE PRINT-LINE. | ||
| 000500 ADD 1 TO RECORDS-WRITTEN. | ||
| 000510 READ STUDENT-FILE | ||
| 000520 AT END MOVE 'NO' TO DATA-REMAINS-SWITCH | ||
| 000530 END-READ. | ||
| 000540 | ||
| 000550 PRINT-SUMMARY. | ||
| 000560 MOVE RECORDS-WRITTEN TO TOTAL-READ. | ||
| 000570 MOVE SUMMARY-LINE TO PRINT-LINE. | ||
| 000571 WRITE PRINT-LINE. | ||
| 000572 | ||
| 000580 | ||
| </textarea> | ||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| lineNumbers: true, | ||
| matchBrackets: true, | ||
| mode: "text/x-cobol", | ||
| theme : "twilight", | ||
| styleActiveLine: true, | ||
| showCursorWhenSelecting : true, | ||
| }); | ||
| function selectTheme() { | ||
| var themeInput = document.getElementById("selectTheme"); | ||
| var theme = themeInput.options[themeInput.selectedIndex].innerHTML; | ||
| editor.setOption("theme", theme); | ||
| } | ||
| function selectFontsize() { | ||
| var fontSizeInput = document.getElementById("selectFontSize"); | ||
| var fontSize = fontSizeInput.options[fontSizeInput.selectedIndex].innerHTML; | ||
| editor.getWrapperElement().style["font-size"] = fontSize; | ||
| editor.refresh(); | ||
| } | ||
| function selectReadOnly() { | ||
| editor.setOption("readOnly", document.getElementById("checkBoxReadOnly").checked); | ||
| } | ||
| function tabToIndentSpace() { | ||
| if (document.getElementById("id_tabToIndentSpace").checked) { | ||
| editor.setOption("extraKeys", {Tab: function(cm) { cm.replaceSelection(" ", "end"); }}); | ||
| } else { | ||
| editor.setOption("extraKeys", {Tab: function(cm) { cm.replaceSelection(" ", "end"); }}); | ||
| } | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| (function() { | ||
| "use strict"; | ||
|
|
||
| // full haml mode. This handled embeded ruby and html fragments too | ||
| CodeMirror.defineMode("haml", function(config) { | ||
| var htmlMode = CodeMirror.getMode(config, {name: "htmlmixed"}); | ||
| var rubyMode = CodeMirror.getMode(config, "ruby"); | ||
|
|
||
| function rubyInQuote(endQuote) { | ||
| return function(stream, state) { | ||
| var ch = stream.peek(); | ||
| if (ch == endQuote && state.rubyState.tokenize.length == 1) { | ||
| // step out of ruby context as it seems to complete processing all the braces | ||
| stream.next(); | ||
| state.tokenize = html; | ||
| return "closeAttributeTag"; | ||
| } else { | ||
| return ruby(stream, state); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| function ruby(stream, state) { | ||
| if (stream.match("-#")) { | ||
| stream.skipToEnd(); | ||
| return "comment"; | ||
| } | ||
| return rubyMode.token(stream, state.rubyState); | ||
| } | ||
|
|
||
| function html(stream, state) { | ||
| var ch = stream.peek(); | ||
|
|
||
| // handle haml declarations. All declarations that cant be handled here | ||
| // will be passed to html mode | ||
| if (state.previousToken.style == "comment" ) { | ||
| if (state.indented > state.previousToken.indented) { | ||
| stream.skipToEnd(); | ||
| return "commentLine"; | ||
| } | ||
| } | ||
|
|
||
| if (state.startOfLine) { | ||
| if (ch == "!" && stream.match("!!")) { | ||
| stream.skipToEnd(); | ||
| return "tag"; | ||
| } else if (stream.match(/^%[\w:#\.]+=/)) { | ||
| state.tokenize = ruby; | ||
| return "hamlTag"; | ||
| } else if (stream.match(/^%[\w:]+/)) { | ||
| return "hamlTag"; | ||
| } else if (ch == "/" ) { | ||
| stream.skipToEnd(); | ||
| return "comment"; | ||
| } | ||
| } | ||
|
|
||
| if (state.startOfLine || state.previousToken.style == "hamlTag") { | ||
| if ( ch == "#" || ch == ".") { | ||
| stream.match(/[\w-#\.]*/); | ||
| return "hamlAttribute"; | ||
| } | ||
| } | ||
|
|
||
| // donot handle --> as valid ruby, make it HTML close comment instead | ||
| if (state.startOfLine && !stream.match("-->", false) && (ch == "=" || ch == "-" )) { | ||
| state.tokenize = ruby; | ||
| return null; | ||
| } | ||
|
|
||
| if (state.previousToken.style == "hamlTag" || | ||
| state.previousToken.style == "closeAttributeTag" || | ||
| state.previousToken.style == "hamlAttribute") { | ||
| if (ch == "(") { | ||
| state.tokenize = rubyInQuote(")"); | ||
| return null; | ||
| } else if (ch == "{") { | ||
| state.tokenize = rubyInQuote("}"); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| return htmlMode.token(stream, state.htmlState); | ||
| } | ||
|
|
||
| return { | ||
| // default to html mode | ||
| startState: function() { | ||
| var htmlState = htmlMode.startState(); | ||
| var rubyState = rubyMode.startState(); | ||
| return { | ||
| htmlState: htmlState, | ||
| rubyState: rubyState, | ||
| indented: 0, | ||
| previousToken: { style: null, indented: 0}, | ||
| tokenize: html | ||
| }; | ||
| }, | ||
|
|
||
| copyState: function(state) { | ||
| return { | ||
| htmlState : CodeMirror.copyState(htmlMode, state.htmlState), | ||
| rubyState: CodeMirror.copyState(rubyMode, state.rubyState), | ||
| indented: state.indented, | ||
| previousToken: state.previousToken, | ||
| tokenize: state.tokenize | ||
| }; | ||
| }, | ||
|
|
||
| token: function(stream, state) { | ||
| if (stream.sol()) { | ||
| state.indented = stream.indentation(); | ||
| state.startOfLine = true; | ||
| } | ||
| if (stream.eatSpace()) return null; | ||
| var style = state.tokenize(stream, state); | ||
| state.startOfLine = false; | ||
| // dont record comment line as we only want to measure comment line with | ||
| // the opening comment block | ||
| if (style && style != "commentLine") { | ||
| state.previousToken = { style: style, indented: state.indented }; | ||
| } | ||
| // if current state is ruby and the previous token is not `,` reset the | ||
| // tokenize to html | ||
| if (stream.eol() && state.tokenize == ruby) { | ||
| stream.backUp(1); | ||
| var ch = stream.peek(); | ||
| stream.next(); | ||
| if (ch && ch != ",") { | ||
| state.tokenize = html; | ||
| } | ||
| } | ||
| // reprocess some of the specific style tag when finish setting previousToken | ||
| if (style == "hamlTag") { | ||
| style = "tag"; | ||
| } else if (style == "commentLine") { | ||
| style = "comment"; | ||
| } else if (style == "hamlAttribute") { | ||
| style = "attribute"; | ||
| } else if (style == "closeAttributeTag") { | ||
| style = null; | ||
| } | ||
| return style; | ||
| }, | ||
|
|
||
| indent: function(state) { | ||
| return state.indented; | ||
| } | ||
| }; | ||
| }, "htmlmixed", "ruby"); | ||
|
|
||
| CodeMirror.defineMIME("text/x-haml", "haml"); | ||
| })(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>CodeMirror: HAML mode</title> | ||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="../xml/xml.js"></script> | ||
| <script src="../htmlmixed/htmlmixed.js"></script> | ||
| <script src="../javascript/javascript.js"></script> | ||
| <script src="../ruby/ruby.js"></script> | ||
| <script src="haml.js"></script> | ||
| <style>.CodeMirror {background: #f8f8f8;}</style> | ||
| <link rel="stylesheet" href="../../doc/docs.css"> | ||
| </head> | ||
| <body> | ||
| <h1>CodeMirror: HAML mode</h1> | ||
| <form><textarea id="code" name="code"> | ||
| !!! | ||
| #content | ||
| .left.column(title="title"){:href => "/hello", :test => "#{hello}_#{world}"} | ||
| <!-- This is a comment --> | ||
| %h2 Welcome to our site! | ||
| %p= puts "HAML MODE" | ||
| .right.column | ||
| = render :partial => "sidebar" | ||
|
|
||
| .container | ||
| .row | ||
| .span8 | ||
| %h1.title= @page_title | ||
| %p.title= @page_title | ||
| %p | ||
| / | ||
| The same as HTML comment | ||
| Hello multiline comment | ||
|
|
||
| -# haml comment | ||
| This wont be displayed | ||
| nor will this | ||
| Date/Time: | ||
| - now = DateTime.now | ||
| %strong= now | ||
| - if now > DateTime.parse("December 31, 2006") | ||
| = "Happy new " + "year!" | ||
|
|
||
| %title | ||
| = @title | ||
| \= @title | ||
| <h1>Title</h1> | ||
| <h1 title="HELLO"> | ||
| Title | ||
| </h1> | ||
| </textarea></form> | ||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| lineNumbers: true, | ||
| mode: "text/x-haml" | ||
| }); | ||
| </script> | ||
|
|
||
| <p><strong>MIME types defined:</strong> <code>text/x-haml</code>.</p> | ||
|
|
||
| <p><strong>Parsing/Highlighting Tests:</strong> <a href="../../test/index.html#haml_*">normal</a>, <a href="../../test/index.html#verbose,haml_*">verbose</a>.</p> | ||
|
|
||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| (function() { | ||
| var mode = CodeMirror.getMode({tabSize: 4}, "haml"); | ||
| function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } | ||
|
|
||
| // Requires at least one media query | ||
| MT("elementName", | ||
| "[tag %h1] Hey There"); | ||
|
|
||
| MT("oneElementPerLine", | ||
| "[tag %h1] Hey There %h2"); | ||
|
|
||
| MT("idSelector", | ||
| "[tag %h1][attribute #test] Hey There"); | ||
|
|
||
| MT("classSelector", | ||
| "[tag %h1][attribute .hello] Hey There"); | ||
|
|
||
| MT("docType", | ||
| "[tag !!! XML]"); | ||
|
|
||
| MT("comment", | ||
| "[comment / Hello WORLD]"); | ||
|
|
||
| MT("notComment", | ||
| "[tag %h1] This is not a / comment "); | ||
|
|
||
| MT("attributes", | ||
| "[tag %a]([variable title][operator =][string \"test\"]){[atom :title] [operator =>] [string \"test\"]}"); | ||
|
|
||
| MT("htmlCode", | ||
| "[tag <h1>]Title[tag </h1>]"); | ||
|
|
||
| MT("rubyBlock", | ||
| "[operator =][variable-2 @item]"); | ||
|
|
||
| MT("selectorRubyBlock", | ||
| "[tag %a.selector=] [variable-2 @item]"); | ||
|
|
||
| MT("nestedRubyBlock", | ||
| "[tag %a]", | ||
| " [operator =][variable puts] [string \"test\"]"); | ||
|
|
||
| MT("multilinePlaintext", | ||
| "[tag %p]", | ||
| " Hello,", | ||
| " World"); | ||
|
|
||
| MT("multilineRuby", | ||
| "[tag %p]", | ||
| " [comment -# this is a comment]", | ||
| " [comment and this is a comment too]", | ||
| " Date/Time", | ||
| " [operator -] [variable now] [operator =] [tag DateTime][operator .][variable now]", | ||
| " [tag %strong=] [variable now]", | ||
| " [operator -] [keyword if] [variable now] [operator >] [tag DateTime][operator .][variable parse]([string \"December 31, 2006\"])", | ||
| " [operator =][string \"Happy\"]", | ||
| " [operator =][string \"Belated\"]", | ||
| " [operator =][string \"Birthday\"]"); | ||
|
|
||
| MT("multilineComment", | ||
| "[comment /]", | ||
| " [comment Multiline]", | ||
| " [comment Comment]"); | ||
|
|
||
| MT("hamlComment", | ||
| "[comment -# this is a comment]"); | ||
|
|
||
| MT("multilineHamlComment", | ||
| "[comment -# this is a comment]", | ||
| " [comment and this is a comment too]"); | ||
|
|
||
| MT("multilineHTMLComment", | ||
| "[comment <!--]", | ||
| " [comment what a comment]", | ||
| " [comment -->]"); | ||
|
|
||
| MT("hamlAfterRubyTag", | ||
| "[attribute .block]", | ||
| " [tag %strong=] [variable now]", | ||
| " [attribute .test]", | ||
| " [operator =][variable now]", | ||
| " [attribute .right]"); | ||
|
|
||
| MT("stretchedRuby", | ||
| "[operator =] [variable puts] [string \"Hello\"],", | ||
| " [string \"World\"]"); | ||
|
|
||
| MT("interpolationInHashAttribute", | ||
| //"[tag %div]{[atom :id] [operator =>] [string \"#{][variable test][string }_#{][variable ting][string }\"]} test"); | ||
| "[tag %div]{[atom :id] [operator =>] [string \"#{][variable test][string }_#{][variable ting][string }\"]} test"); | ||
|
|
||
| MT("interpolationInHTMLAttribute", | ||
| "[tag %div]([variable title][operator =][string \"#{][variable test][string }_#{][variable ting]()[string }\"]) Test"); | ||
| })(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| namespace = "comment_"; | ||
|
|
||
| (function() { | ||
| function test(name, mode, run, before, after) { | ||
| return testCM(name, function(cm) { | ||
| run(cm); | ||
| eq(cm.getValue(), after); | ||
| }, {value: before, mode: mode}); | ||
| } | ||
|
|
||
| var simpleProg = "function foo() {\n return bar;\n}"; | ||
|
|
||
| test("block", "javascript", function(cm) { | ||
| cm.blockComment(Pos(0, 3), Pos(3, 0), {blockCommentLead: " *"}); | ||
| }, simpleProg + "\n", "/* function foo() {\n * return bar;\n * }\n */"); | ||
|
|
||
| test("blockToggle", "javascript", function(cm) { | ||
| cm.blockComment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"}); | ||
| cm.uncomment(Pos(0, 3), Pos(2, 0), {blockCommentLead: " *"}); | ||
| }, simpleProg, simpleProg); | ||
|
|
||
| test("line", "javascript", function(cm) { | ||
| cm.lineComment(Pos(1, 1), Pos(1, 1)); | ||
| }, simpleProg, "function foo() {\n// return bar;\n}"); | ||
|
|
||
| test("lineToggle", "javascript", function(cm) { | ||
| cm.lineComment(Pos(0, 0), Pos(2, 1)); | ||
| cm.uncomment(Pos(0, 0), Pos(2, 1)); | ||
| }, simpleProg, simpleProg); | ||
|
|
||
| test("fallbackToBlock", "css", function(cm) { | ||
| cm.lineComment(Pos(0, 0), Pos(2, 1)); | ||
| }, "html {\n border: none;\n}", "/* html {\n border: none;\n} */"); | ||
|
|
||
| test("fallbackToLine", "ruby", function(cm) { | ||
| cm.blockComment(Pos(0, 0), Pos(1)); | ||
| }, "def blah()\n return hah\n", "# def blah()\n# return hah\n"); | ||
|
|
||
| test("commentRange", "javascript", function(cm) { | ||
| cm.blockComment(Pos(1, 2), Pos(1, 13), {fullLines: false}); | ||
| }, simpleProg, "function foo() {\n /*return bar;*/\n}"); | ||
|
|
||
| test("indented", "javascript", function(cm) { | ||
| cm.lineComment(Pos(1, 0), Pos(2), {indent: true}); | ||
| }, simpleProg, "function foo() {\n // return bar;\n // }"); | ||
| })(); |