crossnote icon indicating copy to clipboard operation
crossnote copied to clipboard

Feature Request: Specify output directory

Open dzackgarza opened this issue 6 years ago • 8 comments

Perhaps this is already a feature somewhere that I've overlooked, but is it possible to specify the output directory and filename when running the various engine.export functions?

Right now it seems to put the output file in the same directory as the input file. In my case, the situation is something like this:

const engine = new mume.MarkdownEngine({
    filePath: "/some/directory/file.md",
    config: config
});

const result = await engine.htmlExport({ offline: false, runAllCodeChunks: true });
// Produces "/some/directory/file.html"

dzackgarza avatar May 31 '18 22:05 dzackgarza

There's probably no option to configure this at the moment. @shd101wyy have I missed something too?

kachkaev avatar Jun 24 '18 10:06 kachkaev

No it is not possible to specify the output directory (path) now. But we will support it in the future.

shd101wyy avatar Jul 23 '18 16:07 shd101wyy

I may be able to help with this somehow - am I correct in thinking that it would just require passing in a filename and setting the dest parameter at the bottom here? https://github.com/shd101wyy/mume/blob/95533b5f4e671e9011231e4359544866f18d7584/src/markdown-engine.ts#L1517-L1545

dzackgarza avatar Jul 31 '18 23:07 dzackgarza

Like perhaps something like this instead?


   public async htmlExport({ 
     offline = false, 
     runAllCodeChunks = false,
     outputDirectory = null    // Changed
   }): Promise<string> { 
     const inputString = await utility.readFile(this.filePath, { 
       encoding: "utf-8", 
     }); 
     let html; 
     let yamlConfig; 
     ({ html, yamlConfig } = await this.parseMD(inputString, { 
       useRelativeFilePath: true, 
       hideFrontMatter: true, 
       isForPreview: false, 
       runAllCodeChunks, 
     })); 
     const htmlConfig = yamlConfig["html"] || {}; 
     if ("offline" in htmlConfig) { 
       offline = htmlConfig["offline"]; 
     } 
     const embedLocalImages = htmlConfig["embed_local_images"]; // <= embedLocalImages is disabled by default. 
  
     let embedSVG = true; // <= embedSvg is enabled by default. 
     if ("embed_svg" in htmlConfig) { 
       embedSVG = htmlConfig["embed_svg"]; 
     } 
  
     let dest = outputDirectory || this.filePath;     // Changed
     const extname = path.extname(dest); 
     dest = dest.replace(new RegExp(extname + "$"), ".html"); 

With the intended use just being something like

await engine.htmlExport({ 
  offline: false, 
  runAllCodeChunks: true,
  outputDirectory: "/home/someuser/somedirectory"
});

dzackgarza avatar Jul 31 '18 23:07 dzackgarza

Hi @dzackgarza yes you are correct. But dest should be the path of file, not directory. It would be great if someone could could submit a pull request, as I am super busy recently :(

shd101wyy avatar Aug 01 '18 19:08 shd101wyy

+1

lukesmurray avatar Nov 21 '18 23:11 lukesmurray

@shd101wyy

Hi @dzackgarza yes you are correct. But dest should be the path of file, not directory. It would be great if someone could could submit a pull request, as I am super busy recently :(

I think it's time to consider the scan of the entire directory and the output of the entire directory. The input and output path of a single file does not make much sense.

@dzackgarza was doing great.

siriuscc avatar Aug 11 '19 02:08 siriuscc

This is working when using the following front-matter in your md file:

---
export_on_save:
  markdown: true
markdown:
  path: your_file_name.md
  absolute_image_path: false
---

Greg7000 avatar Nov 21 '22 15:11 Greg7000