@@ -7,14 +7,15 @@ import tree from "./tree.js";
77import froca from "./froca.js" ;
88import link from "./link.js" ;
99import { isHtmlEmpty } from "./utils.js" ;
10- import type { RenderOptions } from "./content_renderer.js" ;
10+ import { default as content_renderer , type RenderOptions } from "./content_renderer.js" ;
1111
1212export default async function renderText ( note : FNote | FAttachment , $renderedContent : JQuery < HTMLElement > , options : RenderOptions = { } ) {
1313 // entity must be FNote
1414 const blob = await note . getBlob ( ) ;
1515
1616 if ( blob && ! isHtmlEmpty ( blob . content ) ) {
1717 $renderedContent . append ( $ ( '<div class="ck-content">' ) . html ( blob . content ) ) ;
18+ await renderIncludedNotes ( $renderedContent [ 0 ] ) ;
1819
1920 if ( $renderedContent . find ( "span.math-tex" ) . length > 0 ) {
2021 renderMathInElement ( $renderedContent [ 0 ] , { trust : true } ) ;
@@ -36,6 +37,33 @@ export default async function renderText(note: FNote | FAttachment, $renderedCon
3637 }
3738}
3839
40+ async function renderIncludedNotes ( contentEl : HTMLElement ) {
41+ // TODO: Consider duplicating with server's share/content_renderer.ts.
42+ const includeNoteEls = contentEl . querySelectorAll ( "section.include-note" ) ;
43+
44+ // Gather the list of items to load.
45+ const noteIds : string [ ] = [ ] ;
46+ for ( const includeNoteEl of includeNoteEls ) {
47+ const noteId = includeNoteEl . getAttribute ( "data-note-id" ) ;
48+ if ( noteId ) {
49+ noteIds . push ( noteId ) ;
50+ }
51+ }
52+
53+ // Load the required notes.
54+ await froca . getNotes ( noteIds ) ;
55+
56+ // Render and integrate the notes.
57+ for ( const includeNoteEl of includeNoteEls ) {
58+ const noteId = includeNoteEl . getAttribute ( "data-note-id" ) ;
59+ if ( ! noteId ) return ;
60+
61+ const note = froca . getNoteFromCache ( noteId ) ;
62+ const renderedContent = ( await content_renderer . getRenderedContent ( note ) ) . $renderedContent ;
63+ includeNoteEl . replaceChildren ( ...renderedContent ) ;
64+ }
65+ }
66+
3967/** Rewrite the code block from <pre><code> to <div> in order not to apply a codeblock style to it. */
4068export async function rewriteMermaidDiagramsInContainer ( container : HTMLDivElement ) {
4169 const mermaidBlocks = container . querySelectorAll ( 'pre:has(code[class="language-mermaid"])' ) ;
0 commit comments