This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: syntax highlighting for keto-relation-tuples prism language (#72)
Transferred from ory/keto#582
- Loading branch information
Showing
3 changed files
with
135 additions
and
1 deletion.
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
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,56 @@ | ||
const delimiter = { | ||
delimiter: /[:#@()]/ | ||
} | ||
|
||
const namespace = { | ||
pattern: /[^:#@()\n]+:/, | ||
inside: { | ||
...delimiter, | ||
namespace: /.*/ | ||
} | ||
} | ||
|
||
const object = { | ||
pattern: /[^:#@()\n]+#/, | ||
inside: { | ||
...delimiter, | ||
'property-access': /.*/ | ||
} | ||
} | ||
|
||
const relation = { | ||
pattern: /[^:#@()\n]+/ | ||
} | ||
|
||
const subjectID = { | ||
pattern: /@[^:#@()\n]+/, | ||
inside: { | ||
...delimiter, | ||
subject: /.*/ | ||
} | ||
} | ||
|
||
const subjectSet = { | ||
pattern: /@\(([^:#@()\n]+:)?([^:#@()\n]+)#([^:#@()\n]*)\)/, | ||
inside: { | ||
delimiter: /[@()]*/, | ||
namespace, | ||
object, | ||
relation | ||
} | ||
} | ||
|
||
export default (prism) => | ||
(prism.languages['keto-relation-tuples'] = { | ||
comment: /\/\/.*(\n|$)/, | ||
'relation-tuple': { | ||
pattern: /([^:#@()\n]+:)?([^:#@()\n]+)#([^:#@()\n]+)@?((\(([^:#@()\n]+:)?([^:#@()\n]+)#([^:#@()\n]*)\))|([^:#@()\n]+))/, | ||
inside: { | ||
namespace, | ||
object, | ||
subjectID, | ||
subjectSet, | ||
relation | ||
} | ||
} | ||
}) |
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,27 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment' | ||
import siteConfig from '@generated/docusaurus.config' | ||
import ketoRelationTuplesPrism from './ketoRelationTuplesPrism' | ||
|
||
const prismIncludeLanguages = (PrismObject) => { | ||
if (ExecutionEnvironment.canUseDOM) { | ||
const { | ||
themeConfig: { prism: { additionalLanguages = [] } = {} } | ||
} = siteConfig | ||
window.Prism = PrismObject | ||
additionalLanguages.forEach((lang) => { | ||
require(`prismjs/components/prism-${lang}`) // eslint-disable-line | ||
}) | ||
|
||
ketoRelationTuplesPrism(window.Prism) | ||
|
||
delete window.Prism | ||
} | ||
} | ||
|
||
export default prismIncludeLanguages |