{"id":13623558,"url":"https://github.com/bevacqua/domador","last_synced_at":"2025-03-17T04:31:48.095Z","repository":{"id":28272471,"uuid":"31782908","full_name":"bevacqua/domador","owner":"bevacqua","description":":smirk_cat: Dependency-free and lean DOM parser that outputs Markdown","archived":false,"fork":false,"pushed_at":"2022-06-28T17:31:02.000Z","size":181,"stargazers_count":83,"open_issues_count":4,"forks_count":8,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-04-25T18:03:11.612Z","etag":null,"topics":["html-to-markdown","markdown"],"latest_commit_sha":null,"homepage":"https://ponyfoo.com","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/bevacqua.png","metadata":{"files":{"readme":"readme.markdown","changelog":"changelog.markdown","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":"2015-03-06T18:28:30.000Z","updated_at":"2023-04-17T18:27:00.000Z","dependencies_parsed_at":"2022-08-27T04:11:19.693Z","dependency_job_id":null,"html_url":"https://github.com/bevacqua/domador","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bevacqua%2Fdomador","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bevacqua%2Fdomador/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bevacqua%2Fdomador/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bevacqua%2Fdomador/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bevacqua","download_url":"https://codeload.github.com/bevacqua/domador/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841223,"owners_count":20356446,"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":["html-to-markdown","markdown"],"created_at":"2024-08-01T21:01:33.108Z","updated_at":"2025-03-17T04:31:47.798Z","avatar_url":"https://github.com/bevacqua.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Domador\n\n[![Build Status](https://travis-ci.org/bevacqua/domador.svg?branch=master)](https://travis-ci.org/bevacqua/domador)\n\n\u003e Dependency-free and lean DOM parser that outputs Markdown\n\nYou can use it on the server-side as well, thanks to [jsdom][1]. The client-side version leverages the browser DOM. Originally based on [html-md][3].\n\n# Install\n\nYou can get it on npm.\n\n```shell\nnpm install domador --save\n```\n\nOr bower, too.\n\n```shell\nbower install domador --save\n```\n\n# `domador(input, options?)`\n\nConverts DOM tree _(or HTML string)_ `input` into Markdown. `domador` takes the following options.\n\n##### `absolute`\n\nConvert relative links into absolute ones automatically.\n\n##### `href`\n\nThe document's `href`, necessary for the `absolute` option to work properly outside of a browser environment.\n\n##### `inline`\n\nLinks _(`[foo](/bar)`)_ and image sources _(`![foo](/bar)`)_ are inlined. By default, they are added as footnote references `[foo][1]\\n\\n[1]: /bar`.\n\n##### `fencing`\n\nThe western art of combat with [rapiers][2] or rapier-like swords. It can also be set to `true` to use fences like instead of spaces when delimiting code blocks.\n\n##### `fencinglanguage`\n\nIf `fencing` is enabled, `fencinglanguage` can be a `function` that will run on every `\u003cpre\u003e` element and returns the appropriate language in the fence. If the `\u003cpre\u003e` element contains a `\u003ccode\u003e` element as its first child, `fencinglanguage` will be executed for that element as well in search of a match.\n\nIf nothing is returned, a language won't be assigned to the fence. The example below returns fence languages according to a `md-lang-{language}` class found on the `pre` element.\n\n```js\nfunction fencinglanguage (el) {\n  var match = el.className.match(/md-lang-((?:[^\\s]|$)+)/);\n  if (match) {\n    return match.pop();\n  }\n}\n```\n\n##### `allowFrame`\n\nWhen set to a function, `allowFrame` receives the `src` attribute for an `\u003ciframe\u003e` and `domador` expects a boolean in return. If the return value is `true` then the `\u003ciframe\u003e` will be added to the Markdown output.\n\n```js\ndomador(el, {\n  allowFrame: function (src) {\n    return src.indexOf('https://google.com/') === 0;\n  }\n});\n```\n\n##### `tables`\n\nDomador understands well-formed HTML `\u003ctable\u003e` structures and spits out GitHub flavored Markdown tables. This functionality is enabled by default but you can turn it off by setting `tables` to `false`.\n\n##### `transform`\n\nAllows you to take over the default transformation for any given DOM element. Ignore elements you don't want to override, and return Markdown for the ones you want to change. This method is executed on every single DOM element that's parsed by `domador`. The example below converts links that start with `@` into mentions like `@bevacqua` instead of traditional Markdown links like `[@bevacqua](/users/bevacqua)`. This is particularly useful to transform Markdown-generated HTML back into the original Markdown when your Markdown parser has special tokenizers or hooks.\n\n```js\ndomador(el, {\n  transform: function (el) {\n    if (el.tagName === 'A' \u0026\u0026 el.innerHTML[0] === '@') {\n      return el.innerHTML;\n    }\n  }\n});\n```\n\n##### `markers`\n\n*Advanced option.* Setting markers to an array such as `[[0, 'START'], [10, 'END']]` will place each of those markers in the output, based on the input index you want to track. This feature is necessary because there is no other reliable way of tracking a text cursor position before and after a piece of HTML is converted to Markdown.\n\nThe following example shows how `markers` could be used to preserve a text selection across HTML-into-Markdown parsing, by providing `markers` for each cursor. When the output from `domador` comes back, all you need to do is find your markers, remove them, and place the text selection at their indices. The [`woofmark`][4] _Markdown/HTML/WYSIWYG_ editor module leverages this functionality to do exactly that.\n\n```js\ndomador('\u003cstrong\u003efoo\u003c/strong\u003e', {\n  markers: [[5, '[START]'], [10, '[END]']]\n});\n// \u003c- '**[START]fo[END]o**'\n```\n\n\u003csub\u003eAlso note that, as shown in the example above, when a marker can't be placed in the output exactly where you asked for, it'll be cleanly placed nearby. In the above example, the `[START]` marker would've been placed _\"somewhere inside\"_ the opening `**` tag, but right after the opening tag finishes was preferred.\u003c/sub\u003e\n\n# Tests\n\nRead the unit tests for examples of expected output and their inputs. Run unit tests using the command below.\n\n```shell\nnpm test\n```\n\n#### Disclaimer\n\nDon't expect this to work for arbitrary HTML, it is intended to restore HTML compiled from a Markdown source back into Markdown.\n\n# License\n\nMIT\n\n[1]: https://github.com/tmpvar/jsdom\n[2]: http://en.wikipedia.org/wiki/Rapier\n[3]: https://github.com/neocotic/html.md\n[4]: https://github.com/bevacqua/woofmark\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbevacqua%2Fdomador","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbevacqua%2Fdomador","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbevacqua%2Fdomador/lists"}