Convert a directory of markdown files to structured and usable JSON
Features
contents property.
Install
$ npm install jdownUsage
const jdown = require('jdown');
jdown('path/to/markdown/content').then(content => console.log(content));Where "path/to/markdown/content" is a directory containing markdown files or folders as described under the "Features" header above. The file path will be relative to the project root so if your content was in /Users/username/project/src/content, you would use jdown('src/content').
Use the generated JSON however you like, I recommend with a static site generator like React Static! This way you can use the markdown files as a CMS and use the JSON in the build stage.
Custom render options
By default, jdown uses the default marked render options, but you may pass in your own custom overrides to customize the built html. This can be useful for adding custom ids or CSS classes. In the example below you can see how you can make your links open in a new tab by default, by adding target="_blank" to anchor tags.
const jdown = require('jdown');
const marked = require('marked');
const renderer = new marked.Renderer();
renderer.link = (href, title, text) => `<a target="_blank" href="${href}" title="${title}">${text}</a>`;
jdown('path/to/markdown/content', {renderer}).then(content => console.log(content));See the advanced configurations and extensibility sections of the marked documentation for the full list of possible options you may use here.
Disabling markdown parsing
In some cases you may wish to disable markdown parsing to just recieve structured JSON containing markdown instead of HTML. You can accomplish this using the parseMd option like so:
jdown('path/to/markdown/content', {parseMd: false}).then(content => console.log(content));Examples
See the examples directory of this repository. To test it yourself clone this repo, install the dependancies with npm install, modify some content and run npm run example.
danwebb.co is built using jdown and React Static so see the static.config.js file in the websites github repo for a real world example.
There is also an example built into React Static that you can use to quickly get up and running here.
Contributing
Any pull requests are welcome and will be reviewed. Please use npm run test to test your changes are working before submitting any changes.
License
MIT

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.


