Skip to content

Commit 1d7a6d7

Browse files
committed
Add csv simple mode
1 parent 8ecfc73 commit 1d7a6d7

2 files changed

Lines changed: 77 additions & 0 deletions

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/csv</code>
47+
(CSV)
48+
</article>

0 commit comments

Comments
 (0)