{"id":16687333,"url":"https://github.com/erdomke/bracketpipe","last_synced_at":"2025-03-21T18:33:21.351Z","repository":{"id":55374835,"uuid":"74083537","full_name":"erdomke/BracketPipe","owner":"erdomke","description":"BracketPipe is a .NET library for building parsing and processing piplines for web languages like HTML, CSS, Javscript, SVG, and MathML","archived":false,"fork":false,"pushed_at":"2022-07-25T16:58:33.000Z","size":485,"stargazers_count":22,"open_issues_count":5,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T03:51:30.261Z","etag":null,"topics":["html-markdown","html-minifier","html-parser","html-sanitization"],"latest_commit_sha":null,"homepage":"","language":"C#","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/erdomke.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":"2016-11-18T01:35:16.000Z","updated_at":"2024-09-18T21:49:05.000Z","dependencies_parsed_at":"2022-08-14T22:50:32.289Z","dependency_job_id":null,"html_url":"https://github.com/erdomke/BracketPipe","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erdomke%2FBracketPipe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erdomke%2FBracketPipe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erdomke%2FBracketPipe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erdomke%2FBracketPipe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erdomke","download_url":"https://codeload.github.com/erdomke/BracketPipe/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244849499,"owners_count":20520730,"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-markdown","html-minifier","html-parser","html-sanitization"],"created_at":"2024-10-12T15:08:48.439Z","updated_at":"2025-03-21T18:33:20.920Z","avatar_url":"https://github.com/erdomke.png","language":"C#","readme":"![BracketPipe Icon](https://raw.githubusercontent.com/erdomke/BracketPipe/master/icon.png)\n\n# BracketPipe\n\nBracketPipe is a .NET library for building parsing and processing piplines for web languages like HTML, CSS, Javscript, SVG, and MathML. The parser is built upon the official W3C specification.  It differentiates itself from other libraries such as [AngleSharp](https://github.com/AngleSharp/AngleSharp) (which it is based on) and [HTML Agility Pack](http://htmlagilitypack.codeplex.com/) in that it does not build an in-memory representation of the DOM.  Rather, it focuses on providing a convenient streaming interface for fast processing of HTML documents.  This makes the library ideal for \n\n* minifying HTML\n* sanitizing HTML to prevent XSS attacks\n* converting HTML to text\n* crawling hyperlinks from HTML documents\n* cleaning up MS Word HTML\n* ... and any other task that only requires a single traversal of the HTML document\n\nIt can also be viewed as a modern update to previous projects such as the [SgmlReader](https://github.com/MindTouch/SGMLReader) and [Majestic-12 HTML Parser](http://www.majestic12.co.uk/projects/html_parser.php)\n\n## Usage\n\nUse a pipeline to parse, minify, and sanitize HTML;\n\n```csharp\nvar html = @\"\u003cdiv\u003e  \u003cscript\u003ealert('xss');\u003c/script\u003e\n              \u003ca href=\"\"http://www.google.com/\"\"\u003eGoogle\u003c/a\u003e\n              \u003ca href=\"\"http://www.yahoo.com/\"\"\u003eYahoo\u003c/a\u003e  \u003c/div\u003e\";\nusing (var reader = new HtmlReader(html))\n{\n  var result = (string)reader.Sanitize().Minify().ToHtml();\n  Assert.AreEqual(@\"\u003cdiv\u003e\u003ca href=\"\"http://www.google.com/\"\"\u003eGoogle\u003c/a\u003e \u003ca href=\"\"http://www.yahoo.com/\"\"\u003eYahoo\u003c/a\u003e\u003c/div\u003e\"\n    , result);\n}\n```\n\nParse the links from an HTML string\n\n```csharp\nvar html = @\"\u003chtml\u003e  \u003cbody\u003e  \u003cscript\u003ealert('xss');\u003c/script\u003e\n              \u003ca href=\"\"http://www.google.com/\"\"\u003eGoogle\u003c/a\u003e\n              \u003ca href=\"\"http://www.yahoo.com/\"\"\u003eYahoo\u003c/a\u003e  \u003c/body\u003e  \u003c/html\u003e\";\nusing (var reader = new HtmlReader(html))\n{\n  var urls = reader\n    .OfType\u003cHtmlStartTag\u003e()\n    .Where(t =\u003e t.Value == \"a\")\n    .Select(t =\u003e t[\"href\"])\n    .ToArray();\n  CollectionAssert.AreEqual(new string[]\n  {\n    \"http://www.google.com/\",\n    \"http://www.yahoo.com/\"\n  }\n  , urls);\n}\n```\n\nSanitize, minify, or convert HTML\n\n```csharp\nvar html = \"Something to \u003cstrong\u003econvert\u003c/strong\u003e\";\nvar str = Html.Sanitize(html);\nstr = Html.Minify(html);\nstr = Html.ToMarkdown(html)\n```\n\nWrite HTML\n\n```csharp\nusing (var s = new StringWriter())\nusing (var w = new HtmlTextWriter(s))\n{\n  w[\"html\"]\n    [\"body\"]\n      [\"div\", \"style\", \"color:red\", \"id\", \"1234\"]\n        .Text(\"A \u003e value\")\n      [\"/div\"]\n      [\"input\", \"type\", \"text\", \"value\", \"start\"]\n      [\"p\"].Text(\"para \u0026 more\")[\"/p\"]\n    [\"/body\"]\n   [\"/html\"].Flush();\n  var str = s.ToString();\n}\n```\n\nXML to HTML\n\n```csharp\nusing (var s = new StringWriter())\nusing (var w = new HtmlTextWriter(s))\n{\n  var xml = new XElement(\"body\",\n    new XElement(\"div\", new XAttribute(\"style\", \"color:red\"), \"A \u003e value\"),\n    new XElement(\"input\", new XAttribute(\"type\", \"text\"), new XAttribute(\"value\", \"start\")),\n    new XElement(\"p\", \"para \u0026 more\"));\n  xml.WriteTo(w);\n  w.Flush();\n\n  var str = s.ToString();\n}\n```\n\n## Installing via NuGet\n\n[![NuGet version](https://badge.fury.io/nu/BracketPipe.svg)](https://www.nuget.org/packages/BracketPipe)\n\n    Install-Package BracketPipe\n\n## Performance\n\nUsing only the stripped down core of [AngleSharp](https://github.com/AngleSharp/AngleSharp), BracketPipe\nachives incredibly fast performance.  Comparison charts each showing the average time over thousands of operations:\n\n**Conversion to Markdown**\n\nComparison to [ReverseMarkdown](https://github.com/mysticmind/reversemarkdown-net/) and [HTML2Markdown](https://github.com/baynezy/Html2Markdown/);\n\n![Markdown conversion comparsion chart](http://chart.googleapis.com/chart?cht=bhg\u0026chs=400x120\u0026chd=t:1203.8,1148.8,5255.2\u0026chds=0,5300\u0026chxl=1:|Html2Markdown(5255ms)|ReverseMarkdown(1149ms)|BracketPipe(1204ms)\u0026chxt=x,y\u0026chxr=0,0,5300\u0026chco=a347bb)\n\n**Minifying HTML**\n\nComparison to [WebMarkupMin](https://github.com/Taritsyn/WebMarkupMin);\n\n![Minification comparsion chart](http://chart.googleapis.com/chart?cht=bhg\u0026chs=400x80\u0026chd=t:853.3,1203\u0026chds=0,1300\u0026chxl=1:|WebMarkupMin(1203ms)|BracketPipe(853ms)\u0026chxt=x,y\u0026chxr=0,0,1300\u0026chco=a347bb)\n\n**Sanitizing HTML**\n\nComparison to [HtmlSanitizer](https://github.com/mganss/HtmlSanitizer)\n\n![Sanitization comparsion chart](http://chart.googleapis.com/chart?cht=bhg\u0026chs=400x80\u0026chd=t:410.8,1983.6\u0026chds=0,2000\u0026chxl=1:|HtmlSanitizer(1983ms)|BracketPipe(410ms)\u0026chxt=x,y\u0026chxr=0,0,2000\u0026chco=a347bb)\n\n## Standards Conformance\n\nThe parser uses the [HTML 5.1 specification](https://dev.w3.org/html5/spec-preview/tokenization.html), which defines error handling and element correction.  As \na result, it works the same as all modern browsers.\n\n## Portable\n\nIt is designed as a .Net Standard library targeting [.Net Standard 1.0](https://docs.microsoft.com/en-us/dotnet/articles/standard/library).  \nThat means it supports the following platforms:\n\n* .NET Core 1.0+\n* .NET Framework 4.5+\n* Xamarin vNext+\n* Universal Windows Platform 10.0+\n* Windows 8.0+\n* Windows Phone 8.1+\n* Windows Phone Silverlight 8.0+\n\nThe NuGet package build also supports .Net 3.5 and .Net 4.0.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 - 2016 BracketPipe\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferdomke%2Fbracketpipe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferdomke%2Fbracketpipe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferdomke%2Fbracketpipe/lists"}