From c3ac4ec6783738ab0b5baa30c1a61a9d16065bc5 Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Mon, 15 Dec 2025 20:42:23 -0800 Subject: [PATCH 1/3] Add support for Pkl syntax highlighting --- jest.config.js | 1 + package-lock.json | 9 +++++++++ package.json | 1 + src/utils/custom-highlight-lang/pkl.js | 13 +++++++++++++ src/utils/syntax-highlight.js | 2 ++ tests/unit/utils/syntax-highlight.spec.js | 13 +++++++++++++ 6 files changed, 39 insertions(+) create mode 100644 src/utils/custom-highlight-lang/pkl.js diff --git a/jest.config.js b/jest.config.js index b9f1ee56c..4c295a7c5 100644 --- a/jest.config.js +++ b/jest.config.js @@ -18,4 +18,5 @@ module.exports = { }, testEnvironment: 'jest-environment-jsdom', setupFiles: ['./tests/unit/config.js'], + transformIgnorePatterns: ['/node_modules/(?!@apple/highlightjs-pkl)'], }; diff --git a/package-lock.json b/package-lock.json index bf2f994b8..d17e7bafd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "swift-docc-render", "version": "0.1.0", "dependencies": { + "@apple/highlightjs-pkl": "^1.0.0", "core-js": "^3.8.2", "css.escape": "^1.5.1", "highlight.js": "^11.3.1", @@ -81,6 +82,14 @@ "node": ">=6.0.0" } }, + "node_modules/@apple/highlightjs-pkl": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@apple/highlightjs-pkl/-/highlightjs-pkl-1.0.0.tgz", + "integrity": "sha512-MQwZ7c8ky96pFih2Zuzg/NYEcyLZK64EsEAX6BR0flQohdWpeQyTr1g31YvIL47c3q5aJtRIJi8qvB+CLucm2g==", + "dependencies": { + "highlight.js": "^11.11.1" + } + }, "node_modules/@babel/code-frame": { "version": "7.27.1", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.27.1.tgz", diff --git a/package.json b/package.json index 3a6cf4902..208262b16 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "webpack-asset-path.js" ], "dependencies": { + "@apple/highlightjs-pkl": "^1.0.0", "core-js": "^3.8.2", "css.escape": "^1.5.1", "highlight.js": "^11.3.1", diff --git a/src/utils/custom-highlight-lang/pkl.js b/src/utils/custom-highlight-lang/pkl.js new file mode 100644 index 000000000..abbd9bc13 --- /dev/null +++ b/src/utils/custom-highlight-lang/pkl.js @@ -0,0 +1,13 @@ +/** + * This source file is part of the Swift.org open source project + * + * Copyright (c) 2021 Apple Inc. and the Swift project authors + * Licensed under Apache License v2.0 with Runtime Library Exception + * + * See https://swift.org/LICENSE.txt for license information + * See https://swift.org/CONTRIBUTORS.txt for Swift project authors +*/ + +import pkl from '@apple/highlightjs-pkl'; + +export default pkl; diff --git a/src/utils/syntax-highlight.js b/src/utils/syntax-highlight.js index 924436c92..6ec3cec9f 100644 --- a/src/utils/syntax-highlight.js +++ b/src/utils/syntax-highlight.js @@ -31,6 +31,7 @@ const Languages = { objectivec: ['mm', 'objc', 'obj-c'].concat(CustomLanguageAliases.objectivec), perl: ['pl', 'pm'], php: [], + pkl: [], python: ['py', 'gyp', 'ipython'], ruby: ['rb', 'gemspec', 'podspec', 'thor', 'irb'], scss: [], @@ -50,6 +51,7 @@ const Languages = { export const CustomLanguagesSet = new Set([ 'markdown', 'swift', + 'pkl', ]); export const LanguageAliasEntries = Object.entries(Languages); diff --git a/tests/unit/utils/syntax-highlight.spec.js b/tests/unit/utils/syntax-highlight.spec.js index c4d0dd4ba..fc70fd15d 100644 --- a/tests/unit/utils/syntax-highlight.spec.js +++ b/tests/unit/utils/syntax-highlight.spec.js @@ -286,6 +286,19 @@ describe("syntax-highlight", () => { `); }); + it("tokenizes pkl code", async () => { + const content = [ + "foo = 1", + "bar = \"Hello \\(foo)\"", + ]; + const { highlightedCode } = await prepare(content, "pkl"); + expect(highlightedCode).toMatchInlineSnapshot(` + foo = 1 + bar = "Hello \\(foo)" + ` + ); + }); + it("returns false if the language is not supported", async () => { expect(await registerHighlightLanguage("pascal")).toBe(false); }); From b3e59c772825e75530b60ecd322d3dc42e352fda Mon Sep 17 00:00:00 2001 From: Daniel Chao Date: Tue, 16 Dec 2025 11:12:02 -0800 Subject: [PATCH 2/3] Update src/utils/custom-highlight-lang/pkl.js Co-authored-by: Marcus Ortiz --- src/utils/custom-highlight-lang/pkl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/custom-highlight-lang/pkl.js b/src/utils/custom-highlight-lang/pkl.js index abbd9bc13..9843235d1 100644 --- a/src/utils/custom-highlight-lang/pkl.js +++ b/src/utils/custom-highlight-lang/pkl.js @@ -1,7 +1,7 @@ /** * This source file is part of the Swift.org open source project * - * Copyright (c) 2021 Apple Inc. and the Swift project authors + * Copyright (c) 2025 Apple Inc. and the Swift project authors * Licensed under Apache License v2.0 with Runtime Library Exception * * See https://swift.org/LICENSE.txt for license information From 2aab81a4482f583de549f02600b169104ab47641 Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Tue, 16 Dec 2025 13:32:26 -0800 Subject: [PATCH 3/3] Bump highlightjs-pkl to 1.0.1 --- package-lock.json | 9 +++++---- package.json | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index d17e7bafd..67d534383 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "swift-docc-render", "version": "0.1.0", "dependencies": { - "@apple/highlightjs-pkl": "^1.0.0", + "@apple/highlightjs-pkl": "^1.0.1", "core-js": "^3.8.2", "css.escape": "^1.5.1", "highlight.js": "^11.3.1", @@ -83,9 +83,10 @@ } }, "node_modules/@apple/highlightjs-pkl": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@apple/highlightjs-pkl/-/highlightjs-pkl-1.0.0.tgz", - "integrity": "sha512-MQwZ7c8ky96pFih2Zuzg/NYEcyLZK64EsEAX6BR0flQohdWpeQyTr1g31YvIL47c3q5aJtRIJi8qvB+CLucm2g==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@apple/highlightjs-pkl/-/highlightjs-pkl-1.0.1.tgz", + "integrity": "sha512-AYoR/X1W5HlT9elhCjB6cQ6Zs0rvT14o4SJRw2M8lCBP6ceK9LgbHaMRxydikU2Xjmzt0XEYCPzS63+kar35xg==", + "license": "Apache-2.0", "dependencies": { "highlight.js": "^11.11.1" } diff --git a/package.json b/package.json index 208262b16..080f202b1 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "webpack-asset-path.js" ], "dependencies": { - "@apple/highlightjs-pkl": "^1.0.0", + "@apple/highlightjs-pkl": "^1.0.1", "core-js": "^3.8.2", "css.escape": "^1.5.1", "highlight.js": "^11.3.1",