-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
770 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@rdfjs-elements/formats-pretty': patch | ||
--- | ||
|
||
Preserve line breaks when serialising Turtle and Trig (fixes #139) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { xsd } from '@tpluscode/rdf-ns-builders' | ||
import { shrink } from '@zazuko/prefixes' | ||
|
||
export class LongLiteral { | ||
constructor(term) { | ||
this.term = term | ||
} | ||
|
||
toTerm() { | ||
const raw = `"""${this.term.value.replace(/"$/, '\\"')}"""` | ||
|
||
return { | ||
terse: prefixes => raw + this.langOrDatatype(prefixes), | ||
verbose: prefixes => raw + this.langOrDatatype(prefixes), | ||
} | ||
} | ||
|
||
langOrDatatype(prefixes) { | ||
if (this.term.language) { | ||
return `@${this.term.language}` | ||
} | ||
|
||
if (this.term.datatype.equals(xsd.string)) { | ||
return '' | ||
} | ||
|
||
const shrunk = shrink(this.term.datatype.value, prefixes) | ||
if (!shrunk) { | ||
return `^^<${this.term.datatype.value}>` | ||
} | ||
|
||
return `^^${shrunk}` | ||
} | ||
} | ||
|
||
export const coercions = new Map([[LongLiteral, literal => literal.toTerm()]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
PREFIX ex: <http://example.org/> | ||
|
||
ex:a ex:b "The first line\nThe second line\n more" . | ||
|
||
ex:x ex:y "Long\ndescription\nwith datatype"^^ex:multiline . | ||
|
||
ex:m ex:n "multiline\nwith language"@en-US . | ||
|
||
ex:f ex:g "The first line\n\"The quoted line\"\n more" . | ||
|
||
ex:r ex:q "Quote\nat end\"" . |
48 changes: 48 additions & 0 deletions
48
packages/formats/test/serializers/__snapshots__/index.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`@rdfjs-elements/formats-pretty/serializers turtle preserves line breaks in literals 1`] = ` | ||
" | ||
<http://example.org/a> <http://example.org/b> \\"\\"\\"The first line | ||
The second line | ||
more\\"\\"\\" . | ||
<http://example.org/x> <http://example.org/y> \\"\\"\\"Long | ||
description | ||
with datatype\\"\\"\\"^^<http://example.org/multiline> . | ||
<http://example.org/m> <http://example.org/n> \\"\\"\\"multiline | ||
with language\\"\\"\\"@en-US . | ||
<http://example.org/f> <http://example.org/g> \\"\\"\\"The first line | ||
\\"The quoted line\\" | ||
more\\"\\"\\" . | ||
<http://example.org/r> <http://example.org/q> \\"\\"\\"Quote | ||
at end\\\\\\"\\"\\"\\" . | ||
" | ||
`; | ||
|
||
exports[`@rdfjs-elements/formats-pretty/serializers turtle preserves line breaks in literals when using prefixes 1`] = ` | ||
"@prefix ex: <http://example.org/> . | ||
ex:a ex:b \\"\\"\\"The first line | ||
The second line | ||
more\\"\\"\\" . | ||
ex:x ex:y \\"\\"\\"Long | ||
description | ||
with datatype\\"\\"\\"^^ex:multiline . | ||
ex:m ex:n \\"\\"\\"multiline | ||
with language\\"\\"\\"@en-US . | ||
ex:f ex:g \\"\\"\\"The first line | ||
\\"The quoted line\\" | ||
more\\"\\"\\" . | ||
ex:r ex:q \\"\\"\\"Quote | ||
at end\\\\\\"\\"\\"\\" . | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.