Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/prism fhirpath formatting #253

Merged
merged 4 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions content/assets/css/prism-fhirpath.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Custom formatting for the code blocks */
pre.language-fhirpath {
background-color: #eee;
text-shadow: unset;
}

pre.language-fhirpath code.language-fhirpath {
white-space: pre-wrap;
text-shadow: unset;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
background: unset;
}


pre.language-fhirpath.stu {
margin-left: 20px;
overflow: unset;
}
pre.language-fhirpath.stu:after {
left: -16px;
}

/* inline fhirpath code blocks used in examples */
:not(pre) > code.fhirpath {
background-color: #eee;
padding: 1px 4px;
border: 1px solid #cccccc;
font-size: 1em;
display: inline-block;
margin: 2px 0;
text-shadow: unset;
}
67 changes: 67 additions & 0 deletions content/assets/js/prism-fhirpath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* eslint-disable regexp/prefer-d */
// https://hl7.org/fhirpath
Prism.languages.fhirpath = {
'comment': {
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true
},
'constant': [
// This is where I'm going to put in the literals for datetime/date/time/quantity
/@[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9](:[0-9][0-9])?(\.[0-9]+)?(Z|[+\-][0-9][0-9]:[0-9][0-9])?/,
/@[0-9][0-9][0-9][0-9](-[0-9][0-9](-[0-9][0-9])?)?/,
/@T[0-9][0-9]:[0-9][0-9](:[0-9][0-9])?(\.[0-9]+)?/,
/\b\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b\s+(years|months|weeks|days|hours|minutes|seconds|milliseconds|year|month|week|day|hour|minute|second|millisecond)\b/
],
'number': [
/\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i,
/\b\d+(?:\.\d+)?L\b/i
],
'string': {
pattern: /(^|[^\\])'(?:\\.|[^\\'\r\n])*'(?!\s*:)/,
lookbehind: true,
greedy: true
},
'punctuation': /[()[\],.]/,
'operator': /(>=|<=|!=|!~|[|\\+\-=<>~/*&])/,
'keyword': [
/\b(and|as|contains|day|days|div|hour|hours|implies|in|\$index|is|millisecond|milliseconds|minute|minutes|mod|month|months|or|second|seconds|\$this|\$total|week|weeks|xor|year|years)\b/,
/\{\s*\}/
],
'boolean': /\b(?:false|true)\b/,
'builtin': [
// section 5.1 http://hl7.org/fhirpath/#existence
/\b(empty|exists|all|allTrue|anyTrue|allFalse|anyFalse|subsetOf|supersetOf|count|distinct|isDistinct)\b/,
// section 5.2 http://hl7.org/fhirpath/#filtering-and-projection
/\b(where|select|repeat|ofType)\b/,
// section 5.3 http://hl7.org/fhirpath/#subsetting
/\b(single|first|last|tail|skip|take|intersect|exclude)\b/,
// section 5.4
/\b(union|combine)\b/,
// section 5.5
/\b(iif|toBoolean|convertsToBoolean|toInteger|convertsToInteger|toDate|convertsToDate|toDateTime|convertsToDateTime|toDecimal|convertsToDecimal|toQuantity|convertsToQuantity|toString|convertsToString|toTime|convertsToTime)\b/,
// section 5.6
/\b(indexOf|substring|startsWith|endsWith|contains|upper|lower|replace|matches|replaceMatches|length|toChars|split|join|encode|decode)\b/,
// section 5.7
/\b(abs|ceiling|exp|floor|ln|log|power|round|sqrt|truncate)\b/,
// section 5.8
/\b(children|descendants)\b/,
// section 5.9 (not is in section 6.5)
/\b(trace|now|timeOfDay|today|not)\b/,
// section 6.3
/\b(as|is)\b/,
// section 7
/\b(aggregate)\b/
],
'variable': [
/(%\w+)\b/,
/(%`(?:\w|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|[ \-\."\\\/fnrt])+`)/ // this isn;t quite right, but it's a start
],
'identifier': [
{
pattern: /`(?:\w|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|[ \-\."\\\/fnrt])+`/,
// lookbehind: true,
greedy: true
},
/\b([A-Za-z]|_)([A-Za-z0-9]|_)*\b/,
]
};