From aff4790d30cfa15cf77e976fd63c6229700ca111 Mon Sep 17 00:00:00 2001 From: Golmote Date: Sat, 3 Mar 2018 22:25:59 +0100 Subject: [PATCH] Add support for ARFF (Fix #653) --- components.js | 4 ++ components/prism-arff.js | 10 ++++ components/prism-arff.min.js | 1 + examples/prism-arff.html | 49 +++++++++++++++++++ plugins/show-language/prism-show-language.js | 2 +- .../show-language/prism-show-language.min.js | 2 +- tests/languages/arff/comment_feature.test | 15 ++++++ tests/languages/arff/keyword_feature.test | 17 +++++++ tests/languages/arff/number_feature.test | 13 +++++ tests/languages/arff/string_feature.test | 13 +++++ 10 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 components/prism-arff.js create mode 100644 components/prism-arff.min.js create mode 100644 examples/prism-arff.html create mode 100644 tests/languages/arff/comment_feature.test create mode 100644 tests/languages/arff/keyword_feature.test create mode 100644 tests/languages/arff/number_feature.test create mode 100644 tests/languages/arff/string_feature.test diff --git a/components.js b/components.js index 4472716092..e0407d8060 100644 --- a/components.js +++ b/components.js @@ -95,6 +95,10 @@ var components = { "require": "cpp", "owner": "eisbehr-" }, + "arff": { + "title": "ARFF", + "owner": "Golmote" + }, "asciidoc": { "title": "AsciiDoc", "owner": "Golmote" diff --git a/components/prism-arff.js b/components/prism-arff.js new file mode 100644 index 0000000000..c13c22de39 --- /dev/null +++ b/components/prism-arff.js @@ -0,0 +1,10 @@ +Prism.languages.arff = { + 'comment': /%.*/, + 'string': { + pattern: /(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/, + greedy: true + }, + 'keyword': /@(?:attribute|data|end|relation)\b/i, + 'number': /\b\d+(?:\.\d+)?\b/, + 'punctuation': /[{},]/ +}; \ No newline at end of file diff --git a/components/prism-arff.min.js b/components/prism-arff.min.js new file mode 100644 index 0000000000..0cccb502f7 --- /dev/null +++ b/components/prism-arff.min.js @@ -0,0 +1 @@ +Prism.languages.arff={comment:/%.*/,string:{pattern:/(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,greedy:!0},keyword:/@(?:attribute|data|relation)\b/i,number:/\b\d+(?:\.\d+)?\b/,punctuation:/[{},]/}; \ No newline at end of file diff --git a/examples/prism-arff.html b/examples/prism-arff.html new file mode 100644 index 0000000000..1cc2eb29af --- /dev/null +++ b/examples/prism-arff.html @@ -0,0 +1,49 @@ +

ARFF

+

To use this language, use the class "language-arff".

+ +

Comments

+
%
+% Some comments
+%
+%
+ +

Keywords

+
@attribute
+@data
+@relation
+ +

Numbers

+
42
+0.14
+ +

Strings

+
'Single \'quoted\' string'
+"Double \"quoted\" string"
+ +

Full example

+
% 1. Title: Iris Plants Database
+%
+% 2. Sources:
+%      (a) Creator: R.A. Fisher
+%      (b) Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)
+%      (c) Date: July, 1988
+%
+@RELATION iris
+
+@ATTRIBUTE sepallength  NUMERIC
+@ATTRIBUTE sepalwidth   NUMERIC
+@ATTRIBUTE petallength  NUMERIC
+@ATTRIBUTE petalwidth   NUMERIC
+@ATTRIBUTE class        {Iris-setosa,Iris-versicolor,Iris-virginica}
+
+@DATA
+5.1,3.5,1.4,0.2,Iris-setosa
+4.9,3.0,1.4,0.2,Iris-setosa
+4.7,3.2,1.3,0.2,Iris-setosa
+4.6,3.1,1.5,0.2,Iris-setosa
+5.0,3.6,1.4,0.2,Iris-setosa
+5.4,3.9,1.7,0.4,Iris-setosa
+4.6,3.4,1.4,0.3,Iris-setosa
+5.0,3.4,1.5,0.2,Iris-setosa
+4.4,2.9,1.4,0.2,Iris-setosa
+4.9,3.1,1.5,0.1,Iris-setosa
diff --git a/plugins/show-language/prism-show-language.js b/plugins/show-language/prism-show-language.js index d2e6d1c31d..19e8e0f86d 100644 --- a/plugins/show-language/prism-show-language.js +++ b/plugins/show-language/prism-show-language.js @@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) { } // The languages map is built automatically with gulp -var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/; +var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","fsharp":"F#","glsl":"GLSL","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","xojo":"Xojo (REALbasic)","yaml":"YAML"}/*]*/; Prism.plugins.toolbar.registerButton('show-language', function(env) { var pre = env.element.parentNode; if (!pre || !/pre/i.test(pre.nodeName)) { diff --git a/plugins/show-language/prism-show-language.min.js b/plugins/show-language/prism-show-language.min.js index b281663698..214b1c763d 100644 --- a/plugins/show-language/prism-show-language.min.js +++ b/plugins/show-language/prism-show-language.min.js @@ -1 +1 @@ -!function(){if("undefined"!=typeof self&&self.Prism&&self.document){if(!Prism.plugins.toolbar)return console.warn("Show Languages plugin loaded before Toolbar plugin."),void 0;var e={html:"HTML",xml:"XML",svg:"SVG",mathml:"MathML",css:"CSS",clike:"C-like",javascript:"JavaScript",abap:"ABAP",actionscript:"ActionScript",apacheconf:"Apache Configuration",apl:"APL",applescript:"AppleScript",asciidoc:"AsciiDoc",asm6502:"6502 Assembly",aspnet:"ASP.NET (C#)",autohotkey:"AutoHotkey",autoit:"AutoIt",basic:"BASIC",csharp:"C#",cpp:"C++",coffeescript:"CoffeeScript",csp:"Content-Security-Policy","css-extras":"CSS Extras",django:"Django/Jinja2",fsharp:"F#",glsl:"GLSL",graphql:"GraphQL",http:"HTTP",hpkp:"HTTP Public-Key-Pins",hsts:"HTTP Strict-Transport-Security",ichigojam:"IchigoJam",inform7:"Inform 7",json:"JSON",latex:"LaTeX",livescript:"LiveScript",lolcode:"LOLCODE",matlab:"MATLAB",mel:"MEL",n4js:"N4JS",nasm:"NASM",nginx:"nginx",nsis:"NSIS",objectivec:"Objective-C",ocaml:"OCaml",opencl:"OpenCL",parigp:"PARI/GP",php:"PHP","php-extras":"PHP Extras",powershell:"PowerShell",properties:".properties",protobuf:"Protocol Buffers",jsx:"React JSX",tsx:"React TSX",renpy:"Ren'py",rest:"reST (reStructuredText)",sas:"SAS",sass:"Sass (Sass)",scss:"Sass (Scss)",sql:"SQL",typescript:"TypeScript",vbnet:"VB.Net",vhdl:"VHDL",vim:"vim",wiki:"Wiki markup",xojo:"Xojo (REALbasic)",yaml:"YAML"};Prism.plugins.toolbar.registerButton("show-language",function(t){var a=t.element.parentNode;if(a&&/pre/i.test(a.nodeName)){var s=a.getAttribute("data-language")||e[t.language]||t.language.substring(0,1).toUpperCase()+t.language.substring(1),i=document.createElement("span");return i.textContent=s,i}})}}(); \ No newline at end of file +!function(){if("undefined"!=typeof self&&self.Prism&&self.document){if(!Prism.plugins.toolbar)return console.warn("Show Languages plugin loaded before Toolbar plugin."),void 0;var e={html:"HTML",xml:"XML",svg:"SVG",mathml:"MathML",css:"CSS",clike:"C-like",javascript:"JavaScript",abap:"ABAP",actionscript:"ActionScript",apacheconf:"Apache Configuration",apl:"APL",applescript:"AppleScript",arff:"ARFF",asciidoc:"AsciiDoc",asm6502:"6502 Assembly",aspnet:"ASP.NET (C#)",autohotkey:"AutoHotkey",autoit:"AutoIt",basic:"BASIC",csharp:"C#",cpp:"C++",coffeescript:"CoffeeScript",csp:"Content-Security-Policy","css-extras":"CSS Extras",django:"Django/Jinja2",fsharp:"F#",glsl:"GLSL",graphql:"GraphQL",http:"HTTP",hpkp:"HTTP Public-Key-Pins",hsts:"HTTP Strict-Transport-Security",ichigojam:"IchigoJam",inform7:"Inform 7",json:"JSON",latex:"LaTeX",livescript:"LiveScript",lolcode:"LOLCODE",matlab:"MATLAB",mel:"MEL",n4js:"N4JS",nasm:"NASM",nginx:"nginx",nsis:"NSIS",objectivec:"Objective-C",ocaml:"OCaml",opencl:"OpenCL",parigp:"PARI/GP",php:"PHP","php-extras":"PHP Extras",powershell:"PowerShell",properties:".properties",protobuf:"Protocol Buffers",jsx:"React JSX",tsx:"React TSX",renpy:"Ren'py",rest:"reST (reStructuredText)",sas:"SAS",sass:"Sass (Sass)",scss:"Sass (Scss)",sql:"SQL",typescript:"TypeScript",vbnet:"VB.Net",vhdl:"VHDL",vim:"vim",wiki:"Wiki markup",xojo:"Xojo (REALbasic)",yaml:"YAML"};Prism.plugins.toolbar.registerButton("show-language",function(t){var a=t.element.parentNode;if(a&&/pre/i.test(a.nodeName)){var s=a.getAttribute("data-language")||e[t.language]||t.language.substring(0,1).toUpperCase()+t.language.substring(1),i=document.createElement("span");return i.textContent=s,i}})}}(); \ No newline at end of file diff --git a/tests/languages/arff/comment_feature.test b/tests/languages/arff/comment_feature.test new file mode 100644 index 0000000000..4d53a8e1b9 --- /dev/null +++ b/tests/languages/arff/comment_feature.test @@ -0,0 +1,15 @@ +% +% Some comment +% Comment " with ' quotes + +---------------------------------------------------- + +[ + ["comment", "%"], + ["comment", "% Some comment"], + ["comment", "% Comment \" with ' quotes"] +] + +---------------------------------------------------- + +Checks for comments. \ No newline at end of file diff --git a/tests/languages/arff/keyword_feature.test b/tests/languages/arff/keyword_feature.test new file mode 100644 index 0000000000..b1c98169ef --- /dev/null +++ b/tests/languages/arff/keyword_feature.test @@ -0,0 +1,17 @@ +@attribute +@data +@end +@relation + +---------------------------------------------------- + +[ + ["keyword", "@attribute"], + ["keyword", "@data"], + ["keyword", "@end"], + ["keyword", "@relation"] +] + +---------------------------------------------------- + +Checks for all keywords. \ No newline at end of file diff --git a/tests/languages/arff/number_feature.test b/tests/languages/arff/number_feature.test new file mode 100644 index 0000000000..99969b4de9 --- /dev/null +++ b/tests/languages/arff/number_feature.test @@ -0,0 +1,13 @@ +42 +0.14 + +---------------------------------------------------- + +[ + ["number", "42"], + ["number", "0.14"] +] + +---------------------------------------------------- + +Checks for numbers. \ No newline at end of file diff --git a/tests/languages/arff/string_feature.test b/tests/languages/arff/string_feature.test new file mode 100644 index 0000000000..c3178f17b1 --- /dev/null +++ b/tests/languages/arff/string_feature.test @@ -0,0 +1,13 @@ +"double quoted\"' % string" +'single quoted"\' % string' + +---------------------------------------------------- + +[ + ["string", "\"double quoted\\\"' % string\""], + ["string", "'single quoted\"\\' % string'"] +] + +---------------------------------------------------- + +Checks for strings. \ No newline at end of file