@@ -43,16 +43,30 @@ function detectCanvasElement(el: HTMLElement, ctx: MarkdownPostProcessorContext,
4343 }
4444}
4545
46+ // Try to detect if the postprocessor was asked to render an export, which seems to be the only case on which
47+ // the post processor is called with a top-level Markdown Preview View div.
48+ // In this case, we must add the relevant document direction class to that element, because no one else will.
49+ function detectExport ( el : HTMLElement , ctx : MarkdownPostProcessorContext , setPreviewDirection : SetPreviewDirection ) {
50+ if ( el ?. classList && el . classList ?. contains ( 'markdown-preview-view' ) ) {
51+ setPreviewDirection ( ctx . sourcePath , el as HTMLDivElement ) ;
52+ }
53+ }
54+
4655type SetPreviewDirection = ( path : string , markdownPreviewElement : HTMLDivElement ) => void ;
4756
4857/*
4958 * This Markdown post-processor handles the Reading view and other rendered components of notes.
5059 * It detects the direction for each node individually and adds corresponding CSS classes that are
5160 * later referenced in styles.css.
5261 */
53- export const autoDirectionPostProcessor = ( el : HTMLElement , ctx : MarkdownPostProcessorContext , setPreviewDirection : SetPreviewDirection ) => {
62+ export const autoDirectionPostProcessor = (
63+ el : HTMLElement ,
64+ ctx : MarkdownPostProcessorContext ,
65+ setPreviewDirection : SetPreviewDirection ,
66+ ) => {
5467 let shouldAddDir = false , addedDir = false ;
5568 detectCanvasElement ( el , ctx , setPreviewDirection ) ;
69+ detectExport ( el , ctx , setPreviewDirection ) ;
5670
5771 // Obsidian renders adjacent lines as one <p> element with <br> breaks. Since these cannot
5872 // be set a direction individually, the following breaks them into individual divs.
0 commit comments