@@ -2,16 +2,6 @@ import { App, MarkdownView, Plugin, MarkdownPostProcessorContext, PluginSettingT
22
33import * as base64js from 'base64-js' ;
44
5- // Remember to rename these classes and interfaces!
6-
7- interface MyPluginSettings {
8- mySetting : string ;
9- }
10-
11- const DEFAULT_SETTINGS : MyPluginSettings = {
12- mySetting : 'default'
13- }
14-
155
166// Abstract class for all coders
177interface Coder {
@@ -39,15 +29,13 @@ class Base64Encoder implements Coder {
3929}
4030
4131
42- export default class MyPlugin extends Plugin {
43- settings : MyPluginSettings ;
32+ export default class CoderPlugin extends Plugin {
4433
4534 // List of coders
4635 coders : Coder [ ] = [ new Base64Encoder ( ) ] ;
4736
4837 async onload ( ) {
4938 this . registerMarkdownCodeBlockProcessor ( 'transform-text-base64' , this . processTextToBase64 ) ;
50- //this.registerMarkdownCodeBlockProcessor('transform-base64-text', this.processBase64ToText);
5139 }
5240
5341 // function to get a coder by from and to types
@@ -64,16 +52,9 @@ export default class MyPlugin extends Plugin {
6452
6553 }
6654
67- async loadSettings ( ) {
68- this . settings = Object . assign ( { } , DEFAULT_SETTINGS , await this . loadData ( ) ) ;
69- }
70-
71- async saveSettings ( ) {
72- await this . saveData ( this . settings ) ;
73- }
7455
7556 processTextToBase64 = async ( content : string , el : HTMLElement , ctx : MarkdownPostProcessorContext ) => {
76- let destination = document . createElement ( 'p' ) ;
57+ var destination ;
7758
7859 if ( content . endsWith ( "\n" ) ) {
7960 // Obsidian gives an unpretty linebreak at the end. Don't encode it in our content!
@@ -83,16 +64,19 @@ export default class MyPlugin extends Plugin {
8364
8465 // convert the content variable to a byte array
8566 if ( coder != null ) {
86- destination . innerHTML = coder . transform ( content ) ;
67+ destination = document . createTextNode ( coder . transform ( content ) ) ;
8768 } else {
88- destination . innerHTML = "No coder found!" ;
69+ destination = document . createTextNode ( "No coder found!" ) ;
8970 }
9071
9172 el . appendChild ( destination ) ;
9273 return ;
9374 }
75+
76+
77+ /**
9478 processBase64ToText = async (content: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
95- let destination = document . createElement ( 'span' ) ;
79+ var destination;
9680
9781 if(content.endsWith("\n")) {
9882 // Obsidian gives an unpretty linebreak at the end. Don't encode it in our content!
@@ -102,14 +86,14 @@ export default class MyPlugin extends Plugin {
10286
10387 // convert the content variable to a byte array
10488 if(coder != null) {
105- destination . innerHTML = coder . transform ( content ) ;
89+ destination = document.createTextNode ( coder.transform(content) );
10690 } else {
107- destination . innerHTML = "No coder found!" ;
91+ destination = document.createTextNode ( "No coder found!" ) ;
10892 }
10993
11094 el.appendChild(destination);
11195 return;
112- }
96+ }**/
11397
11498}
11599
0 commit comments