From 944b9124c18ae296a333ecf44844980a9d065620 Mon Sep 17 00:00:00 2001 From: Brian Postlethwaite Date: Mon, 6 May 2024 16:07:13 +1000 Subject: [PATCH 1/3] Add support for prism based syntax for fhirpath expressions in markdown --- content/assets/css/prism.fhirpath.css | 38 +++++++++++++++++++++++++++ content/assets/js/prism.fhirpath.js | 26 ++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 content/assets/css/prism.fhirpath.css create mode 100644 content/assets/js/prism.fhirpath.js diff --git a/content/assets/css/prism.fhirpath.css b/content/assets/css/prism.fhirpath.css new file mode 100644 index 0000000..ad78435 --- /dev/null +++ b/content/assets/css/prism.fhirpath.css @@ -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: -15.5px; +} + +/* 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; +} diff --git a/content/assets/js/prism.fhirpath.js b/content/assets/js/prism.fhirpath.js new file mode 100644 index 0000000..d612b60 --- /dev/null +++ b/content/assets/js/prism.fhirpath.js @@ -0,0 +1,26 @@ + // Script to perform syntax highlighting of the FHIRPath grammar + // https://prismjs.com/extending.html#language-definitions + Prism.languages['fhirpath'] = Prism.languages.extend('json', { + 'property': { + pattern: /(^|[^\\])`(?:\\.|[^\\`\r\n])*`(?=\s*:)/, + lookbehind: true, + greedy: true + }, + 'string': { + pattern: /(^|[^\\])'(?:\\.|[^\\'\r\n])*'(?!\s*:)/, + lookbehind: true, + greedy: true + }, + 'comment': { + pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/, + greedy: true + }, + 'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i, + 'punctuation': /[{}[\],]/, + 'operator': /:/, + 'boolean': /\b(?:false|true)\b/, + 'null': { + pattern: /\bnull\b/, + alias: 'keyword' + } +}); From 21b073becfeb54c29240340cdde16586faee6fcf Mon Sep 17 00:00:00 2001 From: Brian Postlethwaite Date: Wed, 28 Aug 2024 21:09:23 +1000 Subject: [PATCH 2/3] Update the prism fhirpath-js implementation to be more complete --- ...{prism.fhirpath.css => prism-fhirpath.css} | 0 content/assets/js/prism-fhirpath.js | 67 +++++++++++++++++++ content/assets/js/prism.fhirpath.js | 26 ------- 3 files changed, 67 insertions(+), 26 deletions(-) rename content/assets/css/{prism.fhirpath.css => prism-fhirpath.css} (100%) create mode 100644 content/assets/js/prism-fhirpath.js delete mode 100644 content/assets/js/prism.fhirpath.js diff --git a/content/assets/css/prism.fhirpath.css b/content/assets/css/prism-fhirpath.css similarity index 100% rename from content/assets/css/prism.fhirpath.css rename to content/assets/css/prism-fhirpath.css diff --git a/content/assets/js/prism-fhirpath.js b/content/assets/js/prism-fhirpath.js new file mode 100644 index 0000000..01d503d --- /dev/null +++ b/content/assets/js/prism-fhirpath.js @@ -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/, + ] +}; diff --git a/content/assets/js/prism.fhirpath.js b/content/assets/js/prism.fhirpath.js deleted file mode 100644 index d612b60..0000000 --- a/content/assets/js/prism.fhirpath.js +++ /dev/null @@ -1,26 +0,0 @@ - // Script to perform syntax highlighting of the FHIRPath grammar - // https://prismjs.com/extending.html#language-definitions - Prism.languages['fhirpath'] = Prism.languages.extend('json', { - 'property': { - pattern: /(^|[^\\])`(?:\\.|[^\\`\r\n])*`(?=\s*:)/, - lookbehind: true, - greedy: true - }, - 'string': { - pattern: /(^|[^\\])'(?:\\.|[^\\'\r\n])*'(?!\s*:)/, - lookbehind: true, - greedy: true - }, - 'comment': { - pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/, - greedy: true - }, - 'number': /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i, - 'punctuation': /[{}[\],]/, - 'operator': /:/, - 'boolean': /\b(?:false|true)\b/, - 'null': { - pattern: /\bnull\b/, - alias: 'keyword' - } -}); From a0d66604190a2c8d2989dbe55038222f32752fd5 Mon Sep 17 00:00:00 2001 From: Brian Postlethwaite Date: Thu, 29 Aug 2024 11:02:40 +1000 Subject: [PATCH 3/3] correct left alignment. --- content/assets/css/prism-fhirpath.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/assets/css/prism-fhirpath.css b/content/assets/css/prism-fhirpath.css index ad78435..5c73bff 100644 --- a/content/assets/css/prism-fhirpath.css +++ b/content/assets/css/prism-fhirpath.css @@ -23,7 +23,7 @@ pre.language-fhirpath.stu { overflow: unset; } pre.language-fhirpath.stu:after { - left: -15.5px; + left: -16px; } /* inline fhirpath code blocks used in examples */