knennigtri / merge-markdown

A tool to take in a list of markdown files and merge them with optional HTML/PDF output
76 stars 9 forks source link

merge-markdown -m path/to/files without YAML #27

Closed khofstadter closed 2 years ago

khofstadter commented 2 years ago

hello!

Is it possible to merge all files in a folder without the YAML front matter?

I could only merge files without YAML front matter by using the myManifest.md file and the option for each file e.g.

---
input:
  00-1-title-pages.md: {noYAML: true}
  00-2-toc.md: {noYAML: true}
  00-3-figures.md: {noYAML: true}
  00-4-tables.md: {noYAML: true}
  00-5-acronyms-and-definitions.md: {noYAML: true}
  01-introduction.md: {noYAML: true}
  02-0-methodology.md: {noYAML: true}
  02-1-method-litrev.md: {noYAML: true}
  03--litrev-overview.md: {noYAML: true}
  03-1-litrev-bci.md: {noYAML: true}
  03-2-litrev-nf.md: {noYAML: true}
  03-3-litrev-meditation.md: {noYAML: true}
  03-4-litrev-neuromeditation.md: {noYAML: true}
  03-5-litrev-bcmi.md: {noYAML: true}
  03-6-litrev-syncronisation-entrainment.md: {noYAML: true}
output: myOutput.md
---

But my list of files is actually longer and sometimes the filenames change.

Thanks! k

knennigtri commented 2 years ago

As it stands currently, I don't think this is possible, but I think I might be able to come up with a quick solution so that you can make global rules in the manifest for all files in a folder. Right now, if you use a manifest, it requires an input. But if I remove that requirement and just make the all files in the folder default, it should solve this quickly.

knennigtri commented 2 years ago

Once implemented, your manifest would look something like this:

---
noYAML: true
output: myOutput.md
---

Where noYAML becomes global for all files.

knennigtri commented 2 years ago

@khofstadter this is now possible with the 0.2.1 release today. See https://www.npmjs.com/package/merge-markdown#options-applied-to-all-files-in-a-folder

khofstadter commented 2 years ago

@knennigtri thanks!

It works, but I have some error messages and I am not exactly sure what they mean.

These were my steps:

  1. updated the package
  2. changed the myManifest.md file with this content:
---
output: myOutput.md
noYAML: true
replace:
  ${timestamp}: 06/01/2021
  ({#(.*?)}): ""
TOC: "#### Chapter contents"
---
  1. in the Terminal I navigated to the folder where the .md files to merge are kept (the myManifest.md file is in this folder as well, but its content wasn't added to the final merged file)

  2. used merge-markdown -m myManifest.md to merge the files

  3. the files are merged in myOutput.md but the Terminal says this at the end of the process:

myOutput.md has been created.
node:events:368
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20)
Emitted 'error' event on ClientRequest instance at:
    at TLSSocket.socketErrorListener (node:_http_client:447:9)
    at TLSSocket.emit (node:events:390:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -54,
  code: 'ECONNRESET',
  syscall: 'read'
}

thanks!

knennigtri commented 2 years ago

Well, I'm glad it's working. I'm not sure though why that error is being returned. I'll try and investigate and see if I can reproduce and figure it out.

Good luck!

khofstadter commented 2 years ago

Hello, thanks again for adding this earlier.

How could I exclude the 'myOutput.md' file created earlier?

There are tree extra .md files in the folder:

The first two are automatically excluded when merging, but the last one I always have to delete before merging again.

Thanks!

k

knennigtri commented 2 years ago

This is fixed with 0.2.2 that was just pushed with #30