{"id":15644810,"url":"https://github.com/egoist/docute-iframe","last_synced_at":"2025-06-15T01:33:19.064Z","repository":{"id":45275505,"uuid":"84450859","full_name":"egoist/docute-iframe","owner":"egoist","description":"A docute plugin to run code in docs with an iframe.","archived":false,"fork":false,"pushed_at":"2021-12-25T13:53:51.000Z","size":38,"stargazers_count":15,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T19:20:12.528Z","etag":null,"topics":["docute"],"latest_commit_sha":null,"homepage":"https://docute.js.org","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/egoist.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":"2017-03-09T14:25:42.000Z","updated_at":"2023-09-08T17:22:01.000Z","dependencies_parsed_at":"2022-09-26T16:21:32.861Z","dependency_job_id":null,"html_url":"https://github.com/egoist/docute-iframe","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fdocute-iframe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fdocute-iframe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fdocute-iframe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Fdocute-iframe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egoist","download_url":"https://codeload.github.com/egoist/docute-iframe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251438911,"owners_count":21589540,"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":["docute"],"created_at":"2024-10-03T12:02:31.426Z","updated_at":"2025-04-30T10:14:52.909Z","avatar_url":"https://github.com/egoist.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# docute-iframe\n\n[![NPM version](https://img.shields.io/npm/v/docute-iframe.svg?style=flat)](https://npmjs.com/package/docute-iframe) [![NPM downloads](https://img.shields.io/npm/dm/docute-iframe.svg?style=flat)](https://npmjs.com/package/docute-iframe) [![Build Status](https://img.shields.io/circleci/project/egoist/docute-iframe/master.svg?style=flat)](https://circleci.com/gh/egoist/docute-iframe) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000\u0026style=flat)](https://github.com/egoist/donate)\n\nA docute plugin to run code in docs with an iframe.\n\n## Usage\n\n*This plugin requires docute^2.9.0*\n\nInclude the scripts before running `docute.init`:\n\n```html\n\u003cscript src=\"https://unpkg.com/docute-iframe\"\u003e\u003c/script\u003e\n```\n\nThen activate the plugin:\n\n```js\ndocute.init({\n  plugins: [\n    docuteIframe()\n  ]\n})\n```\n\nFinally, you can write some fancy code examples which are `runnable`:\n\n    This is a **markdown** file, here it to demonstrate some code:\n\n    ````html\n    \u003cdiv id=\"example\"\u003e\u003c/div\u003e\n    \u003cscript\u003e\n      document.getElementById('example').innerHTML = '\u003cstrong\u003eit works\u003c/strong\u003e'\n    \u003c/script\u003e\n    ````\n\n**Note:** It's similar to gfm code blocks, which use triple backticks, but here you need to use **4 backticks** to mark it as runnable code while still have syntax highlight in your editor.\n\nIf the `language` of code block is `js` or `javascript`, it will be automatically wrapped in `\u003cscript\u003e` tag and inserted into iframe body, you can [customize it](#parsecontent) though.\n\n## API\n\n### docuteIframe([options])\n\n#### options\n\n##### match\n\nType: `RegExp`\u003cbr\u003e\nDefault: \u003ccode\u003e/^\\`{4}(.\\*?)[\\n\\r]+([\\s\\S]\\*?)[\\n\\r]+\\`{4}/gm\u003c/code\u003e\n\nThe regular expression we use to find runnable code.\n\n##### showSourceCode\n\nType: `boolean`\u003cbr\u003e\nDefault: `true`\n\nShow highlighted source code before iframe.\n\n##### prepend\n\nType: `string`\n\nPrepend string to iframe body, eg:\n\n```js\ndocuteIframe({\n  prepend: '\u003cscript src=\"https://unpkg.com/vue@2.2.2/dist/vue.min.js\"\u003e\u003c/script\u003e'\n})\n```\n\nThen you can use `Vue` in your code.\n\n##### append\n\nSame as `prepend` but append to iframe body.\n\n##### sandbox\n\nType: `string`\u003cbr\u003e\nDefault: `allow-modals allow-forms allow-pointer-lock allow-popups allow-same-origin allow-scripts`\n\nThe `sandbox` attribute of `iframe` element.\n\n##### surfaceAPI\n\nType: `Array`\u003cbr\u003e\nDefault: `['Prism', 'fetch']`\n\nDeliver some global variables of parent window to iframe, don't deliver variables that rely on `window.document`, since the parent window and iframe have different `document.`\n\n##### parseContent\n\nType: `function`\u003cbr\u003e\nDefault:\n\n```js\nfunction defaultParseContent(lang, content) {\n  if (lang === 'js' || lang === 'javascript') {\n    return `\u003cscript\u003e${content}\u003c/script\u003e`\n  }\n  return content\n}\n```\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n\n## Author\n\n**docute-iframe** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.\u003cbr\u003e\nAuthored and maintained by egoist with help from contributors ([list](https://github.com/egoist/docute-iframe/contributors)).\n\n\u003e [egoistian.com](https://egoistian.com) · GitHub [@egoist](https://github.com/egoist) · Twitter [@rem_rin_rin](https://twitter.com/rem_rin_rin)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fdocute-iframe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegoist%2Fdocute-iframe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Fdocute-iframe/lists"}