Commit 54bc7cc 1 parent 401e540 commit 54bc7cc Copy full SHA for 54bc7cc
File tree 1 file changed +17
-0
lines changed
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,11 @@ export default class HotkeysPlus extends Plugin {
62
62
name : "Duplicate the current line or selected lines" ,
63
63
callback : ( ) => this . duplicateLines ( ) ,
64
64
} ) ;
65
+ this . addCommand ( {
66
+ id : "clean-selected" ,
67
+ name : "Removes new line characters and html elements" ,
68
+ callback : ( ) => this . cleanSelected ( ) ,
69
+ } ) ;
65
70
66
71
this . addCommand ( {
67
72
id : 'insert-line-above' ,
@@ -109,6 +114,18 @@ export default class HotkeysPlus extends Plugin {
109
114
var newString = selectedText . content + "\n" ;
110
115
editor . replaceRange ( newString , selectedText . start , selectedText . start ) ;
111
116
}
117
+ cleanSelected ( ) {
118
+ var activeLeaf : any = this . app . workspace . activeLeaf ;
119
+ var editor = activeLeaf . view . sourceMode . cmEditor ;
120
+ var selectedText = this . getSelectedText ( editor ) ;
121
+ // removing new line chars
122
+ var newString = selectedText . content . trim ( ) . replace ( / ( \r \n | \n | \r ) / gm, ' ' ) ;
123
+ //removing html
124
+ newString = newString . replace ( / < \/ ? \w + \/ ? > / gm, ' ' ) ;
125
+ // removing access white space
126
+ newString = newString . replace ( / + / gm, ' ' ) ;
127
+ editor . replaceRange ( newString , selectedText . start , selectedText . end ) ;
128
+ }
112
129
113
130
onunload ( ) {
114
131
console . log ( "Unloading Hotkeys++ plugin" ) ;
You can’t perform that action at this time.
0 commit comments