Skip to content

Instantly share code, notes, and snippets.

View Fevol's full-sized avatar

Fevol

  • Belgium
View GitHub Profile
@Fevol
Fevol / LICENSE
Last active May 4, 2024 21:18
Embeddable CM Markdown Editor
Copyright 2024 Matthew Meyers, Fevol
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE US
@Fevol
Fevol / debugging.md
Last active September 15, 2024 17:03
An overview for debugging and performance analysis within Obsidian

Debugging your code

Unwinding the code trace

Sometimes you want to figure out what path your code takes when getting executed. This may be helpful for investigating inconsistent behaviour between function calls or finding where exactly in the bundled/minified code your function is located

// Logs the current stack trace of the code, also logs any provided parameters

/*
 * YOUR CODE HERE
 */
console.trace(var1, var2);
@Fevol
Fevol / database.ts
Last active September 6, 2023 21:50
Obsidian IndexedDB Database with Vault hooks example
import localforage from 'localforage';
import { type EventRef, Events, Notice, type Plugin, TFile } from 'obsidian';
type DatabaseItem<T> = {
data: T,
mtime: number
}
export class EventComponent extends Events {
@Fevol
Fevol / main.ts
Last active March 11, 2023 20:31
CodeMirror Document incremental parser statefield
import { Plugin } from 'obsidian';
import { treeParser } from './tree-parser';
import { OTHER_EXTENSION } from './other-extension';
// Obsidian plugin file
export default class YOURPLUGIN extends Plugin {
async onload() {
// ...
this.registerEditorExtension([treeParser, OTHER_EXTENSION]);
}
@Fevol
Fevol / index.html
Last active January 8, 2023 23:35
Electron spellchecker API issue
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'">
<link href="./styles.css" rel="stylesheet">
<title>Hello World!</title>
</head>
<body>
@Fevol
Fevol / main.ts
Created December 28, 2022 20:53
Obsidian - Foldable settings section
import {Plugin} from 'obsidian';
import {SampleSettingTab} from "./settings";
export default class MyPlugin extends Plugin {
settings: { [key: string]: any } = {};
// `data` variable contains data that will *not* be saved on app unload, this means that the sections that were closed/opened
// will be forgotten once the app restarts.
// If you want these folds to be saved across app restarts too, then store the open: {} in settings instead.
data: { open: { [key: string]: boolean } ; }
@Fevol
Fevol / buttonlist.ts
Last active December 23, 2022 23:28
Obsidian - Add Button List Component
// Copy this entire file into your source directory, you can adapt it if you want
// This code is written in a way that makes use of the same interface as all other Obsidian settings components
import {setIcon, Setting, ValueComponent} from "obsidian";
declare module "obsidian" {
interface Setting {
addButtonList(cb: (component: ButtonListComponent) => any): this;
}
}
@Fevol
Fevol / settings.ts
Created November 30, 2022 13:48
Tabulated settings page
export class SampleSettingTab extends PluginSettingTab {
plugin: MyPlugin;
settingsPage: HTMLElement;
YOUR_TABS = {
'first-tab-id': {
name: 'First tab',
icon: 'coffee',
},
'second-tab-id': {