{"id":19258502,"url":"https://github.com/breakdance/breakdance-util","last_synced_at":"2025-04-21T15:31:34.763Z","repository":{"id":143869754,"uuid":"80965081","full_name":"breakdance/breakdance-util","owner":"breakdance","description":"Utility functions for breakdance plugins.","archived":false,"fork":false,"pushed_at":"2017-02-15T19:05:50.000Z","size":21,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T13:17:16.174Z","etag":null,"topics":["breakdance","javascript","plugins","utilities"],"latest_commit_sha":null,"homepage":null,"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/breakdance.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-05T03:06:06.000Z","updated_at":"2021-02-19T17:01:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"dcc22de3-86c7-42cc-b5d2-ee5efa653fff","html_url":"https://github.com/breakdance/breakdance-util","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/breakdance%2Fbreakdance-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/breakdance%2Fbreakdance-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/breakdance%2Fbreakdance-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/breakdance%2Fbreakdance-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/breakdance","download_url":"https://codeload.github.com/breakdance/breakdance-util/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250080669,"owners_count":21371547,"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":["breakdance","javascript","plugins","utilities"],"created_at":"2024-11-09T19:13:34.455Z","updated_at":"2025-04-21T15:31:34.533Z","avatar_url":"https://github.com/breakdance.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# breakdance-util [![NPM version](https://img.shields.io/npm/v/breakdance-util.svg?style=flat)](https://www.npmjs.com/package/breakdance-util) [![NPM monthly downloads](https://img.shields.io/npm/dm/breakdance-util.svg?style=flat)](https://npmjs.org/package/breakdance-util)  [![NPM total downloads](https://img.shields.io/npm/dt/breakdance-util.svg?style=flat)](https://npmjs.org/package/breakdance-util) [![Linux Build Status](https://img.shields.io/travis/breakdance/breakdance-util.svg?style=flat\u0026label=Travis)](https://travis-ci.org/breakdance/breakdance-util)\n\n\u003e Utility functions for breakdance plugins.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save breakdance-util\n```\n\n## Usage\n\n```js\nvar utils = require('breakdance-util');\n```\n\nVisit the [breakdance documentation](http://breakdance.io) for more information about using and customizing breakdance.\n\n## API\n\n### [.block](index.js#L36)\n\nWrapper for creating the handlers for compiling a tag that has `*.open` and `*.close` nodes, in a single function call.\n\n**Params**\n\n* `open` **{String}**: The opening tag to render\n* `close` **{String}**: The closing tag to render\n* `state` **{Object}**\n* `handler` **{Function}**: Visitor function to modify the node\n* `returns` **{undefined}**\n\n**Example**\n\n```js\nbreakdance.set('div', utils.block('', ''));\nbreakdance.set('address', block('\\n\u003caddress\u003e\\n', '\\n\u003c/address\u003e\\n'));\n// optionally pass a handler function to access the \"parent\" node\nbreakdance.set('abbr', block('\u003cabbr\u003e', '\u003c/abbr\u003e', function(node) {\n  var attr = utils.toAttribs(node.attribs, ['title']);\n  if (attr) {\n    node.open = '\u003cabbr' + attr + '\u003e';\n  }\n}))\n```\n\n### [.toAttribs](index.js#L89)\n\nStringify the `attribs` for a node.\n\n**Params**\n\n* `attribs` **{Object}**: Object of attributes to stringify\n* `names` **{Array}**: Array of `names` to only stringify attributes with those names.\n* `returns` **{String}**: Returns a string of attributes, e.g. `src=\"foo.jpg\"`\n\n**Example**\n\n```js\nvar str = utils.toAttribs(node.attribs);\n```\n\n### [.getLang](index.js#L125)\n\nAttempt to get a \"language\" value from the given `attribs`. Used with code/pre tags.\n\n**Params**\n\n* `attribs` **{Object}**: The `node.attribs` object\n* `returns` **{String}**\n\n**Example**\n\n```js\nbreakdance.set('code', function(node) {\n  var lang = utils.getLang(node.attribs);\n  // console.log(lang);\n});\n```\n\n### [.formatLink](index.js#L226)\n\nFormats the link part of a \"src\" or \"href\" attribute on the given `node`.\n\n**Params**\n\n* `node` **{Object}**\n* `key` **{String}**: Either `'src'` or `'href'`\n* `compiler` **{Object}**: Pass the breakdance compiler instance, for state and options.\n* `returns` **{String}**\n\n**Example**\n\n```js\n// this is how \u003cimg\u003e tags are rendered\nbreakdance.set('img', function(node) {\n  var attribs = node.attribs || {};\n  if (attribs.src) {\n    this.emit('![' + (attribs.alt || '').trim());\n    this.mapVisit(node);\n    var src = utils.formatLink(node, 'src', this);\n    this.emit(']' + src);\n    //=\u003e ![foo](bar.jpg)\n  }\n})\n```\n\n## About\n\n### Related projects\n\n* [breakdance-checklist](https://www.npmjs.com/package/breakdance-checklist): Plugin that adds checklist rendering support to breakdance, similar to task lists in github-flavored-markdown. | [homepage](https://github.com/jonschlinkert/breakdance-checklist \"Plugin that adds checklist rendering support to breakdance, similar to task lists in github-flavored-markdown.\")\n* [breakdance](https://www.npmjs.com/package/breakdance): Breakdance is a node.js library for converting HTML to markdown. Highly pluggable, flexible and easy… [more](http://breakdance.io) | [homepage](http://breakdance.io \"Breakdance is a node.js library for converting HTML to markdown. Highly pluggable, flexible and easy to use. It's time for your markup to get down.\")\n* [generate-breakdance](https://www.npmjs.com/package/generate-breakdance): Generate a new breakdance plugin project. | [homepage](https://github.com/generate/generate-breakdance \"Generate a new breakdance plugin project.\")\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\nPlease read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.\n\n### Building docs\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n### Running tests\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n### Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).\nMIT\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 05, 2017._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbreakdance%2Fbreakdance-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbreakdance%2Fbreakdance-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbreakdance%2Fbreakdance-util/lists"}