1
- import { Editor , EditorPosition , Notice , Setting , MarkdownPostProcessorContext } from "obsidian" ;
1
+ import { Editor , EditorPosition , Notice , Setting , MarkdownPostProcessorContext , MarkdownRenderer } from "obsidian" ;
2
2
import DecryptModal from "./DecryptModal" ;
3
3
import { IMeldEncryptPluginFeature } from "../IMeldEncryptPluginFeature" ;
4
4
import MeldEncrypt from "../../main" ;
@@ -12,8 +12,8 @@ import { Decryptable } from "./Decryptable";
12
12
13
13
14
14
15
- const _PREFIX_B = '%%🔐 β ' ;
16
- const _PREFIX_B_VISIBLE = '🔐 β ' ;
15
+ const _PREFIX_B = '%%🔐β ' ;
16
+ const _PREFIX_B_VISIBLE = '🔐β ' ;
17
17
18
18
const _PREFIX_A = '%%🔐α ' ;
19
19
const _PREFIX_A_VISIBLE = '🔐α ' ;
@@ -52,8 +52,9 @@ export default class FeatureInplaceEncrypt implements IMeldEncryptPluginFeature{
52
52
this . pluginSettings = settings ;
53
53
this . featureSettings = settings . featureInplaceEncrypt ;
54
54
55
-
56
- this . plugin . registerMarkdownPostProcessor ( ( el , ctx ) => this . processEncryptedCodeBlockProcessor ( el , ctx ) ) ;
55
+ this . plugin . registerMarkdownPostProcessor (
56
+ ( el , ctx ) => this . processEncryptedCodeBlockProcessor ( el , ctx )
57
+ ) ;
57
58
58
59
plugin . addCommand ( {
59
60
id : 'meld-encrypt' ,
@@ -75,7 +76,7 @@ export default class FeatureInplaceEncrypt implements IMeldEncryptPluginFeature{
75
76
76
77
}
77
78
78
- private processEncryptedCodeBlockProcessor ( el : HTMLElement , ctx : MarkdownPostProcessorContext ) {
79
+ private async processEncryptedCodeBlockProcessor ( el : HTMLElement , ctx : MarkdownPostProcessorContext ) {
79
80
80
81
const si = ctx . getSectionInfo ( el ) ;
81
82
if ( si == null ) {
@@ -111,25 +112,26 @@ export default class FeatureInplaceEncrypt implements IMeldEncryptPluginFeature{
111
112
return ;
112
113
}
113
114
114
- const textBeforeIndicator = InplaceTextHelper . extractTextBeforeMarker ( text , markerStart ) ;
115
- const textAfterIndicator = InplaceTextHelper . extractTextAfterMarker ( text , markerEnd ) ;
115
+ const textBeforeIndicator = InplaceTextHelper . extractTextBeforeMarker ( text , markerStart ) ;
116
+ const textAfterIndicator = InplaceTextHelper . extractTextAfterMarker ( text , markerEnd ) ;
116
117
118
+ const newMd = textBeforeIndicator
119
+ + '<span class="meld-encrypt-inline-reading-marker">🔐</span>'
120
+ + textAfterIndicator
121
+ ;
117
122
118
- // create elements
119
- const elPreIndicator = createSpan ( { text : textBeforeIndicator } ) ;
120
- const elPostIndicator = createSpan ( { text : textAfterIndicator } ) ;
121
-
122
- const elIndicator = createSpan ( { text : '🔐' , cls : ' meld-encrypt-inline-reading-marker' } ) ;
123
- elIndicator . onClickEvent ( async ( ) =>
123
+ el . empty ( ) ;
124
+ await MarkdownRenderer . renderMarkdown ( newMd , el , ctx . sourcePath , this . plugin ) ;
125
+
126
+ //console.debug( {el} );
127
+ const elIndicator = el . querySelector ( '. meld-encrypt-inline-reading-marker') as HTMLSpanElement ;
128
+ elIndicator ? .onClickEvent ( async ( ) =>
124
129
await this . handleReadingIndicatorClick (
125
130
ctx . sourcePath ,
126
131
selectionAnalysis . decryptable
127
132
)
128
133
) ;
129
134
130
- el . empty ( ) ;
131
- el . append ( elPreIndicator , elIndicator , elPostIndicator ) ;
132
-
133
135
}
134
136
135
137
private async handleReadingIndicatorClick ( path : string , decryptable ?:Decryptable ) {
0 commit comments