Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
"styled-components": "^4.3.2",
"unified": "^9.1.0",
"unist-util-visit": "^2.0.3",
"use-force-update": "^1.0.7"
"use-force-update": "^1.0.7",
"yaml": "^1.10.0"
},
"build": {
"appId": "com.boostio.boostnote",
Expand Down
47 changes: 36 additions & 11 deletions src/components/organisms/NotePageToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
mdiDotsVertical,
mdiStarOutline,
mdiStar,
mdiExportVariant,
} from '@mdi/js'
import { borderBottom, flexCenter } from '../../lib/styled/styleFunctions'
import ToolbarIconButton from '../atoms/ToolbarIconButton'
Expand All @@ -21,13 +22,15 @@ import { values, isTagNameValid } from '../../lib/db/utils'
import {
exportNoteAsHtmlFile,
exportNoteAsMarkdownFile,
exportNoteAsPdfFile,
} from '../../lib/exports'
import { usePreferences } from '../../lib/preferences'
import { usePreviewStyle } from '../../lib/preview'
import { useTranslation } from 'react-i18next'
import { useDb } from '../../lib/db'
import { useRouteParams } from '../../lib/routeParams'
import { useAnalytics, analyticsEvents } from '../../lib/analytics'
import { useToast } from '../../lib/toast'
import TopbarSwitchSelector from '../atoms/TopbarSwitchSelector'
import { openContextMenu } from '../../lib/electronOnly'

Expand Down Expand Up @@ -76,6 +79,7 @@ const NotePageToolbar = ({
const { previewStyle } = usePreviewStyle()
const { generalStatus } = useGeneralStatus()
const { noteViewMode, preferredEditingViewMode } = generalStatus
const { pushMessage } = useToast()

const storageId = storage.id
const storageName = storage.name
Expand Down Expand Up @@ -168,6 +172,8 @@ const NotePageToolbar = ({
selectViewMode('preview')
}, [selectViewMode])

const includeFrontMatter = preferences['markdown.includeFrontMatter']

const openExportContextMenu = useCallback(
(event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault()
Expand All @@ -176,24 +182,43 @@ const NotePageToolbar = ({
}
openContextMenu({
menuItems: [
{
type: 'normal',
label: 'Markdown export',
click: async () =>
await exportNoteAsMarkdownFile(note, {
includeFrontMatter,
}),
},
{
type: 'normal',
label: 'HTML export',
click: async () =>
await exportNoteAsHtmlFile(note, preferences, previewStyle),
await exportNoteAsHtmlFile(
note,
preferences,
pushMessage,
previewStyle
),
},
{
type: 'normal',
label: 'Markdown export',
label: 'PDF export',
click: async () =>
await exportNoteAsMarkdownFile(note, {
includeFrontMatter: preferences['markdown.includeFrontMatter'],
}),
await exportNoteAsPdfFile(
note,
preferences,
pushMessage,
{
includeFrontMatter,
},
previewStyle
),
},
],
})
},
[note, preferences, previewStyle]
[note, preferences, includeFrontMatter, previewStyle, pushMessage]
)

const routeParams = useRouteParams()
Expand Down Expand Up @@ -320,6 +345,11 @@ const NotePageToolbar = ({
onClick={!note.data.bookmarked ? bookmark : unbookmark}
iconPath={note.data.bookmarked ? mdiStar : mdiStarOutline}
/>
<ToolbarIconButton
title={t('note.export')}
onClick={openExportContextMenu}
iconPath={mdiExportVariant}
/>
{note.trashed ? (
<>
<ToolbarIconButton
Expand All @@ -340,11 +370,6 @@ const NotePageToolbar = ({
iconPath={mdiTrashCan}
/>
)}
<ToolbarIconButton
title={t('note.export')}
onClick={openExportContextMenu}
iconPath={mdiDotsVertical}
/>
</Control>
)}
</Container>
Expand Down
6 changes: 6 additions & 0 deletions src/electron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
BrowserWindow,
BrowserWindowConstructorOptions,
Menu,
protocol,
} from 'electron'
import path from 'path'
import url from 'url'
Expand Down Expand Up @@ -102,6 +103,11 @@ app.on('activate', () => {

// create main BrowserWindow when electron is ready
app.on('ready', () => {
/* This file protocol registration will be needed from v9.x.x for PDF export feature */
protocol.registerFileProtocol('file', (request, callback) => {
const pathname = decodeURI(request.url.replace('file:///', ''))
callback(pathname)
})
mainWindow = createMainWindow()

app.on('open-url', (_event, url) => {
Expand Down
Loading