Skip to content

Commit

Permalink
Added support for CSV (#2794)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment committed Mar 21, 2021
1 parent f84c49c commit f9b6952
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Expand Up @@ -287,6 +287,10 @@
"modify": "css",
"owner": "milesj"
},
"csv": {
"title": "CSV",
"owner": "RunDevelopment"
},
"cypher": {
"title": "Cypher",
"owner": "RunDevelopment"
Expand Down
6 changes: 6 additions & 0 deletions components/prism-csv.js
@@ -0,0 +1,6 @@
// https://tools.ietf.org/html/rfc4180

Prism.languages.csv = {
'value': /[^\r\n,"]+|"(?:[^"]|"")*"(?!")/,
'punctuation': /,/
};
1 change: 1 addition & 0 deletions components/prism-csv.min.js
@@ -0,0 +1 @@
Prism.languages.csv={value:/[^\r\n,"]+|"(?:[^"]|"")*"(?!")/,punctuation:/,/};
7 changes: 7 additions & 0 deletions examples/prism-csv.html
@@ -0,0 +1,7 @@
<h2>Full example</h2>
<pre><code>Year,Make,Model,Description,Price
1997,Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
1996,Jeep,Grand Cherokee,"MUST SELL!
air, moon roof, loaded",4799.00</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Expand Up @@ -59,6 +59,7 @@
"conc": "Concurnas",
"csp": "Content-Security-Policy",
"css-extras": "CSS Extras",
"csv": "CSV",
"dataweave": "DataWeave",
"dax": "DAX",
"django": "Django/Jinja2",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions tests/languages/csv/value.test
@@ -0,0 +1,99 @@
aaa,bbb,ccc
zzz,yyy,xxx

"aaa","bbb","ccc"

"aaa","b
bb","ccc"

"aaa","b""bb","ccc"

Year,Make,Model,Description,Price
1997,Ford,E350,"ac, abs, moon",3000.00
1999,Chevy,"Venture ""Extended Edition""","",4900.00
1999,Chevy,"Venture ""Extended Edition, Very Large""",,5000.00
1996,Jeep,Grand Cherokee,"MUST SELL!
air, moon roof, loaded",4799.00

----------------------------------------------------

[
["value", "aaa"],
["punctuation", ","],
["value", "bbb"],
["punctuation", ","],
["value", "ccc"],

["value", "zzz"],
["punctuation", ","],
["value", "yyy"],
["punctuation", ","],
["value", "xxx"],

["value", "\"aaa\""],
["punctuation", ","],
["value", "\"bbb\""],
["punctuation", ","],
["value", "\"ccc\""],

["value", "\"aaa\""],
["punctuation", ","],
["value", "\"b\r\nbb\""],
["punctuation", ","],
["value", "\"ccc\""],

["value", "\"aaa\""],
["punctuation", ","],
["value", "\"b\"\"bb\""],
["punctuation", ","],
["value", "\"ccc\""],

["value", "Year"],
["punctuation", ","],
["value", "Make"],
["punctuation", ","],
["value", "Model"],
["punctuation", ","],
["value", "Description"],
["punctuation", ","],
["value", "Price"],

["value", "1997"],
["punctuation", ","],
["value", "Ford"],
["punctuation", ","],
["value", "E350"],
["punctuation", ","],
["value", "\"ac, abs, moon\""],
["punctuation", ","],
["value", "3000.00"],

["value", "1999"],
["punctuation", ","],
["value", "Chevy"],
["punctuation", ","],
["value", "\"Venture \"\"Extended Edition\"\"\""],
["punctuation", ","],
["value", "\"\""],
["punctuation", ","],
["value", "4900.00"],

["value", "1999"],
["punctuation", ","],
["value", "Chevy"],
["punctuation", ","],
["value", "\"Venture \"\"Extended Edition, Very Large\"\"\""],
["punctuation", ","],
["punctuation", ","],
["value", "5000.00"],

["value", "1996"],
["punctuation", ","],
["value", "Jeep"],
["punctuation", ","],
["value", "Grand Cherokee"],
["punctuation", ","],
["value", "\"MUST SELL!\r\nair, moon roof, loaded\""],
["punctuation", ","],
["value", "4799.00"]
]

0 comments on commit f9b6952

Please sign in to comment.