Skip to content

Commit dbd11e3

Browse files
authored
Merge pull request #7 from hackmdio/feature/csv
2 parents 758dce5 + c4dcc3e commit dbd11e3

7 files changed

Lines changed: 82 additions & 1 deletion

File tree

mode/csv/csv.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(function(mod) {
2+
if (typeof exports == "object" && typeof module == "object") // CommonJS
3+
mod(require("../../lib/codemirror"), require("../../addon/mode/simple"));
4+
else if (typeof define == "function" && define.amd) // AMD
5+
define(["../../lib/codemirror", "../../addon/mode/simple"], mod);
6+
else // Plain browser env
7+
mod(CodeMirror);
8+
})(function(CodeMirror) {
9+
// Regex is taken from https://github.com/mechatroner/vscode_rainbow_csv/blob/master/syntaxes/csv.tmLanguage.json
10+
CodeMirror.defineSimpleMode('csv', {
11+
start: [
12+
{
13+
regex: /((?: *\"(?:[^\"]*\"\")*[^\"]*\" *(?:,|$))|(?:[^,]*(?:,|$)))?((?: *\"(?:[^\"]*\"\")*[^\"]*\" *(?:,|$))|(?:[^,]*(?:,|$)))?((?: *\"(?:[^\"]*\"\")*[^\"]*\" *(?:,|$))|(?:[^,]*(?:,|$)))?((?: *\"(?:[^\"]*\"\")*[^\"]*\" *(?:,|$))|(?:[^,]*(?:,|$)))?((?: *\"(?:[^\"]*\"\")*[^\"]*\" *(?:,|$))|(?:[^,]*(?:,|$)))?((?: *\"(?:[^\"]*\"\")*[^\"]*\" *(?:,|$))|(?:[^,]*(?:,|$)))?((?: *\"(?:[^\"]*\"\")*[^\"]*\" *(?:,|$))|(?:[^,]*(?:,|$)))?((?: *\"(?:[^\"]*\"\")*[^\"]*\" *(?:,|$))|(?:[^,]*(?:,|$)))?((?: *\"(?:[^\"]*\"\")*[^\"]*\" *(?:,|$))|(?:[^,]*(?:,|$)))?((?: *\"(?:[^\"]*\"\")*[^\"]*\" *(?:,|$))|(?:[^,]*(?:,|$)))?/,
14+
token: [
15+
"variable",
16+
"variable-2",
17+
"variable-3",
18+
"operator",
19+
"keyword",
20+
"variable",
21+
"variable-2",
22+
"variable-3",
23+
"operator",
24+
"keyword"
25+
]
26+
}
27+
]
28+
})
29+
})

mode/csv/index.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!doctype html>
2+
<title>CodeMirror: CSV mode</title>
3+
<meta charset="utf-8"/>
4+
<link rel=stylesheet href="../../doc/docs.css">
5+
6+
<link rel="stylesheet" href="../../lib/codemirror.css">
7+
<script src="../../lib/codemirror.js"></script>
8+
<script src="../../addon/mode/simple.js"></script>
9+
<script src="csv.js"></script>
10+
<style>.CodeMirror {border: 2px inset #dee;}</style>
11+
<div id=nav>
12+
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
13+
14+
<ul>
15+
<li><a href="../../index.html">Home</a>
16+
<li><a href="../../doc/manual.html">Manual</a>
17+
<li><a href="https://github.com/codemirror/codemirror">Code</a>
18+
</ul>
19+
<ul>
20+
<li><a href="../index.html">Language modes</a>
21+
<li><a class=active href="#">CSV</a>
22+
</ul>
23+
</div>
24+
25+
<article>
26+
<h2>CSV mode</h2>
27+
<form><textarea id="code" name="code">
28+
firstName,lastName,email,phoneNumber
29+
John,Doe,john@doe.com,0123456789
30+
Jane,Doe,jane@doe.com,9876543210
31+
James,Bond,james.bond@mi6.co.uk,0612345678
32+
</textarea></form>
33+
34+
<script>
35+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
36+
lineNumbers: true,
37+
indentUnit: 4,
38+
mode: "csv"
39+
});
40+
</script>
41+
42+
<p>
43+
Simple mode that handles CSV language.
44+
</p>
45+
46+
<p><strong>MIME type defined:</strong> <code>text/x-csv</code>
47+
(CSV)
48+
</article>

mode/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ <h2>Language modes</h2>
4444
<li><a href="commonlisp/index.html">Common Lisp</a></li>
4545
<li><a href="crystal/index.html">Crystal</a></li>
4646
<li><a href="css/index.html">CSS</a></li>
47+
<li><a href="csv/index.html">CSV</a></li>
4748
<li><a href="cypher/index.html">Cypher</a></li>
4849
<li><a href="python/index.html">Cython</a></li>
4950
<li><a href="d/index.html">D</a></li>

mode/meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
{name: "Cython", mime: "text/x-cython", mode: "python", ext: ["pyx", "pxd", "pxi"]},
3232
{name: "Crystal", mime: "text/x-crystal", mode: "crystal", ext: ["cr"]},
3333
{name: "CSS", mime: "text/css", mode: "css", ext: ["css"]},
34+
{name: "CSV", mime: "text/x-csv", mode: "csv", ext: ["csv"]},
3435
{name: "CQL", mime: "text/x-cassandra", mode: "sql", ext: ["cql"]},
3536
{name: "D", mime: "text/x-d", mode: "d", ext: ["d"]},
3637
{name: "Dart", mimes: ["application/dart", "text/x-dart"], mode: "dart", ext: ["dart"]},

mode/plantuml/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!doctype html>
2-
<title>CodeMirror: Pig Latin mode</title>
2+
<title>CodeMirror: PlantUML mode</title>
33
<meta charset="utf-8"/>
44
<link rel=stylesheet href="../../doc/docs.css">
55

release.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mode\ruby\ruby.js ^
4545
mode\rust\rust.js ^
4646
mode\python\python.js ^
4747
mode\plantuml\plantuml.js ^
48+
mode\csv\csv.js ^
4849
mode\shell\shell.js ^
4950
mode\php\php.js ^
5051
mode\sas\sas.js ^

release.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ mode/ruby/ruby.js \
5454
mode/rust/rust.js \
5555
mode/python/python.js \
5656
mode/plantuml/plantuml.js \
57+
mode/csv/csv.js \
5758
mode/shell/shell.js \
5859
mode/php/php.js \
5960
mode/sas/sas.js \

0 commit comments

Comments
 (0)