Skip to content

Commit

Permalink
Merge pull request #253 from brianpos/feature/prism-fhirpath-formatting
Browse files Browse the repository at this point in the history
Feature/prism fhirpath formatting
  • Loading branch information
lmckenzi authored Oct 10, 2024
2 parents fc77737 + a0d6660 commit 33fc4b0
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
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/,
]
};

0 comments on commit 33fc4b0

Please sign in to comment.