snow-editor

small markdown and org-mode editor
Log | Files | Refs | README

download.js (503B)


      1 import { MODES } from './editorConstants.js';
      2 
      3 export function downloadDocument(content, mode, filenameBase = 'document') {
      4   const isOrg = mode === MODES.ORG;
      5   const blob = new Blob([content], {
      6     type: isOrg ? 'text/plain;charset=utf-8' : 'text/markdown;charset=utf-8',
      7   });
      8   const url = URL.createObjectURL(blob);
      9   const link = document.createElement('a');
     10   link.href = url;
     11   link.download = isOrg ? `${filenameBase}.org` : `${filenameBase}.md`;
     12   link.click();
     13   URL.revokeObjectURL(url);
     14 }