2022-06-13 16:31:36 +00:00
|
|
|
import { HighlightStyle } from "@codemirror/language";
|
|
|
|
import { tags as t } from "@lezer/highlight";
|
2022-04-29 16:54:27 +00:00
|
|
|
import * as ct from "@silverbulletmd/common/customtags";
|
|
|
|
import { MDExt } from "@silverbulletmd/common/markdown_ext";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-04-11 18:34:09 +00:00
|
|
|
export default function highlightStyles(mdExtension: MDExt[]) {
|
2022-06-13 16:31:36 +00:00
|
|
|
const hls = HighlightStyle.define([
|
2022-08-02 12:40:04 +00:00
|
|
|
{ tag: t.heading1, class: "sb-h1" },
|
|
|
|
{ tag: t.heading2, class: "sb-h2" },
|
|
|
|
{ tag: t.heading3, class: "sb-h3" },
|
|
|
|
{ tag: t.link, class: "sb-link" },
|
|
|
|
{ tag: t.meta, class: "sb-meta" },
|
|
|
|
{ tag: t.quote, class: "sb-quote" },
|
|
|
|
{ tag: t.monospace, class: "sb-code" },
|
|
|
|
{ tag: t.url, class: "sb-url" },
|
|
|
|
{ tag: ct.WikiLinkTag, class: "sb-wiki-link" },
|
|
|
|
{ tag: ct.WikiLinkPageTag, class: "sb-wiki-link-page" },
|
|
|
|
{ tag: ct.TaskTag, class: "sb-task" },
|
|
|
|
{ tag: ct.TaskMarkerTag, class: "sb-task-marker" },
|
|
|
|
{ tag: ct.CodeInfoTag, class: "sb-code-info" },
|
|
|
|
{ tag: ct.CommentTag, class: "sb-comment" },
|
|
|
|
{ tag: ct.CommentMarkerTag, class: "sb-comment-marker" },
|
|
|
|
{ tag: ct.Highlight, class: "sb-highlight" },
|
|
|
|
{ tag: t.emphasis, class: "sb-emphasis" },
|
|
|
|
{ tag: t.strong, class: "sb-strong" },
|
|
|
|
{ tag: t.atom, class: "sb-atom" },
|
|
|
|
{ tag: t.bool, class: "sb-bool" },
|
|
|
|
{ tag: t.url, class: "sb-url" },
|
|
|
|
{ tag: t.inserted, class: "sb-inserted" },
|
|
|
|
{ tag: t.deleted, class: "sb-deleted" },
|
|
|
|
{ tag: t.literal, class: "sb-literal" },
|
|
|
|
{ tag: t.keyword, class: "sb-keyword" },
|
|
|
|
{ tag: t.list, class: "sb-list" },
|
|
|
|
// { tag: t.def, class: "sb-li" },
|
|
|
|
{ tag: t.string, class: "sb-string" },
|
|
|
|
{ tag: t.number, class: "sb-number" },
|
|
|
|
{ tag: [t.regexp, t.escape, t.special(t.string)], class: "sb-string2" },
|
|
|
|
{ tag: t.variableName, class: "sb-variableName" },
|
|
|
|
{ tag: t.typeName, class: "sb-typeName" },
|
|
|
|
{ tag: t.comment, class: "sb-comment" },
|
|
|
|
{ tag: t.invalid, class: "sb-invalid" },
|
|
|
|
{ tag: t.processingInstruction, class: "sb-meta" },
|
2022-04-20 08:56:43 +00:00
|
|
|
// { tag: t.content, class: "tbl-content" },
|
2022-08-02 12:40:04 +00:00
|
|
|
{ tag: t.punctuation, class: "sb-punctuation" },
|
2022-08-29 14:48:52 +00:00
|
|
|
{ tag: ct.HorizontalRuleTag, class: "sb-hr" },
|
2022-04-11 18:34:09 +00:00
|
|
|
...mdExtension.map((mdExt) => {
|
2022-08-29 14:16:55 +00:00
|
|
|
return { tag: mdExt.tag, ...mdExt.styles, class: mdExt.className };
|
2022-04-11 18:34:09 +00:00
|
|
|
}),
|
|
|
|
]);
|
2022-06-13 16:31:36 +00:00
|
|
|
const fn0 = hls.style;
|
|
|
|
// Hack: https://discuss.codemirror.net/t/highlighting-that-seems-ignored-in-cm6/4320/16
|
|
|
|
// @ts-ignore
|
|
|
|
hls.style = (tags) => {
|
|
|
|
return fn0(tags || []);
|
|
|
|
};
|
|
|
|
|
|
|
|
return hls;
|
2022-04-11 18:34:09 +00:00
|
|
|
}
|