YAML, TS and JS highlighting

pull/87/head
Zef Hemel 2022-10-07 17:01:44 +02:00
parent bc1c38d77c
commit efeadfb1a0
5 changed files with 43 additions and 9 deletions

View File

@ -2,11 +2,8 @@ export {
autocompletion, autocompletion,
CompletionContext, CompletionContext,
completionKeymap, completionKeymap,
} from "https://esm.sh/@codemirror/autocomplete@6.3.0?external=@codemirror/state,@lezer/common"; } from "@codemirror/autocomplete";
export type { export type { Completion, CompletionResult } from "@codemirror/autocomplete";
Completion,
CompletionResult,
} from "https://esm.sh/@codemirror/autocomplete@6.3.0?external=@codemirror/state,@lezer/common,@codemirror/view";
export * as YAML from "https://deno.land/std@0.158.0/encoding/yaml.ts"; export * as YAML from "https://deno.land/std@0.158.0/encoding/yaml.ts";
export * as path from "https://deno.land/std@0.158.0/path/mod.ts"; export * as path from "https://deno.land/std@0.158.0/path/mod.ts";
@ -85,11 +82,19 @@ export {
foldNodeProp, foldNodeProp,
HighlightStyle, HighlightStyle,
indentNodeProp, indentNodeProp,
indentOnInput,
Language, Language,
languageDataProp, languageDataProp,
LanguageDescription, LanguageDescription,
LanguageSupport, LanguageSupport,
ParseContext, ParseContext,
StreamLanguage,
syntaxHighlighting, syntaxHighlighting,
syntaxTree, syntaxTree,
} from "@codemirror/language"; } from "@codemirror/language";
export { yaml as yamlLanguage } from "https://esm.sh/@codemirror/legacy-modes@6.1.0/mode/yaml?external=@codemirror/language";
export {
javascriptLanguage,
typescriptLanguage,
} from "https://esm.sh/@codemirror/lang-javascript@6.1.0?external=@codemirror/language,@codemirror/autocomplete,@codemirror/view,@codemirror/state,@codemirror/lint,@lezer/common,@lezer/lr,@lezer/javascript,@codemirror/commands";

File diff suppressed because one or more lines are too long

View File

@ -3,10 +3,13 @@
"@codemirror/state": "https://esm.sh/@codemirror/state@6.1.2", "@codemirror/state": "https://esm.sh/@codemirror/state@6.1.2",
"@lezer/common": "https://esm.sh/@lezer/common@1.0.1", "@lezer/common": "https://esm.sh/@lezer/common@1.0.1",
"@lezer/markdown": "https://esm.sh/@lezer/markdown@1.0.2?external=@lezer/common,@codemirror/language,@lezer/highlight", "@lezer/markdown": "https://esm.sh/@lezer/markdown@1.0.2?external=@lezer/common,@codemirror/language,@lezer/highlight",
"@lezer/javascript": "https://esm.sh/@lezer/javascript@1.0.2?external=@lezer/common,@codemirror/language,@lezer/highlight",
"@codemirror/language": "https://esm.sh/@codemirror/language@6.2.1?external=@codemirror/state,@lezer/common,@lezer/lr,@codemirror/view,@lezer/highlight", "@codemirror/language": "https://esm.sh/@codemirror/language@6.2.1?external=@codemirror/state,@lezer/common,@lezer/lr,@codemirror/view,@lezer/highlight",
"@codemirror/commands": "https://esm.sh/@codemirror/commands@6.1.1?external=@codemirror/state,@codemirror/view", "@codemirror/commands": "https://esm.sh/@codemirror/commands@6.1.1?external=@codemirror/state,@codemirror/view",
"@codemirror/view": "https://esm.sh/@codemirror/view@6.3.0?external=@codemirror/state,@lezer/common", "@codemirror/view": "https://esm.sh/@codemirror/view@6.3.0?external=@codemirror/state,@lezer/common",
"@lezer/highlight": "https://esm.sh/@lezer/highlight@1.1.1?external=@lezer/common", "@lezer/highlight": "https://esm.sh/@lezer/highlight@1.1.1?external=@lezer/common",
"@codemirror/autocomplete": "https://esm.sh/@codemirror/autocomplete@6.3.0?external=@codemirror/state,@lezer/common",
"@codemirror/lint": "https://esm.sh/@codemirror/lint@6.0.0?external=@codemirror/state,@lezer/common",
"$sb/": "./packages/", "$sb/": "./packages/",
"handlebars": "https://esm.sh/handlebars", "handlebars": "https://esm.sh/handlebars",
"@lezer/lr": "https://esm.sh/@lezer/lr", "@lezer/lr": "https://esm.sh/@lezer/lr",

View File

@ -1,10 +1,13 @@
import { import {
BlockContext, BlockContext,
Language, Language,
LanguageDescription,
LanguageSupport,
LeafBlock, LeafBlock,
LeafBlockParser, LeafBlockParser,
markdown, markdown,
MarkdownConfig, MarkdownConfig,
parseCode,
styleTags, styleTags,
Table, Table,
tags as t, tags as t,
@ -17,7 +20,6 @@ import {
mdExtensionSyntaxConfig, mdExtensionSyntaxConfig,
} from "./markdown_ext.ts"; } from "./markdown_ext.ts";
// import { markdown } from "./markdown/index.ts";
export const pageLinkRegex = /^\[\[([^\]]+)\]\]/; export const pageLinkRegex = /^\[\[([^\]]+)\]\]/;
const WikiLink: MarkdownConfig = { const WikiLink: MarkdownConfig = {

View File

@ -7,7 +7,6 @@ import {
closeBracketsKeymap, closeBracketsKeymap,
completionKeymap, completionKeymap,
CompletionResult, CompletionResult,
defaultHighlightStyle,
drawSelection, drawSelection,
dropCursor, dropCursor,
EditorSelection, EditorSelection,
@ -16,16 +15,23 @@ import {
highlightSpecialChars, highlightSpecialChars,
history, history,
historyKeymap, historyKeymap,
indentOnInput,
indentWithTab, indentWithTab,
javascriptLanguage,
KeyBinding, KeyBinding,
keymap, keymap,
LanguageDescription,
LanguageSupport,
runScopeHandlers, runScopeHandlers,
searchKeymap, searchKeymap,
standardKeymap, standardKeymap,
StreamLanguage,
syntaxHighlighting, syntaxHighlighting,
syntaxTree, syntaxTree,
typescriptLanguage,
ViewPlugin, ViewPlugin,
ViewUpdate, ViewUpdate,
yamlLanguage,
} from "../../dep_common.ts"; } from "../../dep_common.ts";
import { SilverBulletHooks } from "../common/manifest.ts"; import { SilverBulletHooks } from "../common/manifest.ts";
// import { markdown } from "../common/_markdown/index.ts"; // import { markdown } from "../common/_markdown/index.ts";
@ -413,6 +419,23 @@ export class Editor {
extensions: [ extensions: [
markdown({ markdown({
base: buildMarkdown(this.mdExtensions), base: buildMarkdown(this.mdExtensions),
codeLanguages: [
LanguageDescription.of({
name: "yaml",
alias: ["meta", "data"],
support: new LanguageSupport(StreamLanguage.define(yamlLanguage)),
}),
LanguageDescription.of({
name: "javascript",
alias: ["js"],
support: new LanguageSupport(javascriptLanguage),
}),
LanguageDescription.of({
name: "typescript",
alias: ["ts"],
support: new LanguageSupport(typescriptLanguage),
}),
],
addKeymap: true, addKeymap: true,
}), }),
syntaxHighlighting(customMarkdownStyle(this.mdExtensions)), syntaxHighlighting(customMarkdownStyle(this.mdExtensions)),
@ -429,6 +452,7 @@ export class Editor {
history(), history(),
drawSelection(), drawSelection(),
dropCursor(), dropCursor(),
indentOnInput(),
EditorView.lineWrapping, EditorView.lineWrapping,
lineWrapper([ lineWrapper([
{ selector: "ATXHeading1", class: "sb-line-h1" }, { selector: "ATXHeading1", class: "sb-line-h1" },