{"id":15017739,"url":"https://github.com/chlodalejandro/parsoid-document","last_synced_at":"2026-01-04T08:34:11.426Z","repository":{"id":45766951,"uuid":"453245094","full_name":"ChlodAlejandro/parsoid-document","owner":"ChlodAlejandro","description":"A userscript library for easily handling Parsoid DOM trees.","archived":false,"fork":false,"pushed_at":"2024-03-30T00:52:24.000Z","size":759,"stargazers_count":0,"open_issues_count":7,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-18T09:04:25.727Z","etag":null,"topics":["javascript","mediawiki","parsoid","wiki","wikimedia"],"latest_commit_sha":null,"homepage":"https://chlodalejandro.github.io/parsoid-document/","language":"TypeScript","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/ChlodAlejandro.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-01-28T23:19:02.000Z","updated_at":"2022-07-20T10:39:01.000Z","dependencies_parsed_at":"2023-02-16T03:31:27.169Z","dependency_job_id":"67a8f66f-8472-4a7b-a680-955e3c424afe","html_url":"https://github.com/ChlodAlejandro/parsoid-document","commit_stats":{"total_commits":107,"total_committers":2,"mean_commits":53.5,"dds":0.3551401869158879,"last_synced_commit":"9c0c04f5084d3d24b9762b3dd4e73e75d030499a"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChlodAlejandro%2Fparsoid-document","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChlodAlejandro%2Fparsoid-document/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChlodAlejandro%2Fparsoid-document/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChlodAlejandro%2Fparsoid-document/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChlodAlejandro","download_url":"https://codeload.github.com/ChlodAlejandro/parsoid-document/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245020314,"owners_count":20548156,"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":["javascript","mediawiki","parsoid","wiki","wikimedia"],"created_at":"2024-09-24T19:50:55.495Z","updated_at":"2026-01-04T08:34:11.383Z","avatar_url":"https://github.com/ChlodAlejandro.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ParsoidDocument\n[![npm version](https://img.shields.io/npm/v/@chlodalejandro/parsoid.svg?style=flat-square)](https://www.npmjs.org/package/@chlodalejandro/parsoid)\n[![npm downloads](https://img.shields.io/npm/dm/@chlodalejandro/parsoid.svg?style=flat-square)](http://npm-stat.com/charts.html?package=@chlodalejandro/parsoid)\n\n*Originally from [User:Chlod/Scripts/ParsoidDocument](https://en.wikipedia.org/wiki/User:Chlod/Scripts/ParsoidDocument) on the English Wikipedia.*\n\nParsoidDocument is an ES9+ library which implements a Parsoid-compatible document handler using an HTML5 IFrame. It is not a userscript, but is instead loaded by other userscripts. The IFrame contains the Parsoid document, which can then be modified using standard DOM functions. This is used to perform Parsoid-dependent operations in the browser without having to pull in the entirety of the VisualEditor codebase. The library works even without the existence of MediaWiki `notification` and `Title` modules, although they are helpful in ensuring data stability.\n\nTo be fully optimized, this should be implemented as a gadget and loaded through [mw.loader](https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.loader). Note that some APIs used by this library may not be available on older browsers.\n\n## Installation\nAs a developer, insert the following code in the initialization section of your userscript. **This is the only way to use the library on the English Wikipedia, and for most Wikimedia wikis.**\n```js\n// The \"await\" is optional, but ensures that the script has loaded and run before proceeding.\n// On the English Wikipedia\nawait mw.loader.getScript(\"https://en.wikipedia.org/wiki/User:Chlod/Scripts/ParsoidDocument.js?action=raw\u0026ctype=text/javascript\");\n\n// On other wikis, you must upload ParsoidDocument.js from the English Wikipedia or this repository\n// first, and then change the URL to lead to the correct page. Make sure to keep the\n// `?action=raw\u0026ctype=text/javascript` at the end of the URL!\n```\n\nIf it is available as a gadget, you can instead use the following.\n```js\nmw.loader.load(\"ext.gadget.ParsoidDocument\"); // where ParsoidDocument is the ID of the gadget.\n```\n\nIf your userscript is bundled with Webpack, you can also install the [@chlodalejandro/parsoid](https://npmjs.com/package/@chlodalejandro/parsoid) package. This package also adds typings for ParsoidDocument, in case you're developing with TypeScript or a decent IDE with a type checker.\n```shell\nnpm install @chlodalejandro/parsoid\n```\n\n## Usage\nYou can then access ParsoidDocument using the `ParsoidDocument` window global.\n\n```js\nconst parsoid = new ParsoidDocument();\n\nparsoid.loadPage(\"User:Chlod/Scripts/ParsoidDocument\");\nparsoid.document.body.classList.contains(\"parsoid-body\"); // true\n\n// Prints the \"data-mw\" attribute of all transclusions.\nparsoid.document.querySelectorAll(\"[typeof=\\\"mw:Transclusion\\\"]\").forEach(v =\u003e {\n    console.log(v.getAttribute(\"data-mw\"));\n});\n\n// Convert the document, including any modification, to wikitext.\nparsoid.toWikitext();\n```\n\nYou can also extend the ParsoidDocument class as any other class.\n```js\nclass MyParsoidHandler extends ParsoidDocument {\n\n    findAllTransclusions() {\n        return this.document.querySelectorAll(\"[typeof=\\\"mw:Transclusion\\\"]\");\n    }\n\n}\n\nconst parsoid = new MyParsoidHandler();\n// ...\nparsoid.findAllTransclusions();\n```\n## See also\n* [types-mediawiki](https://github.com/wikimedia-gadgets/types-mediawiki) – provides types for the MediaWiki global (`mw`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchlodalejandro%2Fparsoid-document","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchlodalejandro%2Fparsoid-document","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchlodalejandro%2Fparsoid-document/lists"}