generated from RyotaUshio/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hover preview functionality & callout support
- Loading branch information
1 parent
ebc8173
commit ef449e8
Showing
5 changed files
with
244 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,58 @@ | ||
import { PluginSettingTab, Setting } from 'obsidian'; | ||
import { Modifier, PluginSettingTab, Setting } from 'obsidian'; | ||
import MyPlugin from './main'; | ||
|
||
|
||
// https://stackoverflow.com/a/50851710/13613783 | ||
export type BooleanKeys<T> = { [k in keyof T]: T[k] extends boolean ? k : never }[keyof T]; | ||
export type NumberKeys<T> = { [k in keyof T]: T[k] extends number ? k : never }[keyof T]; | ||
|
||
|
||
export interface MyPluginSettings { | ||
math: boolean; | ||
// code: boolean; | ||
// callout: boolean; | ||
callout: boolean; | ||
dev: boolean; | ||
modifierToPreview: Modifier; | ||
compactPreview: boolean; | ||
} | ||
|
||
export const DEFAULT_SETTINGS: MyPluginSettings = { | ||
math: true, | ||
// code: true, | ||
// callout: true, | ||
callout: true, | ||
dev: false, | ||
modifierToPreview: 'Alt', | ||
compactPreview: false, | ||
} | ||
|
||
export class SampleSettingTab extends PluginSettingTab { | ||
constructor(public plugin: MyPlugin) { | ||
super(plugin.app, plugin); | ||
} | ||
|
||
addSetting(name: string, settingName: keyof MyPluginSettings) { | ||
new Setting(this.containerEl) | ||
.setName(name) | ||
.addToggle((toggle) => { | ||
toggle.setValue(this.plugin.settings.math) | ||
toggle.onChange(async (value) => { | ||
this.plugin.settings[settingName] = value; | ||
await this.plugin.saveSettings(); | ||
addToggleSetting(name: string, settingName: BooleanKeys<MyPluginSettings>) { | ||
return new Setting(this.containerEl) | ||
.setName(name) | ||
.addToggle((toggle) => { | ||
toggle.setValue(this.plugin.settings[settingName]) | ||
toggle.onChange(async (value) => { | ||
this.plugin.settings[settingName] = value; | ||
await this.plugin.saveSettings(); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
addEnableSetting(name: string, settingName: BooleanKeys<MyPluginSettings>) { | ||
return this.addToggleSetting(name, settingName).setHeading(); | ||
} | ||
|
||
display(): void { | ||
const { containerEl } = this; | ||
containerEl.empty(); | ||
|
||
this.addSetting('Math', 'math'); | ||
this.addEnableSetting('Math blocks', 'math'); | ||
this.addEnableSetting('Callouts', 'callout'); | ||
this.addToggleSetting('Compact hover preview', 'compactPreview'); | ||
this.addToggleSetting('Dev mode', 'dev'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Loc, Pos, SearchMatches, TFile } from "obsidian"; | ||
|
||
export interface LinkInfo { | ||
file: TFile; | ||
matches: SearchMatches | null; | ||
path: string; | ||
score: number; | ||
subpath?: string; | ||
} | ||
|
||
export interface FileLinkInfo extends LinkInfo { | ||
type: "file"; | ||
} | ||
|
||
export interface HeadingLinkInfo extends LinkInfo { | ||
type: "heading"; | ||
heading: string; | ||
level: number; | ||
subpath: string; | ||
} | ||
|
||
interface BlockLinkInfo extends LinkInfo { | ||
type: "block"; | ||
idMatch: SearchMatches | null; | ||
subpath: string; | ||
node: CalloutNode | MathNode; | ||
display: string; | ||
content: string; | ||
} | ||
|
||
interface Node { | ||
children: Node[]; | ||
position: { | ||
start: Loc; | ||
end: Loc; | ||
indent: number[]; | ||
} | ||
} | ||
|
||
interface CalloutNode extends Node { | ||
type: "callout", | ||
callout: { | ||
data: string; | ||
type: string; | ||
fold: string; | ||
}, | ||
children: [CalloutTitleNode, CalloutContentNode] | ||
} | ||
|
||
interface CalloutTitleNode extends Node {} | ||
|
||
interface CalloutContentNode extends Node {} | ||
|
||
interface CalloutLinkInfo extends BlockLinkInfo { | ||
node: CalloutNode; | ||
} | ||
|
||
|
||
interface MathNode extends Node { | ||
type: "math"; | ||
value: string; | ||
} | ||
|
||
interface MathLinkInfo extends BlockLinkInfo { | ||
node: MathNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Scope } from "obsidian"; | ||
|
||
declare module "obsidian" { | ||
interface EditorSuggest<T> { | ||
scope: Scope; | ||
suggestions: { | ||
selectedItem: number; | ||
values: T[]; | ||
containerEl: HTMLElement; | ||
moveUp(event: KeyboardEvent): void; | ||
moveDown(event: KeyboardEvent): void; | ||
}; | ||
suggestEl: HTMLElement; | ||
isOpen: boolean; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
/* | ||
.compact-font.hover-popover .markdown-rendered { | ||
font-size: 100%; | ||
} | ||
|
||
This CSS file will be included with your plugin, and | ||
available in the app when your plugin is enabled. | ||
.suggestion-container { | ||
z-index: calc(var(--layer-popover) - 1); | ||
} | ||
|
||
If your plugin does not need CSS, delete this file. | ||
*/ | ||
.suggestion-content { | ||
width: 100%; | ||
} |