{"id":19370031,"url":"https://github.com/bustle/mobiledoc-amp-renderer","last_synced_at":"2025-08-25T01:11:49.029Z","repository":{"id":57299526,"uuid":"49586068","full_name":"bustle/mobiledoc-amp-renderer","owner":"bustle","description":null,"archived":false,"fork":false,"pushed_at":"2016-11-16T19:41:48.000Z","size":22,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-02-07T13:57:52.589Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bustle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-13T16:26:03.000Z","updated_at":"2018-10-28T03:14:16.000Z","dependencies_parsed_at":"2022-08-26T18:22:02.006Z","dependency_job_id":null,"html_url":"https://github.com/bustle/mobiledoc-amp-renderer","commit_stats":null,"previous_names":["bustlelabs/mobiledoc-amp-renderer","bustlelabs/mobiledoc-amp-html-renderer"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bustle%2Fmobiledoc-amp-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bustle%2Fmobiledoc-amp-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bustle%2Fmobiledoc-amp-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bustle%2Fmobiledoc-amp-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bustle","download_url":"https://codeload.github.com/bustle/mobiledoc-amp-renderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240492135,"owners_count":19810038,"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":[],"created_at":"2024-11-10T08:14:02.464Z","updated_at":"2025-02-24T14:22:27.274Z","avatar_url":"https://github.com/bustle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Mobiledoc AMP Renderer [![Build Status](https://travis-ci.org/bustlelabs/mobiledoc-amp-renderer.svg?branch=master)](https://travis-ci.org/bustlelabs/mobiledoc-amp-renderer)\n\nThis is an Google AMP renderer for the [Mobiledoc format](https://github.com/bustlelabs/mobiledoc-kit/blob/master/MOBILEDOC.md) used\nby [Mobiledoc-Kit](https://github.com/bustlelabs/mobiledoc-kit).\n\nLearn about [Google AMP here on GitHub](https://github.com/ampproject/amphtml).\n\nTo learn more about Mobiledoc cards and renderers, see the **[Mobiledoc Cards docs](https://github.com/bustlelabs/mobiledoc-kit/blob/master/CARDS.md)**.\n\nThe renderer is a small library intended for use in servers that are building\nAMP documents.\n\n### Usage\n\n```\nvar mobiledoc = {\n  version: \"0.2.0\",\n  sections: [\n    [         // markers\n      ['B']\n    ],\n    [         // sections\n      [1, 'P', [ // array of markups\n        // markup\n        [\n          [0],          // open markers (by index)\n          0,            // close count\n          'hello world'\n        ]\n      ]\n    ]\n  ]\n};\nvar renderer = new MobiledocAMPRenderer({cards: []});\nvar rendered = renderer.render(mobiledoc);\nconsole.log(rendered.result.outerHTML); // \"\u003cp\u003e\u003cb\u003ehello world\u003c/b\u003e\u003c/p\u003e\"\n```\n\nThe Renderer constructor accepts a single object with the following optional properties:\n  * `cards` [array] - The list of card objects that the renderer may encounter in the mobiledoc\n  * `atoms` [array] - The list of atom objects that the renderer may encounter in the mobiledoc\n  * `cardOptions` [object] - Options to pass to cards and atoms when they are rendered\n  * `unknownCardHandler` [function] - Will be called when any unknown card is enountered\n  * `unknownAtomHandler` [function] - Will be called when any unknown atom is enountered\n  * `sectionElementRenderer` [object] - A map of hooks for section element rendering.\n    * Valid keys are P, H1, H2, H3, BLOCKQUOTE, PULL-QUOTE\n    * The hooks is passed the document\n    * A valid value is a function that returns an element\n\nThe return value from `renderer.render(mobiledoc)` is an object with two properties:\n  * `result` [object] - The rendered result, a DOM node\n  * `teardown` [function] - When called, this function will tear down the rendered mobiledoc and call any teardown handlers that were registered by cards when they were rendered\n\n#### sectionElementRenderer\n\nUse this renderer option to customize what element is used when rendering\na section.\n\n```\nvar renderer = new MobiledocAMPRenderer({\n  sectionElementRenderer: {\n    P: function(dom) { return dom.createElement('span'); },\n    H1: function(dom) { return dom.createElement('h2'); },\n    H2: function(dom) {\n      var element = dom.createElement('h2');\n      element.setAttribute('class', 'subheadline');\n      return element;\n    }\n    /* Valid keys are P, H1, H2, H3, BLOCKQUOTE, PULL-QUOTE */\n  }\n});\nvar rendered = renderer.render(mobiledoc);\n```\n\n### Tests\n\nCommand-line:\n\n * `npm test`\n\nOr in the browser:\n\n * `broccoli serve`\n * visit http://localhost:4200/tests\n\n### Releasing\n\n* `npm version patch` or `minor` or `major`\n* `npm run build`\n* `git push bustle --tags`\n* `npm publish`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbustle%2Fmobiledoc-amp-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbustle%2Fmobiledoc-amp-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbustle%2Fmobiledoc-amp-renderer/lists"}