Skip to content

Commit

Permalink
feat: enable rendering images on markmap, and adjust render size.
Browse files Browse the repository at this point in the history
  • Loading branch information
vipzhicheng committed Feb 4, 2024
1 parent adfa090 commit 192220b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.4.1

- feat: enable rendering images on markmap, and adjust render size.

## 0.4

- feat: make task tag clickable
Expand All @@ -14,6 +18,7 @@
## 0.3.16

- fix: allow empty block with children blocks exists.

## 0.3.15

- fix: style for `WAITING` task and `CANCELLED` task
Expand Down
32 changes: 32 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ const defineSettings: SettingSchemaDesc[] = [
type: 'boolean',
default: false,
},
{
title: '(Experimental) Enable rendering images on markmap',
key: 'enableRenderImage',
description:
'By default render images as icon and image alt text. If you want to render images as image, check this option.',
type: 'boolean',
default: false,
},
{
title: '(Experimental) Max images size for rendering',
key: 'maxRenderImageSize',
description:
'The longest image side length will be less than this setting.',
type: 'enum',
enumChoices: ['200', '150', '100', '50'],
default: '100',
},
]
logseq.useSettingsSchema(defineSettings)

Expand Down Expand Up @@ -361,6 +378,21 @@ async function main() {

if (['pdf'].includes(src.substring(src.lastIndexOf('.') + 1))) {
result = `📄 ${alt}`
} else if (
logseq.settings?.enableRenderImage &&
['png', 'jpg', 'jpeg', 'webp'].includes(
src.substring(src.lastIndexOf('.') + 1).toLowerCase()
)
) {
const maxSize = logseq.settings?.maxRenderImageSize
? logseq.settings.maxRenderImageSize
: '100'
const minSize = 20
result = `<a target="_blank" title="${alt}" data-lightbox="gallery" href="${
src.indexOf('http') !== 0 ? 'assets://' : ''
}${src}"><img alt="${alt}" src="${
src.indexOf('http') !== 0 ? 'assets://' : ''
}${src}" style="max-width: ${maxSize}px; max-height: ${maxSize}px; min-height: ${minSize}px; min-width: ${minSize}px;"/></a>`
} else {
result = `<a target="_blank" title="${alt}" data-lightbox="gallery" href="${
src.indexOf('http') !== 0 ? 'assets://' : ''
Expand Down

0 comments on commit 192220b

Please sign in to comment.