Skip to content

Commit

Permalink
fix: pdf area annotation render issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
vipzhicheng committed Jun 18, 2024
1 parent 019d9ee commit 7e5740e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
// https://eslint.org/docs/rules/no-undef#nodejs
env: {
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.4.4

- fix: pdf area annotation render issue.
- fix: export as svg do not support image.
- chore: upgrade deps

## 0.4.3
Expand Down
2 changes: 1 addition & 1 deletion src/components/ControlPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const handleSavePNG = async () => {
const page = await logseq.Editor.getCurrentPage()
if (el) {
html2canvas(el, {}).then(async function (canvas: HTMLCanvasElement) {
const title = page?.originalName
const title = page?.originalName as string
const url = canvas.toDataURL('image/png')
const oA = document.createElement('a')
oA.download = title || ''
Expand Down
18 changes: 15 additions & 3 deletions src/funcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org from 'org'
import replaceAsync from 'string-replace-async'
import ellipsis from 'text-ellipsis'
import TurndownService from 'turndown'
import { l } from 'vite/dist/node/types.d-aGj9QkWt'

const settingsVersion = 'v3'
export const defaultSettings = {
Expand Down Expand Up @@ -76,6 +75,8 @@ export const getSVGContent = (svg: SVGElement): string => {
svgInner = svgInner
.replace(/onclick=".*?"/g, '')
.replace(/<a class="anchor".*?>.*?<\/a>/g, '')
.replace(/assets:\/\//g, '')
.replace(/<img([^<]*?)>/g, '<img$1/>')

let svgContent = `<?xml version="${xmlVersion}"?>
<svg version="${svgVersion}"
Expand Down Expand Up @@ -363,7 +364,9 @@ export const parseBlockContent = async (
const maxSize = logseq.settings?.maxRenderImageSize
? logseq.settings.maxRenderImageSize
: '100'
const minSize = 20
const minSize = logseq.settings?.minRenderImageSize
? logseq.settings.minRenderImageSize
: '50'
result = `<a target="_blank" title="PDF Annotation P${
block.properties.hlPage
}" data-lightbox="gallery" href="${
Expand All @@ -372,7 +375,7 @@ export const parseBlockContent = async (
block.properties.hlPage
}" src="${
filePath.indexOf('http') !== 0 ? 'assets://' : ''
}${filePath}" style="max-width: ${maxSize}px; max-height: ${maxSize}px; min-height: ${minSize}px; min-width: ${minSize}px;"/></a>`
}${filePath}" style="max-height: ${maxSize}px; min-width: ${minSize}px;"/></a>`
} else {
result = `<a target="_blank" title="PDF Annotation P${
block.properties.hlPage
Expand Down Expand Up @@ -686,6 +689,15 @@ export const getSettingsDefinition = (): SettingSchemaDesc[] => {
enumChoices: ['200', '150', '100', '50'],
default: '100',
},
{
title: '(Experimental) Min images size for rendering',
key: 'minRenderImageSize',
description:
'The minimum image side length will be more than this setting.',
type: 'enum',
enumChoices: ['200', '150', '100', '50'],
default: '50',
},
]
}

Expand Down
11 changes: 3 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@ import { useSettings } from '@/composables/useSettings'
import { createPinia } from 'pinia'
import { createApp } from 'vue'
import App from './App.vue'
import {
getSettings,
getSettingsDefinition,
hookMarkmapTransformer,
initSettings,
} from './funcs'
import './assets/index.css'
import { getSettings, getSettingsDefinition, initSettings } from './funcs'

const app = createApp(App)
app.use(createPinia())
Expand Down Expand Up @@ -162,8 +157,8 @@ async function main() {
updateSettings(newSettings)
resetTheme()
if (logseq.settings?.theme && logseq.settings.theme !== 'auto') {
if (themeMapping[logseq.settings.theme]) {
setTheme(themeMapping[logseq.settings.theme])
if (themeMapping[logseq.settings.theme as string]) {
setTheme(themeMapping[logseq.settings.theme as string])
}
}
})
Expand Down

0 comments on commit 7e5740e

Please sign in to comment.