@@ -76,18 +76,27 @@ export default class Yesterday extends Plugin {
76
76
77
77
inDream = false ;
78
78
dreamContent = "" ;
79
- dreamParagraphsToRemove : HTMLParagraphElement [ ] = [ ] ;
79
+ dreamParagraphsToRemove : Element [ ] = [ ] ;
80
80
81
81
inTodo = false ;
82
82
todoContent = "" ;
83
- todoParagraphsToRemove : HTMLParagraphElement [ ] = [ ] ;
83
+ todoParagraphsToRemove : HTMLElement [ ] = [ ] ;
84
84
85
85
registerMarkdownPostProcessors ( ) {
86
86
this . registerMarkdownPostProcessor ( ( element , context ) => {
87
- const paragraphs = Array . from ( element . querySelectorAll ( "p" ) ) ;
88
-
89
- paragraphs . forEach ( ( paragraph ) => {
90
- const text = paragraph . innerText . trim ( ) ;
87
+ const elements = Array . from ( element . querySelectorAll ( "p, hr" ) ) ;
88
+
89
+ // const paragraphs = elements.map(paragraph => {
90
+
91
+ // })
92
+
93
+ elements . forEach ( ( element ) => {
94
+ let text : string ;
95
+ if ( element . tagName === "HR" ) {
96
+ text = "---" ;
97
+ } else if ( element . tagName === "P" ) {
98
+ text = ( element as HTMLElement ) . innerText . trim ( ) ;
99
+ }
91
100
92
101
const isImage = text [ 0 ] === "/" && mediaExtensions . some ( extension => text . endsWith ( extension ) ) ;
93
102
const isComment = text . startsWith ( "///" ) ;
@@ -98,15 +107,15 @@ export default class Yesterday extends Plugin {
98
107
const isTodoEnd = text . endsWith ( "++" ) ;
99
108
100
109
if ( isImage ) {
101
- context . addChild ( new YesterdayMedia ( paragraph , text ) ) ;
110
+ context . addChild ( new YesterdayMedia ( ( element as HTMLElement ) , text ) ) ;
102
111
}
103
112
104
113
if ( isComment ) {
105
- paragraph . parentElement . addClass ( "yesterday-comment" ) ;
114
+ element . parentElement . addClass ( "yesterday-comment" ) ;
106
115
}
107
116
108
117
if ( isDialog ) {
109
- context . addChild ( new YesterdayDialog ( paragraph , text ) ) ;
118
+ context . addChild ( new YesterdayDialog ( ( element as HTMLElement ) , text ) ) ;
110
119
}
111
120
112
121
if ( isDreamStart && ! this . inDream ) {
@@ -115,11 +124,12 @@ export default class Yesterday extends Plugin {
115
124
}
116
125
117
126
if ( this . inDream ) {
127
+ console . log ( text ) ;
118
128
let textWithoutMarkers = text . replace ( / ^ § § § | § § § $ / g, '' ) . trim ( ) ;
119
129
this . dreamContent += `> ${ textWithoutMarkers } \n` ;
120
130
if ( ! isDreamEnd ) {
121
131
this . dreamContent += `> \n` ;
122
- this . dreamParagraphsToRemove . push ( paragraph ) ;
132
+ this . dreamParagraphsToRemove . push ( element ) ;
123
133
}
124
134
}
125
135
@@ -128,13 +138,13 @@ export default class Yesterday extends Plugin {
128
138
this . dreamParagraphsToRemove . forEach ( element => {
129
139
element . remove ( ) ;
130
140
} ) ;
131
- const container = paragraph . createDiv ( ) ;
141
+ const container = element . createDiv ( ) ;
132
142
MarkdownRenderer . renderMarkdown ( this . dreamContent , container , null , this ) ;
133
- paragraph . replaceWith ( container ) ;
143
+ element . replaceWith ( container ) ;
134
144
}
135
145
136
146
if ( isTodoStart ) {
137
- paragraph . parentElement . addClass ( "yesterday-todo" ) ;
147
+ element . parentElement . addClass ( "yesterday-todo" ) ;
138
148
}
139
149
} ) ;
140
150
} ) ;
0 commit comments