Im currently downloading a txt file on a button click but want to make the txt file more readable. Is there a way to bold the text in a blob? Only thing I've found is related more to the markup.
a.href = window.URL.createObjectURL(new Blob(["this text needs to be bold"]);
CodePudding user response:
const text = "<b>This text needs to be bold!</b> ...This text doesn't.";
const a = document.querySelector("a");
a.href = window.URL.createObjectURL(new Blob([text], { type: "text/html" }));
<a href="#">Click me!</a>
CodePudding user response:
What your Blob
's data contains is the content of a plain text file (.txt). This file format doesn't contain any styling info, so no, it's not possible to style it anyhow, neither bold nor italic or anything, except by the use of some Unicode hacks that you should avoid because your text won't be there anymore.
So what you need is to generate the data of a file that can be styled. HTML is one such format, but most text-editors will show you the markup instead of the rendering. RTF is another, but you'll need a library to generate this kind of files. And there might be other formats that better suit your needs, but that's on you to decide which to use.