generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.ts
26 lines (18 loc) · 746 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { App, Plugin, MarkdownPostProcessor, MarkdownPostProcessorContext } from 'obsidian';
export default class LinkHeadersDirectly extends Plugin {
async onload() {
let postProc: MarkdownPostProcessor;
postProc = (el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
let linkElements = el.querySelectorAll('a.internal-link');
let barIndex, alias;
for(let i = 0; i < linkElements.length; i++) {
let linkAsHTML = (linkElements[i] as HTMLElement).innerText;
barIndex = linkAsHTML.indexOf(">");
if(barIndex < 0) continue;
alias = linkAsHTML.substr(barIndex+2);
(linkElements[i] as HTMLElement).innerText = alias;
}
}
this.registerMarkdownPostProcessor(postProc);
}
}