Skip to content

Commit ec6c2b7

Browse files
committed
Fixed separator lines in dreams
1 parent 2eebbf3 commit ec6c2b7

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/main.ts

+23-13
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,27 @@ export default class Yesterday extends Plugin {
7676

7777
inDream = false;
7878
dreamContent = "";
79-
dreamParagraphsToRemove: HTMLParagraphElement[] = [];
79+
dreamParagraphsToRemove: Element[] = [];
8080

8181
inTodo = false;
8282
todoContent = "";
83-
todoParagraphsToRemove: HTMLParagraphElement[] = [];
83+
todoParagraphsToRemove: HTMLElement[] = [];
8484

8585
registerMarkdownPostProcessors() {
8686
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+
}
91100

92101
const isImage = text[0] === "/" && mediaExtensions.some(extension => text.endsWith(extension));
93102
const isComment = text.startsWith("///");
@@ -98,15 +107,15 @@ export default class Yesterday extends Plugin {
98107
const isTodoEnd = text.endsWith("++");
99108

100109
if (isImage) {
101-
context.addChild(new YesterdayMedia(paragraph, text));
110+
context.addChild(new YesterdayMedia((element as HTMLElement), text));
102111
}
103112

104113
if (isComment) {
105-
paragraph.parentElement.addClass("yesterday-comment");
114+
element.parentElement.addClass("yesterday-comment");
106115
}
107116

108117
if (isDialog) {
109-
context.addChild(new YesterdayDialog(paragraph, text));
118+
context.addChild(new YesterdayDialog((element as HTMLElement), text));
110119
}
111120

112121
if (isDreamStart && !this.inDream) {
@@ -115,11 +124,12 @@ export default class Yesterday extends Plugin {
115124
}
116125

117126
if (this.inDream) {
127+
console.log(text);
118128
let textWithoutMarkers = text.replace(/^§§§|§§§$/g, '').trim();
119129
this.dreamContent += `> ${textWithoutMarkers}\n`;
120130
if (!isDreamEnd) {
121131
this.dreamContent += `> \n`;
122-
this.dreamParagraphsToRemove.push(paragraph);
132+
this.dreamParagraphsToRemove.push(element);
123133
}
124134
}
125135

@@ -128,13 +138,13 @@ export default class Yesterday extends Plugin {
128138
this.dreamParagraphsToRemove.forEach(element => {
129139
element.remove();
130140
});
131-
const container = paragraph.createDiv();
141+
const container = element.createDiv();
132142
MarkdownRenderer.renderMarkdown(this.dreamContent, container, null, this);
133-
paragraph.replaceWith(container);
143+
element.replaceWith(container);
134144
}
135145

136146
if (isTodoStart) {
137-
paragraph.parentElement.addClass("yesterday-todo");
147+
element.parentElement.addClass("yesterday-todo");
138148
}
139149
});
140150
});

0 commit comments

Comments
 (0)