Skip to content

Commit f5bd6d9

Browse files
committed
code highlighting
1 parent c607503 commit f5bd6d9

File tree

8 files changed

+371
-6
lines changed

8 files changed

+371
-6
lines changed

exampleVault/Input Fields/Editor.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ editor: |-
55
**test**
66
77
# Heading
8+
9+
[[Slider]]
810
---
911

1012
```meta-bind

exampleVault/Input Fields/Slider.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ INPUT[slider(addLabels, showcase):slider1]
1717
```meta-bind
1818
INPUT[slider(addLabels, minValue(-20), maxValue(20), showcase):slider2]
1919
```
20+
21+
```js
22+
let a = 5;
23+
```

exampleVault/Meta Bind JS.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
select: a
2+
select: c
33
---
44

55
test
@@ -17,4 +17,37 @@ const inputField = mb.createInputField(declaration, undefined, 'block');
1717
1818
ctx.addChild(inputField);
1919
```
20+
21+
```meta-bind-js
22+
const declaration = mb.createDeclaration(
23+
'select',
24+
[
25+
{type: 'option', value: 'd'},
26+
{type: 'option', value: 'e'},
27+
],
28+
'select'
29+
);
30+
31+
const inputField = mb.createInputField(declaration, undefined, 'block');
32+
33+
ctx.addChild(inputField);
34+
```
35+
36+
```js
37+
const declaration = mb.createDeclaration(
38+
'select',
39+
[
40+
{type: 'option', value: 'a'},
41+
{type: 'option', value: 'c'},
42+
],
43+
'select'
44+
);
45+
46+
0000
47+
48+
const inputField = mb.createInputField(declaration, undefined, 'block');
49+
50+
ctx.addChild(inputField);
51+
```
52+
2053
test
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
<%*
3+
const colors = ['orange','yellow','pink','blue','green'];
4+
let color = await tp.system.suggester(colors,colors,false,'Color');
5+
if (color !== null)
6+
{
7+
tR = `<span class="fs12 ${color}">${tp.file.selection()}</span>`;
8+
}
9+
-%>

package-lock.json

Lines changed: 116 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@typescript-eslint/eslint-plugin": "^5.30.0",
2222
"@typescript-eslint/parser": "^5.30.0",
2323
"@codemirror/view": "^6.7.2",
24+
"@codemirror/lang-javascript": "^6.1.2",
2425
"builtin-modules": "^3.3.0",
2526
"esbuild": "^0.14.47",
2627
"esbuild-plugin-copy-watch": "^0.0.7",
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: https://codemirror.net/LICENSE
3+
4+
// Utility function that allows modes to be combined. The mode given
5+
// as the base argument takes care of most of the normal mode
6+
// functionality, but a second (typically simple) mode is used, which
7+
// can override the style of text. Both modes get to parse all of the
8+
// text, but when both assign a non-null style to a piece of code, the
9+
// overlay wins, unless the combine argument was true and not overridden,
10+
// or state.overlay.combineTokens was true, in which case the styles are
11+
// combined.
12+
13+
(function (mod) {
14+
mod(window.CodeMirror);
15+
})(function (CodeMirror) {
16+
'use strict';
17+
18+
CodeMirror.customOverlayMode = function (base, overlay, combine) {
19+
return {
20+
startState: function () {
21+
return {
22+
base: CodeMirror.startState(base),
23+
overlay: CodeMirror.startState(overlay),
24+
basePos: 0,
25+
baseCur: null,
26+
overlayPos: 0,
27+
overlayCur: null,
28+
streamSeen: null,
29+
};
30+
},
31+
copyState: function (state) {
32+
return {
33+
base: CodeMirror.copyState(base, state.base),
34+
overlay: CodeMirror.copyState(overlay, state.overlay),
35+
basePos: state.basePos,
36+
baseCur: null,
37+
overlayPos: state.overlayPos,
38+
overlayCur: null,
39+
};
40+
},
41+
42+
token: function (stream, state) {
43+
if (stream != state.streamSeen || Math.min(state.basePos, state.overlayPos) < stream.start) {
44+
state.streamSeen = stream;
45+
state.basePos = state.overlayPos = stream.start;
46+
}
47+
48+
if (stream.start == state.basePos) {
49+
state.baseCur = base.token(stream, state.base);
50+
state.basePos = stream.pos;
51+
}
52+
if (stream.start == state.overlayPos) {
53+
stream.pos = stream.start;
54+
state.overlayCur = overlay.token(stream, state.overlay);
55+
state.overlayPos = stream.pos;
56+
}
57+
stream.pos = Math.min(state.basePos, state.overlayPos);
58+
59+
// // Edge case for codeblocks in templater mode
60+
// if (
61+
// state.baseCur &&
62+
// state.overlayCur &&
63+
// state.baseCur.contains("line-HyperMD-codeblock")
64+
// ) {
65+
// state.overlayCur = state.overlayCur.replace(
66+
// "line-templater-inline",
67+
// ""
68+
// );
69+
// state.overlayCur += ` line-background-HyperMD-codeblock-bg`;
70+
// }
71+
72+
// state.overlay.combineTokens always takes precedence over combine,
73+
// unless set to null
74+
if (state.overlayCur == null) return state.baseCur;
75+
else if ((state.baseCur != null && state.overlay.combineTokens) || (combine && state.overlay.combineTokens == null)) return state.baseCur + ' ' + state.overlayCur;
76+
else return state.overlayCur;
77+
},
78+
79+
indent:
80+
base.indent &&
81+
function (state, textAfter, line) {
82+
return base.indent(state.base, textAfter, line);
83+
},
84+
electricChars: base.electricChars,
85+
86+
innerMode: function (state) {
87+
return { state: state.base, mode: base };
88+
},
89+
90+
blankLine: function (state) {
91+
var baseToken, overlayToken;
92+
if (base.blankLine) baseToken = base.blankLine(state.base);
93+
if (overlay.blankLine) overlayToken = overlay.blankLine(state.overlay);
94+
95+
return overlayToken == null ? baseToken : combine && baseToken != null ? baseToken + ' ' + overlayToken : overlayToken;
96+
},
97+
};
98+
};
99+
});

0 commit comments

Comments
 (0)