@@ -2,64 +2,44 @@ import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Set
2
2
3
3
// Remember to rename these classes and interfaces!
4
4
5
- interface MyPluginSettings {
5
+ interface HeaderDisplayTextSettings {
6
6
mySetting : string ;
7
7
}
8
8
9
- const DEFAULT_SETTINGS : MyPluginSettings = {
9
+ const DEFAULT_SETTINGS : HeaderDisplayTextSettings = {
10
10
mySetting : 'default'
11
11
}
12
12
13
- export default class ProfileBuilder extends Plugin {
14
- settings : MyPluginSettings ;
13
+ export default class HeaderDisplayText extends Plugin {
14
+ settings : HeaderDisplayTextSettings ;
15
15
16
16
async onload ( ) {
17
17
await this . loadSettings ( ) ;
18
18
19
- // This creates an icon in the left ribbon.
20
- const ribbonIconEl = this . addRibbonIcon ( 'square-user-round' , 'Get Profile' , async ( evt : MouseEvent ) => {
21
- // Called when the user clicks the icon.
22
- const activeView = this . app . workspace . getActiveViewOfType ( MarkdownView ) ;
23
- if ( activeView ) { // if a file is opened on screen
24
- const editor = activeView . editor ;
25
- const selectedText = editor . getSelection ( ) ; // get the text selected in the editor
26
- if ( selectedText . length === 0 ) {
27
- new Notice ( 'No text selected' ) ;
28
- return ;
29
- } else {
30
- new Notice ( `Getting profile information for ${ selectedText } ` ) ;
31
- const profileInfo = await this . getProfileInfo ( selectedText ) ;
32
- editor . replaceRange ( profileInfo , editor . getCursor ( ) ) ;
33
- new Notice ( 'Profile information inserted' ) ;
34
- }
35
- } else {
36
- new Notice ( 'No file opened' ) ;
37
- }
38
- } ) ;
39
- // Perform additional things with the ribbon
40
- ribbonIconEl . addClass ( 'my-plugin-ribbon-class' ) ;
41
-
42
- this . addCommand ( {
43
- id : 'get-profile-info' ,
44
- name : 'Get and insert profile information' ,
45
- editorCallback : ( editor : Editor ) => {
46
- const selection = editor . getSelection ( ) ;
47
- editor . replaceRange ( 'Some text' , editor . getCursor ( ) ) ;
48
- // Do something with the selection
49
- } ,
50
- } ) ;
51
-
52
19
// This adds a settings tab so the user can configure various aspects of the plugin
53
- this . addSettingTab ( new SampleSettingTab ( this . app , this ) ) ;
20
+ this . addSettingTab ( new HeaderDisplayTextSettingTab ( this . app , this ) ) ;
54
21
55
22
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
56
23
// Using this function will automatically remove the event listener when this plugin is disabled.
57
- this . registerDomEvent ( document , 'click' , ( evt : MouseEvent ) => {
58
- console . log ( 'click' , evt ) ;
59
- } ) ;
60
-
61
- // When registering intervals, this function will automatically clear the interval when the plugin is disabled.
62
- this . registerInterval ( window . setInterval ( ( ) => console . log ( 'setInterval' ) , 5 * 60 * 1000 ) ) ;
24
+ this . registerEvent (
25
+ this . app . workspace . on ( 'editor-change' , ( editor : Editor ) => {
26
+ // get what is being typed
27
+ const cursor = editor . getCursor ( ) ;
28
+ const currentLine = editor . getLine ( cursor . line ) ;
29
+ // Wikilink format
30
+ // match links to other note headings WITHOUT an already defined display text
31
+ const headerLinkPattern = / \[ \[ ( [ ^ \] ] + ) # ( [ ^ | ] + ) \] \] / ;
32
+ const match = currentLine . slice ( 0 , cursor . ch ) . match ( headerLinkPattern ) ;
33
+ if ( match ) {
34
+ const noteName = match [ 1 ] ;
35
+ const heading = match [ 2 ] ;
36
+ console . log ( noteName , heading ) ;
37
+ const startIndex = ( match . index ?? 0 ) + match [ 0 ] . length - 2 ;
38
+ editor . replaceRange ( `|${ heading } ` , { line : cursor . line , ch : startIndex } , undefined , 'headerAliases' )
39
+ new Notice ( 'Link changed!' )
40
+ }
41
+ } )
42
+ ) ;
63
43
}
64
44
65
45
onunload ( ) {
@@ -74,58 +54,12 @@ export default class ProfileBuilder extends Plugin {
74
54
await this . saveData ( this . settings ) ;
75
55
}
76
56
77
- async getProfileInfo ( userSelection : string ) {
78
- // Try changing this to a google search for the linkedin, downloading the page, using an AI to parse the information?
79
- const body = {
80
- "model" :"llama-3.1-sonar-huge-128k-online" ,
81
- "messages" :
82
- [
83
- {
84
- "role" :"system" ,
85
- "content" :"Find the academic and work experience of the given person. Output the information in this structured, Markdown format: ##Background###Work###Education. Each section should just be a list of experiences noting the company and position for work or degree and field of study for education. At the end of each item should be the start and end date. If the end date is not available, just put the start date. If the start date is not available, just put the end date. If both are not available, just put 'N/A'. After these two sections, you may include anything else you find about the person."
86
- } ,
87
- {
88
- "role" :"user" ,
89
- "content" :`Tell me about ${ userSelection } `
90
- }
91
- ] ,
92
- "search_domain_filer" : [ "linkedin.com" ]
93
- }
94
- const options = {
95
- method : 'POST' ,
96
- headers : { Authorization : `Bearer ${ process . env . PPLX_API_KEY } ` , 'Content-Type' : 'application/json' } ,
97
- body : JSON . stringify ( body )
98
- } ;
99
- try {
100
- const response = await fetch ( 'https://api.perplexity.ai/chat/completions' , options ) ;
101
- const data = await response . json ( ) ;
102
- return data . choices [ 0 ] . message . content ;
103
- } catch ( err ) {
104
- return err . message ;
105
- }
106
- }
107
- }
108
-
109
- class SampleModal extends Modal {
110
- constructor ( app : App ) {
111
- super ( app ) ;
112
- }
113
-
114
- onOpen ( ) {
115
- const { contentEl} = this ;
116
- contentEl . setText ( 'Woah!' ) ;
117
- }
118
-
119
- onClose ( ) {
120
- const { contentEl} = this ;
121
- contentEl . empty ( ) ;
122
- }
123
57
}
124
58
125
- class SampleSettingTab extends PluginSettingTab {
126
- plugin : ProfileBuilder ;
59
+ class HeaderDisplayTextSettingTab extends PluginSettingTab {
60
+ plugin : HeaderDisplayText ;
127
61
128
- constructor ( app : App , plugin : ProfileBuilder ) {
62
+ constructor ( app : App , plugin : HeaderDisplayText ) {
129
63
super ( app , plugin ) ;
130
64
this . plugin = plugin ;
131
65
}
@@ -136,8 +70,8 @@ class SampleSettingTab extends PluginSettingTab {
136
70
containerEl . empty ( ) ;
137
71
138
72
new Setting ( containerEl )
139
- . setName ( 'Setting #1 ' )
140
- . setDesc ( 'It\'s a secret ' )
73
+ . setName ( 'Display Text Format ' )
74
+ . setDesc ( 'Change the format of the display text. ' )
141
75
. addText ( text => text
142
76
. setPlaceholder ( 'Enter your secret' )
143
77
. setValue ( this . plugin . settings . mySetting )
0 commit comments