A Prism.js language definition plugin for FHIR Mapping Language (FML)
This project provides a comprehensive language definition plugin for Prism.js, enabling syntax highlighting for FHIR Mapping Language (FML) files. FML is a domain-specific language for transforming data between different FHIR resource formats, essential for healthcare interoperability.
- Complete FML syntax support - All keywords, operators, and constructs
- Comprehensive token highlighting - Metadata comments, transformation arrows, functions
- FHIR-aware patterns - URLs, paths, ConceptMaps, structure definitions
- Performance optimized - Regex patterns designed to avoid backtracking
- Compatible with Prism.js 1.15+ - Works with all modern Prism.js versions
- Extensive test coverage - 50+ test cases covering all FML features
- Visual testing - Interactive demo for real-time syntax verification
prism-lang-fml/
βββ src/
β βββ prism-lang-fml.js # Main language definition
β βββ prism-lang-fml.css # Optional fml styling
βββ test/
β βββ fixtures/ # Test code samples
β βββ prism-lang-fml.test.js # Unit tests
β βββ visual.html # Visual testing page
βββ examples/
β βββ demo.html # Usage examples
βββ dist/ # Built/minified files
β βββ prism-lang-fml.min.js
β βββ prism-lang-fml.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-fml<!-- Include Prism.js core -->
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.30.0/prism.min.js"></script>
<!-- Include the language definition -->
<script src="https://cdn.jsdelivr.net/npm/prism-lang-fml@0.1.0/prism-lang-fml.min.js"></script>- Download the plugin files from the
dist/directory - Include them in your HTML after Prism.js core
<pre><code class="language-fml">
/// url = 'http://example.org/fhir/StructureMap/PatientTransform'
/// name = 'PatientTransformation'
map "PatientTransform" = "Transform"
uses "http://hl7.org/fhir/StructureDefinition/Patient" alias Patient as source
uses "http://hl7.org/fhir/StructureDefinition/Bundle" alias Bundle as target
group TransformPatient(source src : Patient, target tgt : Bundle) {
src.id as id -> tgt.id = id "copyId"
src.name as n where n.use = 'official' -> tgt.displayName = n
src.gender as g -> tgt.genderCode = translate(g, '#GenderMap', 'code')
}
</code></pre>
<script>
// Highlight all code blocks
Prism.highlightAll();
</script>// Programmatic highlighting
const fmlCode = `
src.identifier as id where id.system = 'http://example.org/mrn' then {
id -> tgt.identifier = create('Identifier') as newId then {
id.value as v -> newId.value = v "setValue"
id -> newId.system = 'http://newexample.org/mrn' "setSystem"
}
}
`;
const html = Prism.highlight(fmlCode, Prism.languages.fml, 'fml');The plugin recognizes and highlights the following FML constructs:
| Token Type | Description | Example |
|---|---|---|
metadata-comment |
Metadata declarations | /// url = 'http://example.org' |
structure-keyword |
Structure definition keywords | map, uses, group, imports |
mode-keyword |
Parameter mode keywords | source, target, queried |
transformation-keyword |
Transformation operations | for, where, check, then |
function |
Built-in functions | create(), translate(), cc() |
transformation-arrow |
Transformation operator | -> |
rule-label |
Named rule labels | "copyId" : |
variable-binding |
Variable binding keyword | as |
url |
HTTP/HTTPS URLs | http://hl7.org/fhir/Patient |
path |
Path expressions | src.patient.name.family |
operator |
Logical/comparison operators | =, !=, and, or |
string |
String literals | 'Patient', "Bundle" |
number |
Numeric literals | 42, 3.14 |
boolean |
Boolean values | true, false |
- Node.js >= 16.0.0
- npm >= 7.0.0
- Git
- Clone the repository:
git clone https://github.com/yourusername/prism-lang-fml.git
cd prism-lang-fml- Install dependencies:
npm install- Start development:
npm run devnpm run dev- Start development mode with watchnpm run build- Build production filesnpm test- Run testsnpm run lint- Lint codenpm run format- Format code with Prettiernpm run test:visual- Open visual test page
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
- HL7 FHIR community for the FHIR specification
- FHIR Mapping Language specification authors
- Contributors and maintainers
- Healthcare interoperability community
- FHIR Mapping Language Specification
- FHIR Mapping Language Grammar
- FHIR Mapping Tutorial
- StructureMap Resource
- FHIRPath Specification
- β Language Definition: Complete FML syntax support with 15+ token types
- β Testing: 50+ comprehensive test cases covering all FML features
- β Documentation: Complete language specification and usage examples
- β Performance: Optimized regex patterns, no catastrophic backtracking
- β Visual Testing: Interactive demo with theme switching and real-time testing
- β Build System: Production-ready build pipeline with minification
- Structure Definitions:
map,uses,group,imports,extends,alias,conceptmap - Mode Keywords:
source,target,queried,produced - Transformations:
for,where,check,then,first,last,only_one - Functions: All 17+ built-in functions (
create,translate,cc,qty, etc.) - Special Syntax: Transformation arrows (
->), rule labels, variable binding (as) - Data Types: URLs, paths, strings, numbers, booleans
- ConceptMaps: Full prefix and mapping syntax support
Ready for FHIR developers building healthcare interoperability solutions! π₯
Status: β Ready for Production - Complete FML syntax highlighting implementation
partially developped with Claude Code