Skip to content

Commit

Permalink
Fix incorrect downloaded file extension (#8928)
Browse files Browse the repository at this point in the history
* Fix incorrect downloaded file extension

* Update docs
  • Loading branch information
Leilei332 authored Feb 14, 2025
1 parent 2a2d998 commit fbe5a2f
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions boot/boot.js

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

2 changes: 1 addition & 1 deletion core/modules/saver-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ SaverHandler.prototype.saveWiki = function(options) {
// Call the highest priority saver that supports this method
for(var t=this.savers.length-1; t>=0; t--) {
var saver = this.savers[t];
if(saver.info.capabilities.indexOf(method) !== -1 && saver.save(text,method,callback,{variables: {filename: variables.filename}})) {
if(saver.info.capabilities.indexOf(method) !== -1 && saver.save(text,method,callback,{variables: {filename: variables.filename, type: variables.type}})) {
this.logger.log("Saving wiki with method",method,"through saver",saver.info.name);
return true;
}
Expand Down
8 changes: 6 additions & 2 deletions core/modules/savers/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ DownloadSaver.prototype.save = function(text,method,callback,options) {
options = options || {};
// Get the current filename
var filename = options.variables.filename;
var type = options.variables.type;
if(!filename) {
var p = document.location.pathname.lastIndexOf("/");
if(p !== -1) {
Expand All @@ -32,13 +33,16 @@ DownloadSaver.prototype.save = function(text,method,callback,options) {
if(!filename) {
filename = "tiddlywiki.html";
}
if(!type) {
type = "text/html";
}
// Set up the link
var link = document.createElement("a");
if(Blob !== undefined) {
var blob = new Blob([text], {type: "text/html"});
var blob = new Blob([text], {type: type});
link.setAttribute("href", URL.createObjectURL(blob));
} else {
link.setAttribute("href","data:text/html," + encodeURIComponent(text));
link.setAttribute("href","data:" + type + "," + encodeURIComponent(text));
}
link.setAttribute("download",filename);
document.body.appendChild(link);
Expand Down
1 change: 1 addition & 0 deletions core/templates/exporters/CsvFile.tid
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ title: $:/core/templates/exporters/CsvFile
tags: $:/tags/Exporter
description: {{$:/language/Exporters/CsvFile}}
extension: .csv
file-type: text/csv

<$macrocall $name="csvtiddlers" filter=<<exportFilter>> format="quoted-comma-sep" $output="text/raw"/>
1 change: 1 addition & 0 deletions core/templates/exporters/JsonFile.tid
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ title: $:/core/templates/exporters/JsonFile
tags: $:/tags/Exporter
description: {{$:/language/Exporters/JsonFile}}
extension: .json
file-type: application/json

<$macrocall $name="jsontiddlers" filter=<<exportFilter>> $output="text/raw"/>
1 change: 1 addition & 0 deletions core/templates/exporters/TidFile.tid
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ title: $:/core/templates/exporters/TidFile
tags: $:/tags/Exporter
description: {{$:/language/Exporters/TidFile}}
extension: .tid
file-type: text/vnd.tiddlywiki
condition: [<count>compare:lte[1]]

\define renderContent()
Expand Down
1 change: 1 addition & 0 deletions core/wiki/macros/export.tid
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ tags: $:/tags/Macro
$param=<<currentTiddler>>
exportFilter=<<exportFilter>>
filename={{{ [<baseFilename>addsuffix{!!extension}] }}}
type={{!!file-type}}
/>
<$action-deletetiddler $tiddler=<<qualify "$:/state/popup/export">>/>
<$transclude field="description"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The following variable names have special behaviour:

|!Name |!Description |
|filename |Filename for the downloaded file (note that this is a hint to the browser, and the actual filename used may be different) |
|type |<<.from-version "5.3.7">> Content type for the downloaded file |

The download file message is usually generated with the ButtonWidget.

Expand Down

0 comments on commit fbe5a2f

Please sign in to comment.