diff --git a/package.json b/package.json index ba50da02f..04fa83668 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,7 @@ "react-scripts": "4.0.2", "react-use": "17.1.1", "redux": "4.0.5", + "sanitize-filename": "1.6.3", "ts-mockery": "1.2.0", "typescript": "4.1.5", "use-resize-observer": "7.0.0", diff --git a/src/components/editor-page/sidebar/export-markdown-sidebar-entry.tsx b/src/components/editor-page/sidebar/export-markdown-sidebar-entry.tsx index f1ca3872c..4f92e05c4 100644 --- a/src/components/editor-page/sidebar/export-markdown-sidebar-entry.tsx +++ b/src/components/editor-page/sidebar/export-markdown-sidebar-entry.tsx @@ -5,18 +5,20 @@ */ import React, { useCallback } from 'react' +import sanitize from 'sanitize-filename' +import { store } from '../../../redux' import { Trans, useTranslation } from 'react-i18next' import { useNoteMarkdownContent } from '../../../hooks/common/use-note-markdown-content' import { download } from '../../common/download/download' import { SidebarButton } from './sidebar-button' export const ExportMarkdownSidebarEntry: React.FC = () => { - useTranslation() - + const { t } = useTranslation() const markdownContent = useNoteMarkdownContent() const onClick = useCallback(() => { - download(markdownContent, `title.md`, 'text/markdown') //todo: replace hard coded title with redux - }, [markdownContent]) + const sanitized = sanitize(store.getState().noteDetails.noteTitle) + download(markdownContent, `${ sanitized !== '' ? sanitized : t('editor.untitledNote') }.md`, 'text/markdown') + }, [markdownContent, t]) return ( diff --git a/yarn.lock b/yarn.lock index d7d4b1e4e..1055e64c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12770,6 +12770,13 @@ sane@^4.0.3: minimist "^1.1.1" walker "~1.0.5" +sanitize-filename@1.6.3: + version "1.6.3" + resolved "https://registry.yarnpkg.com/sanitize-filename/-/sanitize-filename-1.6.3.tgz#755ebd752045931977e30b2025d340d7c9090378" + integrity sha512-y/52Mcy7aw3gRm7IrcGDFx/bCk4AhRh2eI9luHOQM86nZsqwiRkkq2GekHXBBD+SmPidc8i2PqtYZl+pWJ8Oeg== + dependencies: + truncate-utf8-bytes "^1.0.0" + sanitize.css@^10.0.0: version "10.0.0" resolved "https://registry.yarnpkg.com/sanitize.css/-/sanitize.css-10.0.0.tgz#b5cb2547e96d8629a60947544665243b1dc3657a" @@ -14023,6 +14030,13 @@ trim-newlines@^1.0.0: dependencies: glob "^7.1.2" +truncate-utf8-bytes@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz#405923909592d56f78a5818434b0b78489ca5f2b" + integrity sha1-QFkjkJWS1W94pYGENLC3hInKXys= + dependencies: + utf8-byte-length "^1.0.1" + try-catch@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/try-catch/-/try-catch-2.0.1.tgz#a35d354187c422f291a0bcfd9eb77e3a4f90c1e5" @@ -14380,6 +14394,11 @@ use@^3.1.0: resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ== +utf8-byte-length@^1.0.1: + version "1.0.4" + resolved "https://registry.yarnpkg.com/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz#f45f150c4c66eee968186505ab93fcbb8ad6bf61" + integrity sha1-9F8VDExm7uloGGUFq5P8u4rWv2E= + util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"