Skip to content

Commit cda6886

Browse files
committed
Fix: download single file
1 parent d68d712 commit cda6886

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

src/App.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -628,23 +628,12 @@ class App extends Component {
628628
DisplayList.length > 0 && DisplayList[0].click();
629629
}
630630

631-
handleDownloadNote(e) {
632-
const html = document.getElementById("notebody-view").innerHTML;
633-
const data = html2md.turndown(marked(html));
634-
const title = html2md
635-
.turndown(marked(document.getElementById("notetitle-view").innerHTML))
636-
.replace(/ /g, "_");
637-
const fileName = `${title || "note"}.md`;
638-
var a = document.createElement("a");
639-
document.body.appendChild(a);
640-
a.style = "display: none";
641-
var blob = new Blob([data], { type: "text/plain;charset=utf-8" }),
642-
url = window.URL.createObjectURL(blob);
643-
a.href = url;
644-
a.download = fileName;
645-
a.click();
646-
window.URL.revokeObjectURL(url);
647-
e.preventDefault();
631+
handleDownloadNote(note) {
632+
const title = `${note.notetitle.replace(/[^A-Z0-9]+/gi, "_") || "note"}.md`;
633+
var blob = new Blob([note.notebody], {
634+
type: "text/plain;charset=utf-8",
635+
});
636+
saveAs(blob, title);
648637
}
649638

650639
handleNotesBackup() {

src/NavbarMain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function NavbarMain(props) {
2929
className="far fa-arrow-alt-circle-down btn"
3030
aria-hidden="true"
3131
style={{ float: "right" }}
32-
onClick={(e) => props.handleDownloadNote(e, note)}
32+
onClick={(e) => props.handleDownloadNote(note)}
3333
></i>
3434
</div>
3535
</div>

src/NoteSort.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ function NoteSort(props) {
1818
</select>
1919
</label>
2020
<div className="backupbtn">
21-
<i class="fas fa-download btn" onClick={props.handleNotesBackup}></i>
21+
<i
22+
className="fas fa-download btn"
23+
onClick={props.handleNotesBackup}
24+
></i>
2225
</div>
2326
</div>
2427
);

0 commit comments

Comments
 (0)