55// Last updated 2025-05-31 by @jgclark
66// ---------------------------------------------------------
77import showdown from 'showdown' // for Markdown -> HTML from https://github.com/showdownjs/showdown
8- import {
9- hasFrontMatter
10- } from '@helpers/NPFrontMatter'
8+ import { hasFrontMatter } from '@helpers/NPFrontMatter'
119import { getFolderFromFilename } from '@helpers/folders'
1210import { clo , logDebug , logError , logInfo , logWarn , JSP , timer } from '@helpers/dev'
1311import { getStoredWindowRect , isHTMLWindowOpen , storeWindowRect } from '@helpers/NPWindows'
@@ -86,7 +84,7 @@ export function getCallbackCodeString(jsFunctionName: string, commandName: strin
8684 .replace("%%commandName%%", commandName)
8785 .replace("%%pluginID%%", pluginID)
8886 .replace("%%commandArgs%%", () => JSON.stringify(commandArgs)); //This is important because it works around problems with $$ in commandArgs
89- // console.log(\` ${ jsFunctionName } : Sending command "\$\{commandName\}" to NotePlan: "\$\{pluginID\}" with args: \$\{JSON.stringify(commandArgs)\}\`);
87+
9088 console.log(\`window.${ jsFunctionName } : Sending code: "\$\{code\}"\`)
9189 if (window.webkit) {
9290 window.webkit.messageHandlers.jsBridge.postMessage({
@@ -101,7 +99,6 @@ export function getCallbackCodeString(jsFunctionName: string, commandName: strin
10199`
102100}
103101
104-
105102/**
106103 * Convert a note's content to HTML and include any images as base64
107104 * @param {string } content
@@ -164,22 +161,22 @@ export async function getNoteContentAsHTML(content: string, note: TNote): Promis
164161 tasklists : true ,
165162 metadata : false , // otherwise metadata is swallowed
166163 requireSpaceBeforeHeadingText : true ,
167- simpleLineBreaks : true // Makes this GFM style. TODO: make an option?
164+ simpleLineBreaks : true , // Makes this GFM style. TODO: make an option?
168165 }
169166 const converter = new showdown . Converter ( converterOptions )
170167 let body = converter . makeHtml ( lines . join ( `\n` ) )
171168 body = `<style>img { background: white; max-width: 100%; max-height: 100%; }</style>${ body } ` // fix for bug in showdown
172-
169+
173170 const imgTagRegex = / < i m g s r c = \" ( .* ?) \" / g
174171 const matches = [ ...body . matchAll ( imgTagRegex ) ]
175172 const noteDirPath = getFolderFromFilename ( note . filename )
176-
173+
177174 for ( const match of matches ) {
178175 const imagePath = match [ 1 ]
179176 try {
180177 // Handle both absolute and relative paths
181178 let fullPath = `../../../Notes/${ noteDirPath } /${ decodeURI ( imagePath ) } `
182- if ( fullPath . endsWith ( '.drawing' ) ) {
179+ if ( fullPath . endsWith ( '.drawing' ) ) {
183180 fullPath = fullPath . replace ( '.drawing' , '.png' )
184181 }
185182 const data = await DataStore . loadData ( fullPath , false )
@@ -237,14 +234,12 @@ export async function getNoteContentAsHTML(content: string, note: TNote): Promis
237234 modifiedLines . push ( line )
238235 }
239236 return modifiedLines . join ( '\n' )
240-
241237 } catch ( error ) {
242238 logError ( 'getNoteContentAsHTML' , error . message )
243239 return '<conversion error>'
244240 }
245241}
246242
247-
248243/**
249244 * This function creates the webkit console.log/error handler for HTML messages to get back to NP console.log
250245 * @returns {string } - the javascript (without a tag)
@@ -566,7 +561,10 @@ export async function showHTMLV2(body: string, opts: HtmlWindowOptions): Promise
566561 try {
567562 const screenWidth = NotePlan . environment . screenWidth
568563 const screenHeight = NotePlan . environment . screenHeight
569- logDebug ( 'HTMLView / showHTMLV2' , `starting with customId ${ opts . customId ?? '' } and reuseUsersWindowRect ${ String ( opts . reuseUsersWindowRect ) ?? '??' } for screen dimensions ${ screenWidth } x${ screenHeight } ` )
564+ logDebug (
565+ 'HTMLView / showHTMLV2' ,
566+ `starting with customId ${ opts . customId ?? '' } and reuseUsersWindowRect ${ String ( opts . reuseUsersWindowRect ) ?? '??' } for screen dimensions ${ screenWidth } x${ screenHeight } ` ,
567+ )
570568
571569 // Assemble the parts of the HTML into a single string
572570 const fullHTMLStr = assembleHTMLParts ( body , opts )
@@ -592,8 +590,8 @@ export async function showHTMLV2(body: string, opts: HtmlWindowOptions): Promise
592590 winOptions = {
593591 x : opts . x ?? ( screenWidth - ( screenWidth - ( opts . paddingWidth ?? 0 ) * 2 ) ) / 2 ,
594592 y : opts . y ?? ( screenHeight - ( screenHeight - ( opts . paddingHeight ?? 0 ) * 2 ) ) / 2 ,
595- width : opts . width ?? ( screenWidth - ( opts . paddingWidth ?? 0 ) * 2 ) ,
596- height : opts . height ?? ( screenHeight - ( opts . paddingHeight ?? 0 ) * 2 ) ,
593+ width : opts . width ?? screenWidth - ( opts . paddingWidth ?? 0 ) * 2 ,
594+ height : opts . height ?? screenHeight - ( opts . paddingHeight ?? 0 ) * 2 ,
597595 shouldFocus : opts . shouldFocus ,
598596 id : cId , // don't need both ... but trying to work out which is the current one for the API
599597 windowId : cId ,
@@ -603,7 +601,6 @@ export async function showHTMLV2(body: string, opts: HtmlWindowOptions): Promise
603601 // logDebug('showHTMLV2', `- Trying to use user's saved Rect from pref for ${cId}`)
604602 const storedRect = getStoredWindowRect ( cId )
605603 if ( storedRect ) {
606-
607604 winOptions = {
608605 x : storedRect . x ,
609606 y : storedRect . y ,
0 commit comments