From 42c61ae9cb0aa569fcaef4ba381430d42295a89a Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 18 May 2025 22:24:21 +0300 Subject: [PATCH] feat(highlighting): add rpm specfile --- docs/Release Notes/Release Notes/v0.94.0.md | 1 + .../highlightjs/src/languages/rpm-specfile.ts | 71 +++++++++++++++++++ .../highlightjs/src/syntax_highlighting.ts | 2 +- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 packages/highlightjs/src/languages/rpm-specfile.ts diff --git a/docs/Release Notes/Release Notes/v0.94.0.md b/docs/Release Notes/Release Notes/v0.94.0.md index fd283aceb..2a0fe383c 100644 --- a/docs/Release Notes/Release Notes/v0.94.0.md +++ b/docs/Release Notes/Release Notes/v0.94.0.md @@ -49,6 +49,7 @@ * Added support for mIRC. * Added support for Cobol. * Added support for Dylan. + * Added support for RPM Specfile. * Mermaid diagrams: basic syntax highlight (not all diagram types are supported) and code folding. * Slight organization in Appearance settings: code block themes are now in "Text Notes", added a "Related settings" section in Appearance. * [Added support for opening and activating a note in a new tab using Ctrl+Shift+click on notes in the launcher pane, note tree, or note images](https://github.com/TriliumNext/Notes/pull/1854) by @SiriusXT diff --git a/packages/highlightjs/src/languages/rpm-specfile.ts b/packages/highlightjs/src/languages/rpm-specfile.ts new file mode 100644 index 000000000..350c4a40f --- /dev/null +++ b/packages/highlightjs/src/languages/rpm-specfile.ts @@ -0,0 +1,71 @@ +import type { HLJSApi, Language, Mode } from "highlight.js"; + +/** + * highlight.js RPM spec file syntax highlighting definition + * + * Source: https://github.com/highlightjs/highlightjs-rpm-specfile + * + * @see https://github.com/highlightjs/highlight.js + * + * @package highlightjs-rpm-specfile + * @author Ryan Lerch , Neal Gompa + * @since 2019-07-08 + * @license magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt BSD-3-Clause + * + * Language: rpm-specfile + * Description: RPM Specfile + * Author: Ryan Lerch + * Contributors: Neal Gompa + * Category: config + * Requires: bash.js + * Website: https://rpm.org/ + **/ + +export default function hljsDefineRpmSpecfile(hljs: HLJSApi): Language { + return { + aliases: ['rpm', 'spec', 'rpm-spec', 'specfile'], + contains: [ + hljs.COMMENT('%dnl', '$'), + hljs.HASH_COMMENT_MODE, + hljs.APOS_STRING_MODE, + hljs.QUOTE_STRING_MODE, + { + className: "type", + begin: /^(Name|BuildRequires|Version|Release|Epoch|Summary|Group|License|Packager|Vendor|Icon|URL|Distribution|Prefix|Patch[0-9]*|Source[0-9]*|Requires\(?[a-z]*\)?|[a-z]+Req|Obsoletes|Recommends|Suggests|Supplements|Enhances|Provides|Conflicts|RemovePathPostfixes|Build[a-z]+|[a-z]+Arch|Auto[a-z]+)(:)/, + }, + { + className: "keyword", + begin: /(%)(?:package|prep|generate_buildrequires|sourcelist|patchlist|build|description|install|verifyscript|clean|changelog|check|pre[a-z]*|post[a-z]*|trigger[a-z]*|files)/, + }, + { + className: "link", + begin: /(%)(if|ifarch|ifnarch|ifos|ifnos|elif|elifarch|elifos|else|endif)/, + }, + { + className: "link", + begin: /%\{_/, + end: /}/, + }, + { + className: "symbol", + begin: /%\{\?/, + end: /}/, + }, + { + className: "link font-weight-bold", + begin: /%\{/, + end: /}/, + }, + { + className: "link font-weight-bold", + begin: /%/, + end: /[ \t\n]/ + }, + { + className: "symbol font-weight-bold", + begin: /^\* (Mon|Tue|Wed|Thu|Fri|Sat|Sun)/, + end: /$/, + }, + ] + }; +} diff --git a/packages/highlightjs/src/syntax_highlighting.ts b/packages/highlightjs/src/syntax_highlighting.ts index d7d70467a..d8ed20e4f 100644 --- a/packages/highlightjs/src/syntax_highlighting.ts +++ b/packages/highlightjs/src/syntax_highlighting.ts @@ -122,7 +122,7 @@ const byMimeType: MimeRecord = { "text/x-python": () => import("highlight.js/lib/languages/python"), "text/x-q": () => import("highlight.js/lib/languages/q"), "text/x-rpm-changes": null, - "text/x-rpm-spec": null, + "text/x-rpm-spec": () => import("./languages/rpm-specfile.js"), "text/x-rsrc": () => import("highlight.js/lib/languages/r"), "text/x-rst": null, "text/x-ruby": () => import("highlight.js/lib/languages/ruby"),