
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
highlightjs-sfmc
Advanced tools
Highlight.js grammars for Salesforce Marketing Cloud languages (AMPscript and SSJS)
Syntax highlighting for Salesforce Marketing Cloud languages using Highlight.js.
Includes grammars for:
npm install highlightjs-sfmc highlight.js
import hljs from 'highlight.js';
import hljsAmpscript from 'highlightjs-sfmc/ampscript';
import hljsSsjs from 'highlightjs-sfmc/ssjs';
hljs.registerLanguage('ampscript', hljsAmpscript);
hljs.registerLanguage('ssjs', hljsSsjs);
hljs.highlightAll();
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/highlight.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/highlightjs-sfmc/dist/ampscript.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/highlightjs-sfmc/dist/ssjs.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release/build/styles/default.min.css" />
<script>
hljs.highlightAll();
</script>
Then mark your code blocks with the appropriate language:
<pre><code class="language-ampscript">
%%[
SET @name = "World"
Output(Concat("Hello, ", @name))
]%%
</code></pre>
<pre><code class="language-ssjs">
Platform.Load("core", "1");
var rows = DataExtension.Init("MyDE").Rows.Lookup(["Key"], ["value"]);
Write(Stringify(rows));
</code></pre>
| Element | Examples | Scope |
|---|---|---|
| Block delimiters | %%[ ]%% | meta |
| Inline delimiters | %%= =%% | meta |
| Keywords | VAR SET IF THEN ELSE ENDIF FOR NEXT | keyword |
| Built-in functions | Lookup ContentBlockByKey Output Concat | built_in |
| User variables | @firstName | variable |
| System variables | @@ExecCtx | variable.language |
| Personalization | %%Name%% | variable.language |
| Strings | "hello" 'world' | string |
| Numbers | 42 3.14 | number |
| Comments | /* block comment */ | comment |
| Operators | == != AND OR NOT | keyword / operator |
Extends JavaScript highlighting with SFMC-specific additions:
| Element | Examples | Scope |
|---|---|---|
| SFMC globals | Platform DataExtension WSProxy HTTP | built_in |
| SFMC functions | Write Stringify ContentBlockByKey | built_in |
| Platform API | Platform.Function.* Platform.Response.* | built_in |
| Script.Util | Script.Util.WSProxy Script.Util.HttpRequest | built_in |
| Core methods | .Init() .Retrieve() .Add() | title.function.invoke |
All standard JavaScript syntax (variables, control flow, strings, etc.) is highlighted by the built-in JavaScript grammar.
To test this plugin against the Highlight.js test suite, clone the highlight.js repo and link this package into its extra/ directory. Run the commands from the parent folder that contains both highlight.js (the clone) and highlightjs-sfmc.
Bash / macOS / Linux (symbolic link):
git clone --depth 1 https://github.com/highlightjs/highlight.js.git
cd highlight.js
mkdir -p extra
ln -s ../highlightjs-sfmc extra/highlightjs-sfmc
node ./tools/build.js -t node
npm test
Windows PowerShell (directory junction; usually works without elevated rights):
git clone --depth 1 https://github.com/highlightjs/highlight.js.git
Set-Location highlight.js
New-Item -ItemType Directory -Force -Path extra | Out-Null
New-Item -ItemType Junction -Path "extra\highlightjs-sfmc" -Target (Resolve-Path "..\highlightjs-sfmc")
node .\tools\build.js -t node
npm test
If Resolve-Path fails, adjust -Target to the absolute path of your highlightjs-sfmc checkout. You can use a symbolic link instead (New-Item -ItemType SymbolicLink) if your Windows version and policy allow it (often requires an elevated shell or Developer Mode).
FAQs
Highlight.js grammars for Salesforce Marketing Cloud languages (AMPscript and SSJS)
We found that highlightjs-sfmc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.