Mostly working except yaml codeblocks

pull/3/head
Zef Hemel 2022-06-13 18:31:36 +02:00
parent 24ac6bbd25
commit c25a53357d
36 changed files with 4893 additions and 43235 deletions

View File

@ -1,4 +0,0 @@
{
"12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true,
"40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true
}

14
mobile/.gitignore vendored
View File

@ -1,14 +0,0 @@
node_modules/
.expo/
dist/
npm-debug.*
*.jks
*.p8
*.p12
*.key
*.mobileprovision
*.orig.*
web-build/
# macOS
.DS_Store

View File

@ -1,47 +0,0 @@
import { StatusBar } from "expo-status-bar";
import React from "react";
import { SafeAreaView, StyleSheet, Text } from "react-native";
import { WebView } from "react-native-webview";
function safeRun(fn: () => Promise<void>) {
return fn().catch((e) => {
console.error(e);
});
}
export default function App() {
const html = require("./bundle.json");
let ref = React.useRef<WebView>(null);
return (
<SafeAreaView style={styles.container}>
<Text
style={{
color: "#fff",
backgroundColor: "#333",
height: 40,
}}
onPress={() => {
ref.current?.injectJavaScript('receiveMessage("Sup");');
}}
>
This is a header
</Text>
<WebView
style={styles.container}
ref={ref}
originWhitelist={["*"]}
source={{ html: html.html }}
onMessage={(event) => {
console.log("Got event", event.nativeEvent.data);
}}
/>
<StatusBar style="auto" />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});

View File

@ -1,32 +0,0 @@
{
"expo": {
"name": "mobile",
"slug": "mobile",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
}
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

View File

@ -1,6 +0,0 @@
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};

View File

@ -1,6 +0,0 @@
import json
html = open("dist/index.html", "r").read()
f = open("bundle.json", "w")
f.write(json.dumps({"html": html}))
f.close()

File diff suppressed because one or more lines are too long

View File

@ -1,45 +0,0 @@
// declare namespace window {
// var ReactNativeWebView: any;
// var receiveMessage: any;
// }
//
// function safeRun(fn: () => Promise<void>) {
// fn().catch((e) => {
// console.error(e);
// });
// }
//
// window.receiveMessage = (msg: string) => {
// console.log("Received message", msg);
// };
// // @ts-ignore
// window.onerror = (msg, source, lineno, colno, error) => {
// console.error("Error", msg, source, lineno, error);
// };
//
// console.log = (...args) => {
// window.ReactNativeWebView.postMessage(
// JSON.stringify({ type: "console.log", args: args })
// );
// };
//
// console.error = (...args) => {
// window.ReactNativeWebView.postMessage(
// JSON.stringify({ type: "console.error", args: args })
// );
// };
try {
// let editor = new Editor(
// new Space(`http://192.168.2.22:3000/fs`, null),
// document.getElementById("root")!
// );
// console.log("Initing editor");
// safeRun(async () => {
// await editor.loadPageList();
// await editor.loadPlugs();
// editor.focus();
// console.log("Inited", editor.viewState);
// });
} catch (e: any) {
console.error("Got an error", e.message);
}

View File

@ -1,19 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Page</title>
<style>
@import "../../webapp/src/styles/main.scss";
</style>
<script type="module" src="server.ts"></script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
</head>
<body>
<div id="root"></div>
<script type="module">
import "./server";
</script>
</body>
</html>

View File

@ -1,31 +0,0 @@
{
"name": "mobile",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"expo": "~44.0.0",
"expo-status-bar": "~1.2.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-fs": "^2.19.0",
"react-native-web": "0.17.1",
"react-native-webview": "11.15.0"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@parcel/transformer-sass": "2.3.2",
"@types/react": "~17.0.21",
"@types/react-native": "~0.64.12",
"parcel": "^2.3.2",
"typescript": "~4.3.5"
},
"private": true
}

View File

@ -1,6 +0,0 @@
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true
}
}

File diff suppressed because it is too large Load Diff

7456
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,9 +3,6 @@
"private": true, "private": true,
"version": "0.0.1", "version": "0.0.1",
"license": "MIT", "license": "MIT",
"resolutions": {
"@lezer/common": "https://github.com/zefhemel/common.git#046c880d1fcab713cadad327a5b7d8bb5de6522c"
},
"scripts": { "scripts": {
"watch": "rm -rf .parcel-cache && parcel watch --no-hmr packages/{web,server,plugos,plugs} desktop", "watch": "rm -rf .parcel-cache && parcel watch --no-hmr packages/{web,server,plugos,plugs} desktop",
"clean": "rm -rf .parcel-cache packages/*/dist", "clean": "rm -rf .parcel-cache packages/*/dist",

View File

@ -1,4 +1,4 @@
import { Tag } from "@codemirror/highlight"; import { Tag } from "@lezer/highlight";
export const WikiLinkTag = Tag.define(); export const WikiLinkTag = Tag.define();
export const WikiLinkPageTag = Tag.define(); export const WikiLinkPageTag = Tag.define();

View File

@ -1,4 +1,9 @@
import { ChangeSpec, EditorSelection, StateCommand, Text } from "@codemirror/state"; import {
StateCommand,
Text,
EditorSelection,
ChangeSpec,
} from "@codemirror/state";
import { syntaxTree } from "@codemirror/language"; import { syntaxTree } from "@codemirror/language";
import { SyntaxNode, Tree } from "@lezer/common"; import { SyntaxNode, Tree } from "@lezer/common";
import { markdownLanguage } from "./markdown"; import { markdownLanguage } from "./markdown";
@ -20,11 +25,8 @@ class Context {
blank(trailing: boolean = true) { blank(trailing: boolean = true) {
let result = this.spaceBefore; let result = this.spaceBefore;
if (this.node.name == "Blockquote") { if (this.node.name == "Blockquote") result += ">";
result += ">"; else
} else if (this.node.name == "Comment") {
result += "%%";
} else
for ( for (
let i = this.to - this.from - result.length - this.spaceAfter.length; let i = this.to - this.from - result.length - this.spaceAfter.length;
i > 0; i > 0;
@ -50,12 +52,7 @@ function getContext(node: SyntaxNode, line: string, doc: Text) {
cur && cur.name != "Document"; cur && cur.name != "Document";
cur = cur.parent cur = cur.parent
) { ) {
if ( if (cur.name == "ListItem" || cur.name == "Blockquote") nodes.push(cur);
cur.name == "ListItem" ||
cur.name == "Blockquote" ||
cur.name == "Comment"
)
nodes.push(cur);
} }
let context = [], let context = [],
pos = 0; pos = 0;
@ -69,12 +66,6 @@ function getContext(node: SyntaxNode, line: string, doc: Text) {
) { ) {
pos += match[0].length; pos += match[0].length;
context.push(new Context(node, start, pos, "", match[1], ">", null)); context.push(new Context(node, start, pos, "", match[1], ">", null));
} else if (
node.name == "Comment" &&
(match = /^[ \t]*%%( ?)/.exec(line.slice(pos)))
) {
pos += match[0].length;
context.push(new Context(node, start, pos, "", match[1], "%%", null));
} else if ( } else if (
node.name == "ListItem" && node.name == "ListItem" &&
node.parent!.name == "OrderedList" && node.parent!.name == "OrderedList" &&
@ -93,17 +84,21 @@ function getContext(node: SyntaxNode, line: string, doc: Text) {
} else if ( } else if (
node.name == "ListItem" && node.name == "ListItem" &&
node.parent!.name == "BulletList" && node.parent!.name == "BulletList" &&
(match = /^([ \t]*)([-+*])([ \t]+)/.exec(nodeStart(node, doc))) (match = /^([ \t]*)([-+*])([ \t]{1,4}\[[ xX]\])?([ \t]+)/.exec(
nodeStart(node, doc)
))
) { ) {
let after = match[3], let after = match[4],
len = match[0].length; len = match[0].length;
if (after.length > 4) { if (after.length > 4) {
after = after.slice(0, after.length - 4); after = after.slice(0, after.length - 4);
len -= 4; len -= 4;
} }
let type = match[2];
if (match[3]) type += match[3].replace(/[xX]/, " ");
pos += len; pos += len;
context.push( context.push(
new Context(node.parent!, start, pos, match[1], after, match[2], node) new Context(node.parent!, start, pos, match[1], after, type, node)
); );
} }
} }
@ -229,19 +224,6 @@ export const insertNewlineContinueMarkup: StateCommand = ({
} }
} }
if (inner.node.name == "Comment" && emptyLine && line.from) {
let prevLine = doc.lineAt(line.from - 1),
commented = /%%\s*$/.exec(prevLine.text);
// Two aligned empty quoted lines in a row
if (commented && commented.index == inner.from) {
let changes = state.changes([
{ from: prevLine.from + commented.index, to: prevLine.to },
{ from: line.from + inner.from, to: line.to },
]);
return { range: range.map(changes), changes };
}
}
let changes: ChangeSpec[] = []; let changes: ChangeSpec[] = [];
if (inner.node.name == "OrderedList") if (inner.node.name == "OrderedList")
renumberList(inner.item!, doc, changes); renumberList(inner.item!, doc, changes);

View File

@ -1,11 +1,19 @@
import { Prec } from "@codemirror/state"; import { Prec } from "@codemirror/state";
import { KeyBinding, keymap } from "@codemirror/view"; import { KeyBinding, keymap } from "@codemirror/view";
import { Language, LanguageDescription, LanguageSupport } from "@codemirror/language"; import {
Language,
LanguageSupport,
LanguageDescription,
} from "@codemirror/language";
import { MarkdownExtension, MarkdownParser, parseCode } from "@lezer/markdown"; import { MarkdownExtension, MarkdownParser, parseCode } from "@lezer/markdown";
import { html } from "@codemirror/lang-html"; import { html } from "@codemirror/lang-html";
import { commonmarkLanguage, getCodeParser, markdownLanguage, mkLang } from "./markdown"; import {
import { deleteMarkupBackward, insertNewlineContinueMarkup } from "./commands"; commonmarkLanguage,
markdownLanguage,
mkLang,
getCodeParser,
} from "./markdown";
import { insertNewlineContinueMarkup, deleteMarkupBackward } from "./commands";
export { export {
commonmarkLanguage, commonmarkLanguage,
markdownLanguage, markdownLanguage,
@ -30,11 +38,15 @@ export function markdown(
/// When given, this language will be used by default to parse code /// When given, this language will be used by default to parse code
/// blocks. /// blocks.
defaultCodeLanguage?: Language | LanguageSupport; defaultCodeLanguage?: Language | LanguageSupport;
/// A collection of language descriptions to search through for a /// A source of language support for highlighting fenced code
/// matching language (with /// blocks. When it is an array, the parser will use
/// [`LanguageDescription.matchLanguageName`](#language.LanguageDescription^matchLanguageName)) /// [`LanguageDescription.matchLanguageName`](#language.LanguageDescription^matchLanguageName)
/// when a fenced code block has an info string. /// with the fenced code info to find a matching language. When it
codeLanguages?: readonly LanguageDescription[]; /// is a function, will be called with the info string and may
/// return a language or `LanguageDescription` object.
codeLanguages?:
| readonly LanguageDescription[]
| ((info: string) => Language | LanguageDescription | null);
/// Set this to false to disable installation of the Markdown /// Set this to false to disable installation of the Markdown
/// [keymap](#lang-markdown.markdownKeymap). /// [keymap](#lang-markdown.markdownKeymap).
addKeymap?: boolean; addKeymap?: boolean;
@ -68,7 +80,7 @@ export function markdown(
} }
let codeParser = let codeParser =
codeLanguages || defaultCode codeLanguages || defaultCode
? getCodeParser(codeLanguages || [], defaultCode) ? getCodeParser(codeLanguages, defaultCode)
: undefined; : undefined;
extensions.push( extensions.push(
parseCode({ codeParser, htmlParser: htmlNoMatch.language.parser }) parseCode({ codeParser, htmlParser: htmlNoMatch.language.parser })

View File

@ -1,43 +1,25 @@
import { import {
Language,
defineLanguageFacet, defineLanguageFacet,
languageDataProp,
foldNodeProp, foldNodeProp,
indentNodeProp, indentNodeProp,
Language,
languageDataProp,
LanguageDescription, LanguageDescription,
ParseContext ParseContext,
} from "@codemirror/language"; } from "@codemirror/language";
import { styleTags, tags as t } from "@codemirror/highlight"; import {
import { Emoji, GFM, MarkdownParser, parser as baseParser, Subscript, Superscript } from "@lezer/markdown"; parser as baseParser,
MarkdownParser,
GFM,
Subscript,
Superscript,
Emoji,
} from "@lezer/markdown";
const data = defineLanguageFacet({ block: { open: "<!--", close: "-->" } }); const data = defineLanguageFacet({ block: { open: "<!--", close: "-->" } });
export const commonmark = baseParser.configure({ export const commonmark = baseParser.configure({
props: [ props: [
styleTags({
"Blockquote/...": t.quote,
HorizontalRule: t.contentSeparator,
"ATXHeading1/... SetextHeading1/...": t.heading1,
"ATXHeading2/... SetextHeading2/...": t.heading2,
"ATXHeading3/...": t.heading3,
"ATXHeading4/...": t.heading4,
"ATXHeading5/...": t.heading5,
"ATXHeading6/...": t.heading6,
"Comment CommentBlock": t.comment,
Escape: t.escape,
Entity: t.character,
"Emphasis/...": t.emphasis,
"StrongEmphasis/...": t.strong,
"Link/... Image/...": t.link,
"OrderedList/... BulletList/...": t.list,
"InlineCode CodeText": t.monospace,
URL: t.url,
"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark":
t.processingInstruction,
"CodeInfo LinkLabel": t.labelName,
LinkTitle: t.string,
Paragraph: t.content,
}),
foldNodeProp.add((type) => { foldNodeProp.add((type) => {
if (!type.is("Block") || type.is("Document")) return undefined; if (!type.is("Block") || type.is("Document")) return undefined;
return (tree, state) => ({ return (tree, state) => ({
@ -55,51 +37,36 @@ export const commonmark = baseParser.configure({
}); });
export function mkLang(parser: MarkdownParser) { export function mkLang(parser: MarkdownParser) {
return new Language( return new Language(data, parser);
data,
parser,
parser.nodeSet.types.find((t) => t.name == "Document")!
);
} }
/// Language support for strict CommonMark. /// Language support for strict CommonMark.
export const commonmarkLanguage = mkLang(commonmark); export const commonmarkLanguage = mkLang(commonmark);
const extended = commonmark.configure([ const extended = commonmark.configure([GFM, Subscript, Superscript, Emoji]);
GFM,
Subscript,
Superscript,
Emoji,
{
props: [
styleTags({
"TableDelimiter SubscriptMark SuperscriptMark StrikethroughMark":
t.processingInstruction,
"TableHeader/...": t.heading,
"Strikethrough/...": t.strikethrough,
TaskMarker: t.atom,
Task: t.list,
Emoji: t.character,
"Subscript Superscript": t.special(t.content),
TableCell: t.content,
}),
],
},
]);
/// Language support for [GFM](https://github.github.com/gfm/) plus /// Language support for [GFM](https://github.github.com/gfm/) plus
/// subscript, superscript, and emoji syntax. /// subscript, superscript, and emoji syntax.
export const markdownLanguage = mkLang(extended); export const markdownLanguage = mkLang(extended);
export function getCodeParser( export function getCodeParser(
languages: readonly LanguageDescription[], languages:
| readonly LanguageDescription[]
| ((info: string) => Language | LanguageDescription | null)
| undefined,
defaultLanguage?: Language defaultLanguage?: Language
) { ) {
return (info: string) => { return (info: string) => {
let found = if (info && languages) {
info && LanguageDescription.matchLanguageName(languages, info, true); let found = null;
if (!found) return defaultLanguage ? defaultLanguage.parser : null; if (typeof languages == "function") found = languages(info);
if (found.support) return found.support.language.parser; else found = LanguageDescription.matchLanguageName(languages, info, true);
return ParseContext.getSkippingParser(found.load()); if (found instanceof LanguageDescription)
return found.support
? found.support.language.parser
: ParseContext.getSkippingParser(found.load());
else if (found) return found.parser;
}
return defaultLanguage ? defaultLanguage.parser : null;
}; };
} }

View File

@ -1,4 +1,4 @@
import { Tag } from "@codemirror/highlight"; import { Tag } from "@lezer/highlight";
import type { MarkdownConfig } from "@lezer/markdown"; import type { MarkdownConfig } from "@lezer/markdown";
import { System } from "@plugos/plugos/system"; import { System } from "@plugos/plugos/system";
import { Manifest } from "@silverbulletmd/common/manifest"; import { Manifest } from "@silverbulletmd/common/manifest";

View File

@ -7,11 +7,17 @@
"version": "0.0.1", "version": "0.0.1",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@codemirror/highlight": "^0.19.0", "@codemirror/autocomplete": "6.0.1",
"@codemirror/language": "^0.19.0", "@codemirror/commands": "6.0.0",
"@codemirror/stream-parser": "^0.19.9", "@codemirror/lang-html": "6.0.0",
"@codemirror/lang-javascript": "^0.19.7", "@codemirror/lang-javascript": "6.0.0",
"@codemirror/legacy-modes": "^0.19.1", "@codemirror/language": "6.0.0",
"@lezer/markdown": "^0.15.0" "@codemirror/legacy-modes": "6.0.0",
"@codemirror/search": "6.0.0",
"@codemirror/state": "6.0.0",
"@codemirror/view": "6.0.0",
"@lezer/highlight": "1.0.0",
"@lezer/markdown": "1.0.0",
"@lezer/common": "1.0.0"
} }
} }

View File

@ -1,4 +1,4 @@
import { styleTags, tags as t } from "@codemirror/highlight"; import { styleTags, tags as t } from "@lezer/highlight";
import { import {
BlockContext, BlockContext,
LeafBlock, LeafBlock,
@ -15,7 +15,7 @@ import {
LanguageDescription, LanguageDescription,
LanguageSupport, LanguageSupport,
} from "@codemirror/language"; } from "@codemirror/language";
import { StreamLanguage } from "@codemirror/stream-parser"; import { StreamLanguage } from "@codemirror/language";
import { yaml } from "@codemirror/legacy-modes/mode/yaml"; import { yaml } from "@codemirror/legacy-modes/mode/yaml";
import { import {
javascriptLanguage, javascriptLanguage,

View File

@ -64,7 +64,7 @@
"typescript": "^4.6.2" "typescript": "^4.6.2"
}, },
"devDependencies": { "devDependencies": {
"@lezer/lr": "^0.15.0", "@lezer/lr": "1.0.0",
"@parcel/optimizer-data-url": "2.6.0", "@parcel/optimizer-data-url": "2.6.0",
"@parcel/packager-raw-url": "2.6.0", "@parcel/packager-raw-url": "2.6.0",
"@parcel/service-worker": "2.6.0", "@parcel/service-worker": "2.6.0",

View File

@ -32,8 +32,8 @@
}, },
"dependencies": { "dependencies": {
"@jest/globals": "^27.5.1", "@jest/globals": "^27.5.1",
"@lezer/generator": "^0.15.4", "@lezer/generator": "1.0.0",
"@lezer/lr": "^0.15.8", "@lezer/lr": "1.0.0",
"@mattermost/client": "^6.7.0-0", "@mattermost/client": "^6.7.0-0",
"@mattermost/types": "^6.7.0-0", "@mattermost/types": "^6.7.0-0",
"@types/yaml": "^1.9.7", "@types/yaml": "^1.9.7",

File diff suppressed because it is too large Load Diff

View File

@ -37,13 +37,11 @@
} }
}, },
"dependencies": { "dependencies": {
"@codemirror/lang-javascript": "^0.19.7", "@codemirror/lang-javascript": "6.0.0",
"@codemirror/lang-markdown": "^0.19.6", "@codemirror/language": "6.0.0",
"@codemirror/language": "^0.19.0", "@codemirror/legacy-modes": "6.0.0",
"@codemirror/legacy-modes": "^0.19.1",
"@codemirror/stream-parser": "^0.19.9",
"@jest/globals": "^27.5.1", "@jest/globals": "^27.5.1",
"@lezer/markdown": "^0.15.0", "@lezer/markdown": "1.0.0",
"@silverbulletmd/web": "^0.0.2", "@silverbulletmd/web": "^0.0.2",
"better-sqlite3": "^7.5.0", "better-sqlite3": "^7.5.0",
"body-parser": "^1.19.2", "body-parser": "^1.19.2",

View File

@ -1,5 +1,5 @@
import { EditorSelection, StateCommand, Transaction } from "@codemirror/state"; import { EditorSelection, StateCommand, Transaction } from "@codemirror/state";
import { Text } from "@codemirror/text"; import { Text } from "@codemirror/state";
export function insertMarker(marker: string): StateCommand { export function insertMarker(marker: string): StateCommand {
return ({ state, dispatch }) => { return ({ state, dispatch }) => {

View File

@ -3,10 +3,14 @@ import {
completionKeymap, completionKeymap,
CompletionResult, CompletionResult,
} from "@codemirror/autocomplete"; } from "@codemirror/autocomplete";
import { closeBrackets, closeBracketsKeymap } from "@codemirror/closebrackets"; import { closeBrackets, closeBracketsKeymap } from "@codemirror/autocomplete";
import { indentWithTab, standardKeymap } from "@codemirror/commands"; import { indentWithTab, standardKeymap } from "@codemirror/commands";
import { history, historyKeymap } from "@codemirror/history"; import { history, historyKeymap } from "@codemirror/commands";
import { bracketMatching } from "@codemirror/matchbrackets"; import {
bracketMatching,
defaultHighlightStyle,
syntaxHighlighting,
} from "@codemirror/language";
import { searchKeymap } from "@codemirror/search"; import { searchKeymap } from "@codemirror/search";
import { EditorSelection, EditorState } from "@codemirror/state"; import { EditorSelection, EditorState } from "@codemirror/state";
import { import {
@ -315,7 +319,8 @@ export class Editor {
history(), history(),
drawSelection(), drawSelection(),
dropCursor(), dropCursor(),
customMarkdownStyle(this.mdExtensions), syntaxHighlighting(customMarkdownStyle(this.mdExtensions)),
// syntaxHighlighting(defaultHighlightStyle),
bracketMatching(), bracketMatching(),
closeBrackets(), closeBrackets(),
autocompletion({ autocompletion({

View File

@ -1,7 +1,13 @@
import { syntaxTree } from "@codemirror/language"; import { syntaxTree } from "@codemirror/language";
import { Decoration, DecorationSet, EditorView, ViewPlugin, ViewUpdate } from "@codemirror/view"; import {
Decoration,
DecorationSet,
EditorView,
ViewPlugin,
ViewUpdate,
} from "@codemirror/view";
import { Range } from "@codemirror/rangeset"; import { Range } from "@codemirror/state";
interface WrapElement { interface WrapElement {
selector: string; selector: string;
@ -17,7 +23,7 @@ function wrapLines(view: EditorView, wrapElements: WrapElement[]) {
syntaxTree(view.state).iterate({ syntaxTree(view.state).iterate({
from, from,
to, to,
enter: (type, from, to) => { enter: ({ type, from, to }) => {
const bodyText = doc.sliceString(from, to); const bodyText = doc.sliceString(from, to);
for (let wrapElement of wrapElements) { for (let wrapElement of wrapElements) {
if (type.name == wrapElement.selector) { if (type.name == wrapElement.selector) {
@ -41,7 +47,7 @@ function wrapLines(view: EditorView, wrapElements: WrapElement[]) {
} }
} }
}, },
leave(type, from: number, to: number) { leave({ type }) {
for (let wrapElement of wrapElements) { for (let wrapElement of wrapElements) {
if (type.name == wrapElement.selector && wrapElement.nesting) { if (type.name == wrapElement.selector && wrapElement.nesting) {
elementStack.pop(); elementStack.pop();

File diff suppressed because it is too large Load Diff

View File

@ -26,27 +26,21 @@
"dist" "dist"
], ],
"dependencies": { "dependencies": {
"@codemirror/autocomplete": "^0.19.1", "@codemirror/autocomplete": "6.0.1",
"@codemirror/closebrackets": "^0.19.1", "@codemirror/commands": "6.0.0",
"@codemirror/commands": "^0.19.8", "@codemirror/lang-javascript": "6.0.0",
"@codemirror/highlight": "^0.19.0", "@codemirror/lang-markdown": "6.0.0",
"@codemirror/history": "^0.19.2", "@codemirror/language": "6.0.0",
"@codemirror/lang-html": "^0.19.4", "@codemirror/legacy-modes": "6.0.0",
"@codemirror/lang-javascript": "^0.19.7", "@codemirror/search": "6.0.0",
"@codemirror/lang-markdown": "^0.19.6", "@codemirror/state": "6.0.0",
"@codemirror/language": "^0.19.0", "@codemirror/view": "6.0.0",
"@codemirror/legacy-modes": "^0.19.1",
"@codemirror/matchbrackets": "^0.19.4",
"@codemirror/search": "^0.19.9",
"@codemirror/state": "^0.19.7",
"@codemirror/stream-parser": "^0.19.9",
"@codemirror/text": "^0.19.6",
"@codemirror/view": "^0.19.42",
"@fortawesome/fontawesome-svg-core": "1.3.0", "@fortawesome/fontawesome-svg-core": "1.3.0",
"@fortawesome/free-solid-svg-icons": "6.0.0", "@fortawesome/free-solid-svg-icons": "6.0.0",
"@fortawesome/react-fontawesome": "0.1.17", "@fortawesome/react-fontawesome": "0.1.17",
"@jest/globals": "^27.5.1", "@jest/globals": "^27.5.1",
"@lezer/markdown": "^0.15.0", "@lezer/highlight": "1.0.0",
"@lezer/markdown": "1.0.0",
"fake-indexeddb": "^3.1.7", "fake-indexeddb": "^3.1.7",
"fuzzysort": "^1.9.0", "fuzzysort": "^1.9.0",
"jest": "^27.5.1", "jest": "^27.5.1",

View File

@ -1,9 +1,10 @@
import { HighlightStyle, tags as t } from "@codemirror/highlight"; import { HighlightStyle } from "@codemirror/language";
import { tags as t } from "@lezer/highlight";
import * as ct from "@silverbulletmd/common/customtags"; import * as ct from "@silverbulletmd/common/customtags";
import { MDExt } from "@silverbulletmd/common/markdown_ext"; import { MDExt } from "@silverbulletmd/common/markdown_ext";
export default function highlightStyles(mdExtension: MDExt[]) { export default function highlightStyles(mdExtension: MDExt[]) {
return HighlightStyle.define([ const hls = HighlightStyle.define([
{ tag: t.heading1, class: "h1" }, { tag: t.heading1, class: "h1" },
{ tag: t.heading2, class: "h2" }, { tag: t.heading2, class: "h2" },
{ tag: t.heading3, class: "h3" }, { tag: t.heading3, class: "h3" },
@ -29,7 +30,7 @@ export default function highlightStyles(mdExtension: MDExt[]) {
{ tag: t.literal, class: "literal" }, { tag: t.literal, class: "literal" },
{ tag: t.keyword, class: "keyword" }, { tag: t.keyword, class: "keyword" },
{ tag: t.list, class: "list" }, { tag: t.list, class: "list" },
{ tag: t.definition, class: "li" }, // { tag: t.def, class: "li" },
{ tag: t.string, class: "string" }, { tag: t.string, class: "string" },
{ tag: t.number, class: "number" }, { tag: t.number, class: "number" },
{ tag: [t.regexp, t.escape, t.special(t.string)], class: "string2" }, { tag: [t.regexp, t.escape, t.special(t.string)], class: "string2" },
@ -44,4 +45,12 @@ export default function highlightStyles(mdExtension: MDExt[]) {
return { tag: mdExt.tag, ...mdExt.styles }; return { tag: mdExt.tag, ...mdExt.styles };
}), }),
]); ]);
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;
} }

3
resolutions Normal file
View File

@ -0,0 +1,3 @@
"resolutions": {
"@lezer/common": "https://github.com/zefhemel/common.git#046c880d1fcab713cadad327a5b7d8bb5de6522c"
},