{"id":19501234,"url":"https://github.com/gitbookio/brightml","last_synced_at":"2025-04-25T23:31:08.149Z","repository":{"id":73453365,"uuid":"48535433","full_name":"GitbookIO/brightml","owner":"GitbookIO","description":"Smart utility rendering markdown-ready HTML","archived":false,"fork":false,"pushed_at":"2016-01-26T11:45:22.000Z","size":23,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-14T00:22:46.665Z","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/GitbookIO.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":"2015-12-24T09:12:38.000Z","updated_at":"2021-11-09T04:40:31.000Z","dependencies_parsed_at":"2023-03-15T09:30:14.196Z","dependency_job_id":null,"html_url":"https://github.com/GitbookIO/brightml","commit_stats":{"total_commits":32,"total_committers":1,"mean_commits":32.0,"dds":0.0,"last_synced_commit":"fc47ecd1fed7710fc6a31798741a826cfcb2fe4c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitbookIO%2Fbrightml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitbookIO%2Fbrightml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitbookIO%2Fbrightml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitbookIO%2Fbrightml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GitbookIO","download_url":"https://codeload.github.com/GitbookIO/brightml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250912660,"owners_count":21506865,"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-10T22:11:59.156Z","updated_at":"2025-04-25T23:31:07.930Z","avatar_url":"https://github.com/GitbookIO.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Brightml\n\nSmart utility rendering markdown-ready HTML.\n\n## Install\n\n```Shell\n$ npm install brightml\n```\n\n## Use\n\nClean all HTML at once :\n\n```JavaScript\nvar brightml = require('brightml');\n\nvar HTMLString = '\u003ctable\u003e\u003ctr\u003e\u003ctd\u003eTitle 1\u003c/td\u003e\u003ctd\u003eTitle 2\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003eData 1\u003c/td\u003e\u003ctd\u003eData 2\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e';\n\nvar cleanHTML = brightml.clean(HTMLString);\n//  cleanHTML is :\n//  \u003ctable\u003e\n//    \u003cthead\u003e\n//      \u003ctr\u003e\n//        \u003cth\u003eTitle 1\u003c/th\u003e\n//        \u003cth\u003eTitle 2\u003c/th\u003e\n//      \u003c/tr\u003e\n//    \u003c/thead\u003e\n//    \u003ctbody\u003e\n//      \u003ctr\u003e\n//        \u003ctd\u003eData 1\u003c/td\u003e\n//        \u003ctd\u003eData 2\u003c/td\u003e\n//      \u003c/tr\u003e\n//    \u003c/tbody\u003e\n//  \u003c/table\u003e\n```\n\nOr use the module's functions as required :\n\n```JavaScript\nvar brightml = require('brightml');\n\nvar HTMLString = '\u003ctable\u003e\u003ctr\u003e\u003ctd\u003eTitle 1\u003c/td\u003e\u003ctd\u003eTitle 2\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003eData 1\u003c/td\u003e\u003ctd\u003eData 2\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e';\n\nbrightml.parse(HTMLString);\nbrightml.formatTables();\nvar cleanHTML = brightml.render();\n//  cleanHTML is :\n//  \u003ctable\u003e\n//    \u003cthead\u003e\n//      \u003ctr\u003e\n//        \u003cth\u003eTitle 1\u003c/th\u003e\n//        \u003cth\u003eTitle 2\u003c/th\u003e\n//      \u003c/tr\u003e\n//    \u003c/thead\u003e\n//    \u003ctbody\u003e\n//      \u003ctr\u003e\n//        \u003ctd\u003eData 1\u003c/td\u003e\n//        \u003ctd\u003eData 2\u003c/td\u003e\n//      \u003c/tr\u003e\n//    \u003c/tbody\u003e\n//  \u003c/table\u003e\n```\n\n## What it does\n\nUsing `brightml.clean(html)` performs the following operations in order.\n\n#### brightml.parse(HTMLString)\n\nConvert HTML to DOM using [cheerio](https://github.com/cheeriojs/cheerio).\n\n#### brightml.retrieveFootNotes()\n\nFor cross-referenced links, handle retrieving the foot/endnotes before the next `\u003ch1\u003e` tag to keep notes within a chapter section.\n\nThe footnotes are then formatted as follow:\n\n```HTML\n\u003ch1\u003eFootnotes\u003c/h1\u003e\n\u003cp\u003e\n  See how to properly format a footnote\u003csup id=\"footnote-ref\"\u003e\u003ca href=\"#footnote\"\u003e1\u003c/a\u003e\u003c/sup\u003e.\n\u003c/p\u003e\n\u003c!-- Some more content --\u003e\n\u003cp\u003e\n  \u003csup id=\"footnote\"\u003e\n    Footnotes are in a paragraph and a sup tag. Link to go back to reference is at the end of the footnote.\n    \u003ca href=\"#footnote-ref\"\u003e\u003c/a\u003e\n  \u003c/sup\u003e\n\u003c/p\u003e\n```\n\n#### brightml.setAnchorsId()\n\nTry to set `\u003ca\u003e` tags `id` attribute on their direct parent if possible.\n\n#### brightml.cleanElements()\n\n* Remove empty tags.\n* Remove forbidden HTML tags and place their HTML content in a `\u003cp\u003e` instead.\n* Remove forbidden HTML attributes.\n* Remove unallowed links schema in HTML attributes.\n\nThis operation uses the `rules.js` file to determine which tags/attributes/schemes are allowed.\n\n#### brightml.cleanImagesInTitles()\n\nMove `\u003cimg\u003e` tags in titles right after the concerned `\u003ch\u003e` tag.\n\n#### brightml.normalizeTitlesId()\n\nSet an `id` attribute on each `\u003ch\u003e` tag. The `id` is based on the title tag content.\n\nEach reference to this `id` will be modified in consequence.\n\n```HTML\n\u003ch1 id=\"some-id\"\u003eA great title\u003c/h1\u003e\n\u003ca href=\"#some-id\"\u003eBack to a great title\u003c/a\u003e\n```\nwill become:\n```HTML\n\u003ch1 id=\"a_great_title\"\u003eA great title\u003c/h1\u003e\n\u003ca href=\"#a_great_title\"\u003eBack to a great title\u003c/a\u003e\n```\n\n#### brightml.removeNestedTables()\n\nReplace nested `\u003ctable\u003e` tags by a warning message followed by their content in a simple `\u003ctd\u003e` tag.\n\n#### brightml.formatTables()\n\nEnsure every `\u003ctable\u003e` elements look the same.\n\nUsed schema :\n\n```HTML\n\u003c!-- Move caption before \u003ctable\u003e if any --\u003e\n\u003ccaption\u003e\u003c/caption\u003e\n\n\u003ctable\u003e\n  \u003c!-- Ensure the first row contains \u003cth\u003e tags in a \u003cthead\u003e element --\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eTitle 1\u003c/th\u003e\n      \u003cth\u003eTitle 2\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003c!-- Ensure all remaining rows are inside a \u003ctbody\u003e element --\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eRow 1 - Data 1\u003c/td\u003e\n      \u003ctd\u003eRow 1 - Data 2\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eRow 2 - Data 1\u003c/td\u003e\n      \u003ctd\u003eRow 2 - Data 2\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n```\n\n#### brightml.cleanTableCells()\n\nEnsure every `\u003cth\u003e` and `\u003ctd\u003e` tags don't contain a `\u003cp\u003e` tag to prevent line breaking.\n\n#### brightml.render()\n\nReturns the current state of `HTMLString` passed to `brightml.parse(HTMLString)`.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitbookio%2Fbrightml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgitbookio%2Fbrightml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitbookio%2Fbrightml/lists"}