A Prism.js language definition plugin for FHIR Shorthand
This project provides a comprehensive language definition plugin for Prism.js to enable syntax highlighting for FHIR Shorthand (FSH) language. FSH is a domain-specific language for defining FHIR implementation guides, profiles, extensions, and other FHIR conformance resources.
- Complete FSH v3.0.0 support - All major language constructs
- Rich syntax highlighting - Comments, aliases, definitions, rules, codes, cardinalities, and more
- Performance optimized - Regex patterns avoid catastrophic backtracking
- Comprehensive token types - 15+ distinct token categories for precise highlighting
- Multiple themes - Light, dark, and high-contrast support
- Browser compatible - Works with all modern browsers
- Extensive testing - 100+ test cases covering edge cases and real-world examples
- Compatible with Prism.js 1.15+
prism-lang-fsh/
βββ src/
β βββ prism-lang-fsh.js # Main language definition
β βββ prism-lang-fsh.css # Optional FSH styling
βββ test/
β βββ fixtures/ # Test code samples
β βββ prism-lang-fsh.test.js # Unit tests
β βββ visual.html # Visual testing page
βββ examples/
β βββ demo.html # Usage examples
βββ dist/ # Built/minified files
β βββ prism-lang-fsh.min.js
β βββ prism-lang-fsh.min.css
βββ docs/
β βββ LANGUAGE_SPEC.md # Language specification
βββ .github/
β βββ workflows/ # CI/CD pipelines
β βββ ISSUE_TEMPLATE/
β βββ PULL_REQUEST_TEMPLATE.md
βββ CONTRIBUTING.md # Contribution guidelines
βββ CLAUDE.md # Claude Code assistant guide
βββ LICENSE # MIT License
βββ package.json
βββ .gitignore
βββ .eslintrc.json
βββ README.md # This file
npm install prism-lang-fsh
<!-- Include Prism.js core -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/prism.min.js"></script>
<!-- Include the language definition -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/prism-lang-fsh.min.js"></script>
- Download the plugin files from the
dist/
directory - Include them in your HTML after Prism.js core
<!DOCTYPE html>
<html>
<head>
<!-- Include Prism CSS -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/themes/prism-min.css"
rel="stylesheet"
/>
<!-- Include FSH theme (optional) -->
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/prism-lang-fsh.min.css"
rel="stylesheet"
/>
</head>
<body>
<pre><code class="language-fsh">
// FHIR Shorthand Profile Example
Profile: MyPatientProfile
Parent: Patient
Id: my-patient
Title: "My Patient Profile"
Description: "A custom patient profile with additional constraints"
* identifier 1..* MS
* name 1..* MS
* birthDate 1..1 MS
* gender from http://hl7.org/fhir/ValueSet/administrative-gender (required)
</code></pre>
<!-- Include Prism core -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/prism.min.js"></script>
<!-- Include FSH language definition -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/prism-lang-fsh.min.js"></script>
<script>
// Highlight all code blocks
Prism.highlightAll();
</script>
</body>
</html>
// Programmatic highlighting
const fshCode = `
Alias: $sct = http://snomed.info/sct
Profile: ObservationProfile
Parent: Observation
* code from $sct (required)
* value[x] only Quantity
`;
const html = Prism.highlight(fshCode, Prism.languages.fsh, 'fsh');
document.getElementById('output').innerHTML = html;
The plugin recognizes and highlights these FSH language elements:
- Comments:
// single-line
and/* multi-line */
- Aliases:
Alias: $name = url
- Definitions:
Profile:
,Extension:
,Instance:
,ValueSet:
, etc. - Metadata:
Id:
,Parent:
,Title:
,Description:
, etc. - Rules:
* element 1..* MS
- Codes:
#active
,SCT#123456
,$alias#code
- Cardinalities:
0..1
,1..*
,0..5
- Flags:
MS
,SU
,?!
,D
,TU
,N
- Actions:
contains
,only
,from
,obeys
,insert
- Bindings:
(required)
,(extensible)
,(preferred)
,(example)
- URLs:
http://example.org/ValueSet/test
- Strings:
"text"
and"""multi-line"""
- Identifiers:
myId
,us-core-patient
,Patient.name.family
- Node.js >= 16.0.0
- npm >= 8.0.0
- Git
- Clone the repository:
git clone https://github.com/aphp/prism-lang-fsh.git
cd prism-lang-fsh
- Install dependencies:
npm install
- Start development:
npm run dev
npm run dev
- Start development mode with watchnpm run build
- Build production filesnpm test
- Run comprehensive test suitenpm run lint
- Lint codenpm run format
- Format code with Prettiernpm run test:visual
- Open visual test page with FSH examples
Run the comprehensive test suite:
npm test
For visual testing and manual verification:
# Open the visual test page
npm run test:visual
# Or directly open in browser
open test/visual.html
The test suite includes:
- Unit tests for all token types
- Integration tests with real FSH files
- Performance tests for large files
- Edge case testing
- Real-world FSH examples
We welcome contributions! Please see our Contributing Guide for details on:
- Code of Conduct
- Development workflow
- Submitting pull requests
- Reporting issues
Found a bug or have a feature request? Please check existing issues first, then open a new issue if needed.
This project is licensed under the MIT License - see the LICENSE file for details.
- Prism.js team for the excellent syntax highlighter
- Contributors and maintainers
- FHIR Shorthand community
- FHIR Shorthand Official Specification
- FSH School - Interactive Tutorial
- SUSHI - FSH Compiler
- GoFSH - FHIR to FSH Converter
- FSH Language Grammar
This plugin provides comprehensive syntax highlighting for all major FSH language constructs:
Feature | Support | Examples |
---|---|---|
Comments | β Full | // comment , /* block */ |
Aliases | β Full | Alias: $sct = http://snomed.info/sct |
Definitions | β Full | Profile: , Extension: , ValueSet: |
Metadata | β Full | Id: , Parent: , Title: , Description: |
Rules | β Full | * element 1..* MS |
Codes | β Full | #active , SCT#123456 , $sct#code |
Cardinalities | β Full | 0..1 , 1..* , 0..5 |
Flags | β Full | MS , SU , ?! , D , TU , N |
Actions | β Full | contains , only , from , obeys |
Bindings | β Full | (required) , (extensible) |
URLs | β Full | http://example.org/path |
Strings | β Full | "text" , """multi-line""" |
Paths | β Full | extension[name].value[x] |
Caret Rules | β Full | * ^status = #active |
Identifiers | β Full | myId , us-core-patient , name.family |
Status: β Production Ready - Full FSH v3.0.0 support with comprehensive testing
partially developped with Claude Code