Skip to content

Commit

Permalink
Add support for GEDCOM. Fix #899 (#1385)
Browse files Browse the repository at this point in the history
  • Loading branch information
Golmote authored Apr 11, 2018
1 parent c673ec2 commit 6e0b20a
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@
"title": "Fortran",
"owner": "Golmote"
},
"gedcom": {
"title": "GEDCOM",
"owner": "Golmote"
},
"gherkin": {
"title": "Gherkin",
"owner": "hason"
Expand Down
28 changes: 28 additions & 0 deletions components/prism-gedcom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Prism.languages.gedcom = {
'line-value': {
// Preceded by level, optional pointer, and tag
pattern: /(^\s*\d+ +(?:@\w[\w!"$%&'()*+,\-./:;<=>?[\\\]^`{|}~\x80-\xfe #]*@ +)?\w+ +).+/m,
lookbehind: true,
inside: {
'pointer': {
pattern: /^@\w[\w!"$%&'()*+,\-./:;<=>?[\\\]^`{|}~\x80-\xfe #]*@$/,
alias: 'variable'
}
}
},
'tag': {
// Preceded by level and optional pointer
pattern: /(^\s*\d+ +(?:@\w[\w!"$%&'()*+,\-./:;<=>?[\\\]^`{|}~\x80-\xfe #]*@ +)?)\w+/m,
lookbehind: true,
alias: 'string'
},
'level': {
pattern: /(^\s*)\d+/m,
lookbehind: true,
alias: 'number'
},
'pointer': {
pattern: /@\w[\w!"$%&'()*+,\-./:;<=>?[\\\]^`{|}~\x80-\xfe #]*@/,
alias: 'variable'
}
};
1 change: 1 addition & 0 deletions components/prism-gedcom.min.js

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

50 changes: 50 additions & 0 deletions examples/prism-gedcom.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<h2>Full example</h2>
<pre><code>0 HEAD
1 CHAR ASCII
1 SOUR ID_OF_CREATING_FILE
1 GEDC
2 VERS 5.5
2 FORM Lineage-Linked
1 SUBM @SUBMITTER@
0 @SUBMITTER@ SUBM
1 NAME /Submitter/
1 ADDR Submitters address
2 CONT address continued here
0 @FATHER@ INDI
1 NAME /Father/
1 SEX M
1 BIRT
2 PLAC birth place
2 DATE 1 JAN 1899
1 DEAT
2 PLAC death place
2 DATE 31 DEC 1990
1 FAMS @FAMILY@
0 @MOTHER@ INDI
1 NAME /Mother/
1 SEX F
1 BIRT
2 PLAC birth place
2 DATE 1 JAN 1899
1 DEAT
2 PLAC death place
2 DATE 31 DEC 1990
1 FAMS @FAMILY@
0 @CHILD@ INDI
1 NAME /Child/
1 BIRT
2 PLAC birth place
2 DATE 31 JUL 1950
1 DEAT
2 PLAC death place
2 DATE 29 FEB 2000
1 FAMC @FAMILY@
0 @FAMILY@ FAM
1 MARR
2 PLAC marriage place
2 DATE 1 APR 1950
1 HUSB @FATHER@
1 WIFE @MOTHER@
1 CHIL @CHILD@
0 TRLR
</code></pre>
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -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","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","erb":"ERB","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","markup-templating":"Markup templating","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","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","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","visual-basic":"Visual Basic","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","erb":"ERB","fsharp":"F#","gedcom":"GEDCOM","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","markup-templating":"Markup templating","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","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","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","visual-basic":"Visual Basic","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)) {
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.

20 changes: 20 additions & 0 deletions tests/languages/gedcom/level_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
0 HEAD
1 CHAR ASCII
99 FOO bar

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

[
["level", "0"],
["tag", "HEAD"],
["level", "1"],
["tag", "CHAR"],
["line-value", ["ASCII"]],
["level", "99"],
["tag", "FOO"],
["line-value", ["bar"]]
]

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

Checks for levels.
29 changes: 29 additions & 0 deletions tests/languages/gedcom/line-value_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
1 CHIL @CHILD1@
2 PLAC ÁĆÉǴÍ,ḰĹḾŃÓ,ṔŔŚÚẂ,ÝŹáćé,ǵíḱĺḿ,ńóṕŕś,úẃýź
1 NAME code: 0313/COMMA ABOVE/
2 DATE @#DGREGORIAN@ 31 DEC 1997
2 CONT Copyright gedcom@@gedcom.org

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

[
["level", "1"],
["tag", "CHIL"],
["line-value", [["pointer", "@CHILD1@"]]],
["level", "2"],
["tag", "PLAC"],
["line-value", ["ÁĆÉǴÍ,ḰĹḾŃÓ,ṔŔŚÚẂ,ÝŹáćé,ǵíḱĺḿ,ńóṕŕś,úẃýź"]],
["level", "1"],
["tag", "NAME"],
["line-value", ["code: 0313/COMMA ABOVE/"]],
["level", "2"],
["tag", "DATE"],
["line-value", ["@#DGREGORIAN@ 31 DEC 1997"]],
["level", "2"],
["tag", "CONT"],
["line-value", ["Copyright gedcom@@gedcom.org"]]
]

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

Checks for line values.
23 changes: 23 additions & 0 deletions tests/languages/gedcom/pointer_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@f!@
@foo_Bar@
@_$!"$%&'()*+,-./:;<=>?[\]^`{|}~ #foobar@
0 @SUBMITTER@ SUBM
1 FAMS @FAMILY@

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

[
["pointer", "@f!@"],
["pointer", "@foo_Bar@"],
["pointer", "@_$!\"$%&'()*+,-./:;<=>?[\\]^`{|}~ #foobar@"],
["level", "0"],
["pointer", "@SUBMITTER@"],
["tag", "SUBM"],
["level", "1"],
["tag", "FAMS"],
["line-value", [["pointer", "@FAMILY@"]]]
]

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

Checks for pointers.
25 changes: 25 additions & 0 deletions tests/languages/gedcom/tag_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
0 HEAD
1 foo_bar
2 _
3 @pointer@ _Sometag42
4 247

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

[
["level", "0"],
["tag", "HEAD"],
["level", "1"],
["tag", "foo_bar"],
["level", "2"],
["tag", "_"],
["level", "3"],
["pointer", "@pointer@"],
["tag", "_Sometag42"],
["level", "4"],
["tag", "247"]
]

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

Checks for tags.

0 comments on commit 6e0b20a

Please sign in to comment.