From 9ad512726cca9141a757499e059303fb76c41a36 Mon Sep 17 00:00:00 2001 From: Brian Carlsen Date: Wed, 1 Dec 2021 10:11:07 +0100 Subject: [PATCH] [main] Updated figure number regex for Apple devices. [md_processor] Added MarkdownPostProcessorContext in attempt to render markdown in caaptions, but does not work. --- manifest.json | 2 +- package.json | 4 ++-- src/main.ts | 9 +++++++-- src/md_processor.ts | 13 ++++++++----- versions.json | 1 + 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/manifest.json b/manifest.json index 30d4316..1a9d134 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-image-caption", "name": "Image Caption", - "version": "0.0.7", + "version": "0.0.8", "minAppVersion": "0.12.19", "description": "Add captions to images.", "author": "bicarlsen", diff --git a/package.json b/package.json index 13a9c99..aa49baa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-image-caption", - "version": "0.0.7", + "version": "0.0.8", "description": "Add captions to images in Obsidian.", "main": "main.js", "scripts": { @@ -13,7 +13,7 @@ "devDependencies": { "@types/node": "^16.11.1", "esbuild": "0.13.8", - "obsidian": "^0.12.17", + "obsidian": "^0.12.19", "tslib": "2.3.1", "typescript": "4.4.4" } diff --git a/src/main.ts b/src/main.ts index 23b4101..5eeb062 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,6 +23,7 @@ const DEFAULT_SETTINGS: ImageCaptionSettings = { delimeter: [] } + export default class ImageCaptionPlugin extends Plugin { settings: ImageCaptionSettings; @@ -85,9 +86,13 @@ export default class ImageCaptionPlugin extends Plugin { let label = this.settings.label; if ( label ) { - const number_pattern = /(? { for ( const mutation of mutations ) { @@ -29,7 +29,8 @@ export function captionObserver( plugin: Plugin ) { caption_text = parseCaptionText( caption_text, plugin.settings.delimeter ); if ( caption_text !== null ) { - addCaption( mutation.target, caption_text ); + const caption = addCaption( mutation.target, caption_text ); + ctx.addChild( caption ); } } // end for..of @@ -39,6 +40,7 @@ export function captionObserver( plugin: Plugin ) { } ); } + function parseCaptionText( text: string, delimeter: string[] ): string | null { if ( delimeter.length === 0 ) { return text; @@ -72,16 +74,17 @@ function parseCaptionText( text: string, delimeter: string[] ): string | null { return text.slice( start + start_offset, end ); } + function addCaption( target: HTMLElement, caption_text: string -): HTMLElement { +): MarkdownRenderChild { const caption = document.createElement( ImageCaptionPlugin.caption_tag ); caption.addClass( ImageCaptionPlugin.caption_class ); caption.innerText = caption_text; target.appendChild( caption ); - return caption; + return new MarkdownRenderChild( caption ); } @@ -112,7 +115,7 @@ export function processImageCaption( ( container: HTMLElement ) => { // must listen for class changes because images // may be loaded after this run - const observer = captionObserver( plugin ); + const observer = captionObserver( plugin, ctx ); observer.observe( container, { attributes: true, attributesFilter: [ 'class' ] } diff --git a/versions.json b/versions.json index 415230e..3d63919 100644 --- a/versions.json +++ b/versions.json @@ -1,4 +1,5 @@ { + "0.0.8": "0.12.19", "0.0.7": "0.12.19", "0.0.6": "0.12.19", "0.0.5": "0.12.19",