@@ -12,6 +12,7 @@ export type TaskLineRenderDetails = {
12
12
parentUlElement : HTMLElement ;
13
13
/** The nth item in this list (including non-tasks). */
14
14
listIndex : number ;
15
+ obsidianComponent : Component | null ;
15
16
layoutOptions ?: LayoutOptions ;
16
17
isFilenameUnique ?: boolean ;
17
18
taskLayout ?: TaskLayout ;
@@ -35,10 +36,21 @@ const DAY_VALUE_OVER_RANGE_POSTFIX = 'far';
35
36
/**
36
37
* The function used to render a Markdown task line into an existing HTML element.
37
38
*/
38
- export type TextRenderer = ( text : string , element : HTMLSpanElement , path : string ) => Promise < void > ;
39
-
40
- async function obsidianMarkdownRenderer ( text : string , element : HTMLSpanElement , path : string ) {
41
- await MarkdownRenderer . renderMarkdown ( text , element , path , null as unknown as Component ) ;
39
+ export type TextRenderer = (
40
+ text : string ,
41
+ element : HTMLSpanElement ,
42
+ path : string ,
43
+ obsidianComponent : Component | null , // null is allowed here only for tests
44
+ ) => Promise < void > ;
45
+
46
+ async function obsidianMarkdownRenderer (
47
+ text : string ,
48
+ element : HTMLSpanElement ,
49
+ path : string ,
50
+ obsidianComponent : Component | null ,
51
+ ) {
52
+ if ( ! obsidianComponent ) throw new Error ( 'Must call the Obsidian renderer with an Obsidian Component object' ) ;
53
+ await MarkdownRenderer . renderMarkdown ( text , element , path , obsidianComponent ) ;
42
54
}
43
55
44
56
/**
@@ -138,7 +150,14 @@ async function taskToHtml(
138
150
// to do things like surrouding only the text (rather than its whole placeholder) with a highlight
139
151
const internalSpan = document . createElement ( 'span' ) ;
140
152
span . appendChild ( internalSpan ) ;
141
- await renderComponentText ( internalSpan , componentString , component , task , textRenderer ) ;
153
+ await renderComponentText (
154
+ internalSpan ,
155
+ componentString ,
156
+ component ,
157
+ task ,
158
+ textRenderer ,
159
+ renderDetails . obsidianComponent ,
160
+ ) ;
142
161
const [ genericClasses , dataAttributes ] = getComponentClassesAndData ( component , task ) ;
143
162
addInternalClasses ( component , internalSpan ) ;
144
163
// Add the generic classes that apply to what this component is (priority, due date etc)
@@ -178,14 +197,15 @@ async function renderComponentText(
178
197
component : TaskLayoutComponent ,
179
198
task : Task ,
180
199
textRenderer : TextRenderer ,
200
+ obsidianComponent : Component | null ,
181
201
) {
182
202
if ( component === 'description' ) {
183
203
const { debugSettings } = getSettings ( ) ;
184
204
if ( debugSettings . showTaskHiddenData ) {
185
205
// Add some debug output to enable hidden information in the task to be inspected.
186
206
componentString += `<br>🐛 <b>${ task . lineNumber } </b> . ${ task . sectionStart } . ${ task . sectionIndex } . '<code>${ task . originalMarkdown } </code>'<br>'<code>${ task . path } </code>' > '<code>${ task . precedingHeader } </code>'<br>` ;
187
207
}
188
- await textRenderer ( componentString , span , task . path ) ;
208
+ await textRenderer ( componentString , span , task . path , obsidianComponent ) ;
189
209
190
210
// If the task is a block quote, the block quote wraps the p-tag that contains the content.
191
211
// In that case, we need to unwrap the p-tag *inside* the surrounding block quote.
0 commit comments