Skip to content

Commit dd9942d

Browse files
Initial commit
0 parents  commit dd9942d

14 files changed

+3308
-0
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[*.{js,json,yml}]
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 2

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/.yarn/** linguist-vendored
2+
/.yarn/releases/* binary
3+
/.yarn/plugins/**/* binary
4+
/.pnp.* binary linguist-generated

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [RobTheFiveNine]

.github/images/example.png

71.3 KB
Loading

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.yarn/*
2+
!.yarn/patches
3+
!.yarn/plugins
4+
!.yarn/releases
5+
!.yarn/sdks
6+
!.yarn/versions
7+
8+
# Swap the comments on the following lines if you wish to use zero-installs
9+
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
10+
# Documentation here: https://yarnpkg.com/features/caching#zero-installs
11+
12+
#!.yarn/cache
13+
.pnp.*
14+
15+
# build fragments
16+
dist/

.yarn/releases/yarn-4.2.1.cjs

Lines changed: 894 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarnPath: .yarn/releases/yarn-4.2.1.cjs

LICENSE

Lines changed: 373 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Obsidian GDScript Syntax Highlighting Plugin
2+
3+
This plugin for Obsidian provides live syntax highlighting for GDScript (the language used in [Godot](https://godotengine.org/)).
4+
5+
An example of the highlighting can be seen below:
6+
7+
![](.github/images/example.png)
8+
9+
## Setup (manual)
10+
The plugin is going to be submitted to the Obsidian team to hopefully be approved as a community plugin, but for now, if you wish to install the plugin manually.
11+
12+
1. Navigate to the vault you wish to install it in using your file explorer
13+
2. Navigate into the `.obisidian` directory, and in there, go into the `plugins` directory
14+
3. Create a new folder in here named `gdscript-syntax-highlighting`
15+
4. Head over to the [Latest Release](https://github.com/RobTheFiveNine/obsidian-gdscript/releases/latest) and download the `main.js` and `manifest.json` files into the newly created folder.
16+
5. Open the settings window in Obsidian and enable the plugin in the `Community plugins` section
17+
18+
## License
19+
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

manifest.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"author":"RobTheFiveNine",
3+
"authorUrl": "https://github.com/RobTheFiveNine/obsidian-gdscript",
4+
"description": "Adds live GDScript syntax highlighting to code blocks in the Obsidian editor.",
5+
"fundingUrl": "https://github.com/sponsors/RobTheFiveNine",
6+
"id": "gdscript-syntax-highlighting",
7+
"isDesktopOnly": false,
8+
"minAppVersion": "1.5.12",
9+
"name": "GDScript Syntax Highlighting",
10+
"version": "1.0.0"
11+
}

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "obsidian-gdscript",
3+
"description": "Adds live GDScript syntax highlighting to code blocks in the Obsidian editor.",
4+
"main": "src/main.js",
5+
"version": "1.0.0",
6+
"author": "RobTheFiveNine",
7+
"type": "module",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/RobTheFiveNine/obsidian-gdscript"
11+
},
12+
"license": "MPL-2.0",
13+
"packageManager": "yarn@4.2.1",
14+
"dependencies": {
15+
"codemirror": "^6.0.1",
16+
"obsidian": "1.5.7-1"
17+
},
18+
"devDependencies": {
19+
"@rollup/plugin-commonjs": "^25.0.7",
20+
"@rollup/plugin-node-resolve": "^15.2.3",
21+
"rimraf": "^5.0.5",
22+
"rollup": "^4.17.2",
23+
"rollup-plugin-copy": "^3.5.0"
24+
},
25+
"scripts": {
26+
"build": "rollup -c",
27+
"clean": "rimraf dist"
28+
}
29+
}

rollup.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {nodeResolve} from '@rollup/plugin-node-resolve';
2+
import commonjs from '@rollup/plugin-commonjs';
3+
import copy from 'rollup-plugin-copy';
4+
5+
export default {
6+
input: 'src/main.js',
7+
output: {
8+
dir: 'dist',
9+
sourcemap: 'inline',
10+
format: 'cjs',
11+
exports: 'default'
12+
},
13+
external: ['obsidian'],
14+
plugins: [
15+
nodeResolve({browser: true}),
16+
commonjs(),
17+
copy({
18+
targets: [
19+
{
20+
src: 'manifest.json',
21+
dest: 'dist',
22+
},
23+
],
24+
}),
25+
]
26+
};

src/main.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Plugin } from 'obsidian';
2+
3+
4+
export default class GdscriptSyntaxPlugin extends Plugin {
5+
onload() {
6+
var self = this;
7+
8+
// The defineSimpleMode function is not immediately available during
9+
// onload, so continue to try and define the language until it is.
10+
const setupInterval = setInterval(() => {
11+
if (CodeMirror && CodeMirror.defineSimpleMode) {
12+
CodeMirror.defineSimpleMode("gdscript", {
13+
start: [
14+
{ regex: /\b0x[0-9a-f]+\b/i, token: "number" },
15+
{ regex: /\b-?\d+\b/, token: "number" },
16+
{ regex: /#.+/, token: 'comment' },
17+
{ regex: /\s*(@onready|@export)\b/, token: 'keyword' },
18+
{ regex: /\b(?:and|as|assert|break|breakpoint|const|continue|elif|else|enum|for|if|in|is|master|mastersync|match|not|null|or|pass|preload|puppet|puppetsync|remote|remotesync|return|self|setget|static|tool|var|while|yield)\b/, token: 'keyword' },
19+
{ regex: /[()\[\]{},]/, token: "meta" },
20+
21+
// The words following func, class_name and class should be highlighted as attributes,
22+
// so push onto the definition stack
23+
{ regex: /\b(func|class_name|class|extends|signal)\b/, token: "keyword", push: "definition" },
24+
25+
{ regex: /@?(?:("|')(?:(?!\1)[^\n\\]|\\[\s\S])*\1(?!"|')|"""(?:[^\\]|\\[\s\S])*?""")/, token: "string" },
26+
{ regex: /\$[\w\/]+\b/, token: 'variable' },
27+
{ regex: /\:[\s]*$/, token: 'operator' },
28+
{ regex: /\:[ ]*/, token: 'meta', push: 'var_type' },
29+
{ regex: /\->[ ]*/, token: 'operator', push: 'definition' },
30+
{ regex: /\+|\*|-|\/|:=|>|<|\^|&|\||%|~|=/, token: "operator" },
31+
{ regex: /\b(?:false|true)\b/, token: 'number' },
32+
{ regex: /\b[A-Z][A-Z_\d]*\b/, token: 'operator' },
33+
],
34+
var_type: [
35+
{ regex: /(\w+)/, token: 'attribute', pop: true },
36+
],
37+
definition: [
38+
{ regex: /(\w+)/, token: "attribute", pop: true }
39+
]
40+
})
41+
42+
self.app.workspace.iterateAllLeaves((leaf) => {
43+
leaf.rebuildView();
44+
});
45+
46+
clearInterval(setupInterval);
47+
}
48+
}, 100);
49+
}
50+
51+
onunload() {
52+
delete CodeMirror.modes['gdscript'];
53+
}
54+
}

0 commit comments

Comments
 (0)