Skip to content

aphp/prism-lang-fsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

prism-lang-fsh

A Prism.js language definition plugin for FHIR Shorthand

License: MIT PRs Welcome Prism.js Compatible

πŸ“‹ Overview

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.

πŸš€ Features

  • 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+

πŸ“ Project Structure

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

πŸ”§ Installation

Using npm

npm install prism-lang-fsh

Using CDN

<!-- 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>

Manual Installation

  1. Download the plugin files from the dist/ directory
  2. Include them in your HTML after Prism.js core

πŸ“– Usage

Basic Usage

<!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>

Advanced Usage

// 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;

Supported Token Types

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

πŸ§ͺ Development

Prerequisites

  • Node.js >= 16.0.0
  • npm >= 8.0.0
  • Git

Setup

  1. Clone the repository:
git clone https://github.com/aphp/prism-lang-fsh.git
cd prism-lang-fsh
  1. Install dependencies:
npm install
  1. Start development:
npm run dev

Available Scripts

  • npm run dev - Start development mode with watch
  • npm run build - Build production files
  • npm test - Run comprehensive test suite
  • npm run lint - Lint code
  • npm run format - Format code with Prettier
  • npm run test:visual - Open visual test page with FSH examples

Testing

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

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details on:

  • Code of Conduct
  • Development workflow
  • Submitting pull requests
  • Reporting issues

πŸ› Issues

Found a bug or have a feature request? Please check existing issues first, then open a new issue if needed.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Prism.js team for the excellent syntax highlighter
  • Contributors and maintainers
  • FHIR Shorthand community

πŸ“š Resources

FHIR Shorthand

Prism.js

FHIR

πŸ”— Links

Token Coverage

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

About

A Prism.js language definition plugin for FHIR Shorthand

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published