{"id":21541497,"url":"https://github.com/reshape/content","last_synced_at":"2025-07-21T23:34:33.553Z","repository":{"id":57354560,"uuid":"65311509","full_name":"reshape/content","owner":"reshape","description":"plugin that transforms specified content with a custom function","archived":false,"fork":false,"pushed_at":"2019-02-05T12:43:20.000Z","size":643,"stargazers_count":4,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-24T16:56:26.279Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reshape.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-09T16:40:15.000Z","updated_at":"2018-07-26T17:26:53.000Z","dependencies_parsed_at":"2022-09-12T04:10:47.968Z","dependency_job_id":null,"html_url":"https://github.com/reshape/content","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/reshape/content","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshape%2Fcontent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshape%2Fcontent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshape%2Fcontent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshape%2Fcontent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reshape","download_url":"https://codeload.github.com/reshape/content/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reshape%2Fcontent/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266403151,"owners_count":23923404,"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","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-24T05:04:54.922Z","updated_at":"2025-07-21T23:34:33.509Z","avatar_url":"https://github.com/reshape.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Reshape Content\n\n[![npm](https://img.shields.io/npm/v/reshape-content.svg?style=flat-square)](https://npmjs.com/package/reshape-content)\n[![tests](https://img.shields.io/travis/reshape/content.svg?style=flat-square)](https://travis-ci.org/reshape/content?branch=master)\n[![dependencies](https://img.shields.io/david/reshape/content.svg?style=flat-square)](https://david-dm.org/reshape/content)\n[![coverage](https://img.shields.io/coveralls/reshape/content.svg?style=flat-square)](https://coveralls.io/r/reshape/content?branch=master)\n\nFlexible content transform for reshape\n\n\u003e **Note:** This project is in early development, and versioning is a little different. [Read this](http://markup.im/#q4_cRZ1Q) for more details.\n\n## Why Should You Care?\n\nRather than having a separate plugin for each kind of content transform you want to be able to do, why not just have one? Parse natural language, markdown, or whatever else you want with a minimalistic and simple interface 🍻\n\n## Install\n\n```bash\nnpm i reshape-content --save\n```\n\n\u003e **Note:** This project is compatible with node v6+ only\n\n## Usage\n\nStart with some html you want to transform in some way. Add attributes of your choosing to an element that has contents you want to transform, and they will be transformed in that order.\n\n```html\n\u003cp windoge\u003ePlease use windows 98\u003c/p\u003e\n```\n\nNow pass in an object to `reshape-content`. Each key in the object represents an attribute that will be searched for in the html. The value is a function that will get that element's contents as a string, and replace the contents with whatever string is returned from the function.\n\n```js\nconst content = require('reshape-content')({\n  windoge: (str) =\u003e str.replace(/windows/g, 'winDOGE')\n})\n\nreshape({ plugins: content })\n  .process(html)\n  .then((res) =\u003e res.output())\n```\n\nThe plugin will remove the custom attributes from the element and replace its contents with your transformed version. Wow!\n\n```html\n\u003cp\u003ePlease use winDOGE 98\u003c/p\u003e\n```\n\nIf you return an [A+ compliant promise](https://promisesaplus.com/) from your content function, it will resolve and work in your templates as well.\n\nYou can use external libraries for this as well, no problem. Just make sure you are passing in a function that takes a string and returns a string. You might have to wrap the library function if it doesn't behave like this, but it will work with anything that transforms content.\n\n## Examples\n\n#### Markdown\n\n```html\n\u003cp md\u003eWow, it's **Markdown**!\u003c/p\u003e\n```\n\n```js\nconst markdown = require('markdown-it')(/* options */)\nconst content = require('reshape-content')({\n  md: (md) =\u003e markdown.render(md)\n})\n\nreshape({ plugins: content })\n  .process(html)\n  .then((res) =\u003e res.output())\n```\n\n```html\n\u003cp\u003eWow, it's \u003cstrong\u003eMarkdown\u003c/strong\u003e!\u003c/p\u003e\n```\n\n#### PostCSS\n\n```sugarss\n\u003cstyle postcss\u003e\n  .test\n    text-transform: uppercase;\n\n    \u0026__hello\n      color: red;\n\n    \u0026__world\n      color: blue;\n\u003c/style\u003e\n```\n\n```js\nconst postcss = require('postcss')([ require('postcss-nested')() ])\nconst options = { parser: require('sugarss'), map: false }\n\nconst content = require('reshape-content')({\n  postcss: (css) =\u003e postcss.process(css, options).css\n})\n\nreshape({ plugins: content })\n  .process(html)\n  .then((res) =\u003e res.output())\n\n```\n\n```html\n\u003cstyle\u003e\n  .test {\n    text-transform: uppercase;\n  }\n\n  .test__hello {\n    color: red;\n  }\n\n  .test__world {\n    color: blue;\n  }\n\u003c/style\u003e\n```\n\n#### Babel\n\n```html\n\u003cscript babel\u003e\n  const hello = 'Hello World!'\n  let greeter = {\n    greet (msg) { alert (msg) }\n  }\n  greeter.greet(hello)\n\u003c/script\u003e\n```\n\n```js\nconst babel = require('babel-core')\nconst options = { presets: [\"es2015\"], sourceMaps: false }\n\nconst content = require('reshape-content')({\n  babel: (js) =\u003e babel.transform(js, options).code\n})\n\nreshape({ plugins: content })\n  .process(html)\n  .then((res) =\u003e res.output())\n```\n\n```html\n\u003cscript\u003e\n  'use strict';\n  var hello = \"Hello World!\";\n  var greeter = {\n    greet: function greet (msg) {\n      alert(msg);\n    };\n  };\n  greeter.greet(hello);\n\u003c/script\u003e\n```\n\n#### Return a Promise\n\n```sugarss\n\u003cstyle postcss\u003e\n  .test\n    text-transform: uppercase;\n\n    \u0026__hello\n      color: red;\n\n    \u0026__world\n      color: blue;\n\u003c/style\u003e\n```\n\n```js\nconst postcss = require('postcss')([ require('postcss-nested')() ])\nconst options = { parser: require('sugarss'), map: false }\n\nconst content = require('reshape-content')({\n  postcss: (css) =\u003e {\n    return postcss.process(css, options).then((res) =\u003e res.css)\n  }\n})\n\nreshape({ plugins: content })\n  .process(html)\n  .then((res) =\u003e res.output())\n```\n\n## License \u0026 Contributing\n\n- Licensed under [MIT](LICENSE.md)\n- Details on running tests and contributing [can be found here](contributing.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freshape%2Fcontent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freshape%2Fcontent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freshape%2Fcontent/lists"}