1
1
import { MarkdownRenderChild } from "obsidian" ;
2
2
import { rant } from "../pkg/obsidian_rantlang_plugin.js" ;
3
+ import { RantLangSettings } from "./settings.js" ;
3
4
4
5
export abstract class BaseRantProcessor extends MarkdownRenderChild {
5
6
result : string = "" ;
6
7
target : HTMLElement ;
7
- enableStyling : boolean = false ;
8
8
9
- constructor ( public input : string , public container : HTMLElement ) {
9
+ constructor (
10
+ public input : string ,
11
+ public container : HTMLElement ,
12
+ public settings : RantLangSettings
13
+ ) {
10
14
super ( container ) ;
11
15
}
12
16
@@ -21,22 +25,30 @@ export abstract class BaseRantProcessor extends MarkdownRenderChild {
21
25
}
22
26
}
23
27
24
- rant ( seed : number , enableStyling : boolean ) {
25
- this . enableStyling = enableStyling ;
28
+ rant ( seed : number ) {
26
29
this . processInput ( seed ) ;
27
30
this . renderResult ( ) ;
28
31
}
29
32
}
30
33
34
+ export type Customization = "bold" | "italic" ;
35
+
31
36
export class CodeblockRantProcessor extends BaseRantProcessor {
32
- constructor ( input : string , container : HTMLElement ) {
33
- super ( input , container ) ;
34
- const cls = this . enableStyling ? [ "rant" , "rant-block" ] : "" ;
35
- this . target = container . createEl ( "p" , { cls } ) ;
37
+ customizations : Customization [ ] ;
38
+
39
+ constructor (
40
+ input : string ,
41
+ container : HTMLElement ,
42
+ settings : RantLangSettings ,
43
+ customizations : Customization [ ] = [ ]
44
+ ) {
45
+ super ( input , container , settings ) ;
46
+ this . customizations = customizations ;
47
+ this . target = container . createEl ( "p" ) ;
36
48
}
37
49
38
50
renderResult ( ) {
39
- const cls = this . enableStyling ? [ "rant" , "rant-block" ] : "" ;
51
+ const cls = this . getStyles ( ) ;
40
52
const newChild = createEl ( "p" , { cls } ) ;
41
53
this . container . replaceChild ( newChild , this . target ) ;
42
54
this . target = newChild ;
@@ -50,17 +62,30 @@ export class CodeblockRantProcessor extends BaseRantProcessor {
50
62
51
63
this . target . replaceChildren ( node ) ;
52
64
}
65
+
66
+ getStyles ( ) {
67
+ let cls = this . settings . enableStyling ? [ "rant" , "rant-block" ] : [ ] ;
68
+ this . customizations . forEach ( ( style ) => {
69
+ cls . push ( `rant-${ style } ` ) ;
70
+ } ) ;
71
+ return cls ;
72
+ }
53
73
}
54
74
55
75
/** Processes inline Rant blocks. */
56
76
export class InlineRantProcessor extends BaseRantProcessor {
57
- constructor ( input : string , container : HTMLElement , target : HTMLElement ) {
58
- super ( input , container ) ;
77
+ constructor (
78
+ input : string ,
79
+ container : HTMLElement ,
80
+ target : HTMLElement ,
81
+ settings : RantLangSettings
82
+ ) {
83
+ super ( input , container , settings ) ;
59
84
this . target = target ;
60
85
}
61
86
62
87
renderResult ( ) {
63
- const cls = this . enableStyling ? [ "rant" , "rant-inline" ] : "" ;
88
+ const cls = this . settings . enableStyling ? [ "rant" , "rant-inline" ] : "" ;
64
89
let temp = createEl ( "span" , { cls } ) ;
65
90
temp . appendText ( this . result ) ;
66
91
this . target . replaceWith ( temp ) ;
0 commit comments