{"id":15481662,"url":"https://github.com/sparkartgroup/gulp-markdown-to-json","last_synced_at":"2025-07-24T06:42:18.454Z","repository":{"id":18521416,"uuid":"21721421","full_name":"sparkartgroup/gulp-markdown-to-json","owner":"sparkartgroup","description":"Parse Markdown and YAML → compile Markdown to HTML → wrap it all up in JSON","archived":false,"fork":false,"pushed_at":"2022-11-02T13:52:49.000Z","size":256,"stargazers_count":75,"open_issues_count":7,"forks_count":14,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-10-19T05:16:54.605Z","etag":null,"topics":["gulp","gulp-plugin","markdown","static-site-generator"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sparkartgroup.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-11T04:14:09.000Z","updated_at":"2024-09-23T20:00:41.000Z","dependencies_parsed_at":"2022-07-22T07:32:05.421Z","dependency_job_id":null,"html_url":"https://github.com/sparkartgroup/gulp-markdown-to-json","commit_stats":null,"previous_names":["sparkartgroupinc/gulp-markdown-to-json"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparkartgroup%2Fgulp-markdown-to-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparkartgroup%2Fgulp-markdown-to-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparkartgroup%2Fgulp-markdown-to-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sparkartgroup%2Fgulp-markdown-to-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sparkartgroup","download_url":"https://codeload.github.com/sparkartgroup/gulp-markdown-to-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229885900,"owners_count":18139382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gulp","gulp-plugin","markdown","static-site-generator"],"created_at":"2024-10-02T05:05:24.812Z","updated_at":"2024-12-19T14:07:27.303Z","avatar_url":"https://github.com/sparkartgroup.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[gulp](http://gulpjs.com)-markdown-to-json\n==========================================\n\n[![CircleCI Status][circleci-badge]][circleci]\n[![Semistandard Style][semistandard-badge]][semistandard]\n\n\u003e Parse Markdown + YAML, compile Markdown to HTML, wrap it in JSON.\n\nThe neutral format of JSON opens new possibilities for your handcrafted content. Send it onward to other plugins such as [gulp-hb][hb]. When their powers combine, you get a static site generator! Pipe to [request][request] to send it to a [search index][algolia] or [import into a CMS][contentful]. Write a plugin to [tap into the stream][plugin] if you need a client library.\n\nTable of Contents\n-----------------\n\n- [Install](#install)\n- [Usage](#usage)\n- [API](#api)\n- [Contribute](#contribute)\n- [License](#license)\n\nInstall\n-------\n\n```bash\nnpm install gulp-markdown-to-json --save-dev\n```\n\n### Dependencies\n\nThis plugin does not bundle any Markdown parser to keep your options open. BYOM!\n\nPick one of these or write a new parser for fun!\n\n- [commonmark.js][commonmark.js]\n- [markdown-js][markdown-js]\n- [markdown-it][markdown-it] ← the best\n- [marked][marked]\n- [remark][remark]\n- [remarkable][remarkable]\n\nInstall, configure, and pass a rendering method to this plugin with a source string as its first argument. Output goes straight into the JSON file’s `body` property. If your parser requires instantiation pass a context to call it with by defining `context` in the config object. If yet more hoop jumping is required, write a wrapper function such as this example for remark:\n\n```js\nfunction render (string) {\n  const remark = require('remark');\n  const html = require('remark-html');\n  return remark().use(html).process(string).toString();\n}\n```\n\n\u003e **Note:**\n\u003e YAML frontmatter blocks are stripped and handled before Markdown rendering with [front-matter][front-matter]\n\nUsage\n-----\n\n**`/gulpfile.js`**\n\n```javascript\nconst gulp = require('gulp');\nconst markdownToJSON = require('gulp-markdown-to-json');\nconst marked = require('marked');\n\nmarked.setOptions({\n  pedantic: true,\n  smartypants: true\n});\n\ngulp.task('markdown', () =\u003e {\n  gulp.src('./content/**/*.md')\n    .pipe(markdownToJSON(marked))\n    .pipe(gulp.dest('.'))\n});\n```\n\nTransformed source files flow onward to the destination of your choice with directory structure preserved. Any valid JSON files matched by your `gulp.src` glob passthrough.\n\n**`/blog/posts/bushwick-artisan.md`**\n\n```md\n---\nslug: bushwick-artisan\ntitle: Wes Anderson pop-up Bushwick artisan\nlayout: centered\n---\n\n## YOLO\nChia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.\n```\n\n**`/blog/posts/bushwick-artisan.json`**\n\n```json\n{\n  \"slug\": \"bushwick-artisan\",\n  \"title\": \"Wes Anderson pop-up Bushwick artisan\",\n  \"layout\": \"centered\",\n  \"body\": \"\u003ch2 id=\\\"yolo\\\"\u003eYOLO\u003c/h2\u003e\\n\u003cp\u003eChia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.\u003c/p\u003e\",\n  \"updatedAt\": \"1970-01-01T00:00:00Z\"\n}\n```\n\n### Consolidated Output\n\nGather Markdown files before piping with [list-stream][] to combine output into a single JSON file. Directory structure is preserved and represented as nested JSON for iteration with [Handlebars.js][handlebars-iterate] and friends. This is handy for navigation and other global content. Valid JSON files are included in the object if matched by your `gulp.src` glob.\n\nThe consolidated file is named **`content.json`** by default and optionally renamed.\n\n```javascript\nconst gulp = require('gulp');\nconst ListStream = require('list-stream');\nconst markdownToJSON = require('gulp-markdown-to-json');\nconst marked = require('marked');\n\ngulp.task('markdown', () =\u003e {\n  gulp.src('./content/**/*.md')\n    .pipe(ListStream.obj())\n    .pipe(markdownToJSON(marked, 'blog.json'))\n    .pipe(gulp.dest('.'))\n});\n```\n\n**`blog.json`**\n\n```json\n{\n  \"blog\": {\n    \"blog\": {\n      \"title\": \"ipsum dipsum\",\n      \"body\": \"\u003cp\u003eFrom west to \\\"east\\\"!\u003c/p\u003e\",\n      \"updatedAt\": \"1970-01-01T00:00:00Z\"\n    },\n    \"posts\": {\n      \"bushwick-artisan\": {\n        \"slug\": \"bushwick-artisan\",\n        \"title\": \"Wes Anderson pop-up Bushwick artisan\", \n        \"layout\": \"centered\",\n        \"body\": \"\u003ch2 id=\\\"yolo\\\"\u003eYOLO\u003c/h2\u003e\\n\u003cp\u003eChia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.\u003c/p\u003e\",\n        \"updatedAt\": \"1970-01-01T00:00:00Z\"\n      }\n    }\n  },\n  \"mission\": {\n    ...\n  }\n}\n```\n\nSpecify `flattenIndex: true` in the config object to unwrap home page/index-style content and merge it into the parent object. Name these files `index` or the same as a parent directory.\n\n```json\n{\n  \"blog\": {\n    \"title\": \"ipsum dipsum\",\n    \"body\": \"\u003cp\u003eFrom west to \\\"east\\\"!\u003c/p\u003e\",\n    \"updatedAt\": \"1970-01-01T00:00:00Z\",\n    \"posts\": {\n      ...\n    }\n  },\n  \"mission\": {\n    ...\n  }\n}\n```\n\nThis avoids redundant-feeling `blog.blog` scenarios when iterating and selecting from this content.\n\n### Title Extraction and Stripping\n\nDefine titles as `title` in the YAML frontmatter. Text of the first `\u003ch1\u003e` is assigned to `title` automatically if this is not specified.\n\nSpecify `stripTitle: true` in the config object to remove the first `\u003ch1\u003e` from the body. Use this if you are displaying the title outside of the body, in a page header for example.\n\n**`/blog/posts/bushwick-artisan.md`**\n\n```md\nWes Anderson pop-up Bushwick artisan\n====================================\n\n## YOLO\nChia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.\n```\n\n**`/blog/posts/bushwick-artisan.json`**\n\n```json\n{\n  \"title\": \"Wes Anderson pop-up Bushwick artisan\", \n  \"body\": \"\u003ch2 id=\\\"yolo\\\"\u003eYOLO\u003c/h2\u003e\\n\u003cp\u003eChia quinoa meh, you probably haven't heard of them sartorial Holowaychuk pickled post-ironic. Plaid ugh vegan, Sixpoint 8-bit sartorial artisan semiotics put a bird on it Mission bicycle rights Club-Mate vinyl.\u003c/p\u003e\",\n  \"updatedAt\": \"1970-01-01T00:00:00Z\"\n}\n```\n\n### Transforms\n\nTo change or add to the JSON data for each file, specify a transform function and return your desired object. This function is passed the default data and the [Vinyl file object][vinyl] for the source file.\n\nFor example:\n\n```js\ngulp.src('./content/**/*.md')\n  .pipe(ListStream.obj())\n  .pipe(markdownToJSON(marked, 'blog.json', (data, file) =\u003e {\n    delete data.body;\n    data.path = file.path;\n    return data;\n  }))\n  .pipe(gulp.dest('.'))\n```\n\nAPI\n---\n\n### `markdownToJSON((renderer: Function, name?: String, transform?: Function) | config: Object) =\u003e TransformStream`\n\n`config`\n\n- `renderer` `Function` accepts Markdown source string, returns an escaped HTML string. **Required**\n- `context` `Object` to use when calling `renderer`\n- `name` `String` to rename consolidated output file, if using. Default: `content.json`\n- `flattenIndex` `Boolean` unwrap files named `index` or after parent dirs in consolidated output. Default: `false`\n- `stripTitle` `Boolean` strips the first `\u003ch1\u003e` from body, if extracted as title. Default: `false`\n- `transform` `Function` to access and change the JSON data for each file before outputting\n\nContribute\n----------\n\nPull requests accepted!\n\nLicense\n-------\n\n**[MIT](LICENSE)**  \nCopyright \u0026copy; 2017 Sparkart Group, Inc.\n\n[circleci]: https://circleci.com/gh/sparkartgroup/gulp-markdown-to-json\n[circleci-badge]: https://circleci.com/gh/sparkartgroup/gulp-markdown-to-json.png?style=shield\u0026circle-token=8bf33da398b8ab296fe670c81b3fecbae1471e25\n\n[semistandard]: https://github.com/Flet/semistandard\n[semistandard-badge]: https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat\n\n[marked]: https://github.com/chjj/marked\n[markdown-js]: https://github.com/evilstreak/markdown-js\n[remarkable]: https://github.com/jonschlinkert/remarkable\n[markdown-it]: https://github.com/markdown-it/markdown-it\n[remark]: https://github.com/wooorm/remark\n[commonmark.js]: https://github.com/jgm/commonmark.js\n[front-matter]: https://github.com/jxson/front-matter\n\n[hb]: https://github.com/shannonmoeller/gulp-hb\n[request]: https://github.com/request/request\n[algolia]: https://www.algolia.com/\n[contentful]: https://www.contentful.com\n[plugin]: https://git.io/v6t5d\n\n[list-stream]: https://github.com/rvagg/list-stream\n[handlebars-iterate]: http://handlebarsjs.com/#iteration\n\n[vinyl]: https://github.com/gulpjs/vinyl\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsparkartgroup%2Fgulp-markdown-to-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsparkartgroup%2Fgulp-markdown-to-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsparkartgroup%2Fgulp-markdown-to-json/lists"}