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-04-11 18:34:09 +00:00
|
|
|
{ tag: t.heading1, class: "h1" },
|
|
|
|
{ tag: t.heading2, class: "h2" },
|
|
|
|
{ tag: t.heading3, class: "h3" },
|
|
|
|
{ tag: t.link, class: "link" },
|
|
|
|
{ tag: t.meta, class: "meta" },
|
|
|
|
{ tag: t.quote, class: "quote" },
|
|
|
|
{ tag: t.monospace, class: "code" },
|
|
|
|
{ tag: t.url, class: "url" },
|
|
|
|
{ tag: ct.WikiLinkTag, class: "wiki-link" },
|
|
|
|
{ tag: ct.WikiLinkPageTag, class: "wiki-link-page" },
|
|
|
|
{ tag: ct.TaskTag, class: "task" },
|
|
|
|
{ tag: ct.TaskMarkerTag, class: "task-marker" },
|
2022-04-24 16:06:34 +00:00
|
|
|
{ tag: ct.CodeInfoTag, class: "code-info" },
|
2022-04-11 18:34:09 +00:00
|
|
|
{ tag: ct.CommentTag, class: "comment" },
|
|
|
|
{ tag: ct.CommentMarkerTag, class: "comment-marker" },
|
2022-07-04 13:07:27 +00:00
|
|
|
{ tag: ct.Highlight, class: "highlight" },
|
2022-04-11 18:34:09 +00:00
|
|
|
{ tag: t.emphasis, class: "emphasis" },
|
|
|
|
{ tag: t.strong, class: "strong" },
|
|
|
|
{ tag: t.atom, class: "atom" },
|
|
|
|
{ tag: t.bool, class: "bool" },
|
|
|
|
{ tag: t.url, class: "url" },
|
|
|
|
{ tag: t.inserted, class: "inserted" },
|
|
|
|
{ tag: t.deleted, class: "deleted" },
|
|
|
|
{ tag: t.literal, class: "literal" },
|
2022-04-24 16:06:34 +00:00
|
|
|
{ tag: t.keyword, class: "keyword" },
|
2022-04-11 18:34:09 +00:00
|
|
|
{ tag: t.list, class: "list" },
|
2022-06-13 16:31:36 +00:00
|
|
|
// { tag: t.def, class: "li" },
|
2022-04-11 18:34:09 +00:00
|
|
|
{ tag: t.string, class: "string" },
|
|
|
|
{ tag: t.number, class: "number" },
|
|
|
|
{ tag: [t.regexp, t.escape, t.special(t.string)], class: "string2" },
|
|
|
|
{ tag: t.variableName, class: "variableName" },
|
2022-04-24 16:06:34 +00:00
|
|
|
{ tag: t.typeName, class: "typeName" },
|
2022-04-11 18:34:09 +00:00
|
|
|
{ tag: t.comment, class: "comment" },
|
|
|
|
{ tag: t.invalid, class: "invalid" },
|
2022-04-20 08:56:43 +00:00
|
|
|
{ tag: t.processingInstruction, class: "meta" },
|
|
|
|
// { tag: t.content, class: "tbl-content" },
|
2022-04-11 18:34:09 +00:00
|
|
|
{ tag: t.punctuation, class: "punctuation" },
|
|
|
|
...mdExtension.map((mdExt) => {
|
|
|
|
return { tag: mdExt.tag, ...mdExt.styles };
|
|
|
|
}),
|
|
|
|
]);
|
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
|
|
|
}
|