{"id":18276434,"url":"https://github.com/u-labs/ulabs.bbcodeparser","last_synced_at":"2025-04-09T04:18:48.921Z","repository":{"id":55374806,"uuid":"200068073","full_name":"U-Labs/ULabs.BBCodeParser","owner":"U-Labs","description":"VBulletin compatible BBCode-Parser for .NET Standard","archived":false,"fork":false,"pushed_at":"2023-10-04T18:54:16.000Z","size":565,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-01T23:51:33.613Z","etag":null,"topics":["bbcode","bbcode-parser","c-sharp","net-core","net-standard","vbulletin"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/U-Labs.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,"publiccode":null,"codemeta":null}},"created_at":"2019-08-01T14:42:00.000Z","updated_at":"2021-10-14T18:53:52.000Z","dependencies_parsed_at":"2025-02-14T22:32:12.884Z","dependency_job_id":"af2be8b0-77bc-4e27-a3bc-bcdfe9460e1d","html_url":"https://github.com/U-Labs/ULabs.BBCodeParser","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/U-Labs%2FULabs.BBCodeParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/U-Labs%2FULabs.BBCodeParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/U-Labs%2FULabs.BBCodeParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/U-Labs%2FULabs.BBCodeParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/U-Labs","download_url":"https://codeload.github.com/U-Labs/ULabs.BBCodeParser/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974734,"owners_count":21026742,"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":["bbcode","bbcode-parser","c-sharp","net-core","net-standard","vbulletin"],"created_at":"2024-11-05T12:16:01.790Z","updated_at":"2025-04-09T04:18:48.902Z","avatar_url":"https://github.com/U-Labs.png","language":"C#","readme":"# U-Labs BBCode-Parser\nA vBulletin 4 compatible BB-Code parser for .NET Standard 2 OSS under [GNU GPLv3](https://choosealicense.com/licenses/gpl-3.0/).\n\n![Demo](https://u-img.net/img/8694Lb.png)\n\n## Usage \nInstall [the official NuGet-Package ULabs.BBCodeParser](https://www.nuget.org/packages/ULabs.BBCodeParser):\n\n```bash\n# Visual Studio Package Manager Console\nInstall-Package ULabs.BBCodeParser\n# DotNet CLI (e.g. for VS Code)\ndotnet add package ULabs.BBCodeParser\n```\nYou need to inject an instance of `BBCodeToHtml` and pass the BBCode to the `Parse(string bbCode)` method like this: \n```cs\nstring html = BBCodeToHtml.Parse(\"This is [b]Bold[/b]\");\n```\nThe solution contains a simple Razor views based demo project with our markup from the demo screenshot above. See \n[Index.html](./ULabs.BBCodeParserDemo/Pages/Index.cshtml) with the sample code. A simple integration into other projects using a \nNuGet package is planned. \n\n### Dependency injection\nFor ASP.NET Core, DI is the recommended way to resolve your dependencies. \nWe don't have interfaces yet for clean dependency injection, but a helper method is already avaliable:\n\n```cs\nusing ULabs.BBCodeParser.Html;\nnamespace ULabs.BBCodeParserDemo {\n    public class Startup {\n        public void ConfigureServices(IServiceCollection services) {\n            services.AddBBCodeParser();\n            // ...\n        }\n    }\n}\n\n```\nThe `AddBBCodeParser()` method can register all services with their default configuration. Changes are only required if you would like to\nmodify or extend BBCodes. To use the parser, inject it's service. \n\nRazor example: \n\n```cs\n@using ULabs.BBCodeParser.Html\n@inject BBCodeToHtml bbCodeToHtml\n\n@Html.Raw(bbCodeToHtml.Parse(\"This is [b]bold[/b], [i]italic[/i], [u]underline[/u] and [s]strike through[/s].\"));\n```\n\n## Customizing BBCodes\nCommon BBCodes like formattings were already covered by this library. This happens in \n[BBCodeHtmlMapper](./ULabs.BBCodeParser/Html/BBCodeHtmlMapper.cs). However, you're able to customize them like removing some BBCodes or\nadd new ones. To do this, simple create a instance of `BBCodeHtmlMapper` and modify `Codes` as you want. Every BBCode is covered by \nan instance of the `BBCode` class. Simple ones like bold formattings only contains their corresponding HTML tag: \n\n```cs\nvar boldCode = new BBCode(\"[b]\", \"\u003cstrong\u003e\");\n```\n\nThis simply replaces `[b]` with `\u003cb\u003e` and it's corresponding close tag. \n\nFore more complex tags, the `BBCode` class has an overload for some delegate method that get all required information in a `Node` object:\n\n```cs\nvar complexCustomCode = new BBCode(\"[shadow]\", (node) =\u003e $\"\u003cspan class='text-shadow'\u003e{node.InnerHtml}\u003c/span\u003e\");\n```\n\nYou can also fetch the argument, which may got passed to the BBCode. This is everything after `{tagName}=`. A good example to explain this\nis `[font]`:\n\n```cs\nvar fontCode = new BBCode(\"[font]\", (node) =\u003e $\"\u003cspan style='font-family: {node.Argument}'\u003e{node.InnerHtml}\u003c/span\u003e\");\n```\n\nSo `[font=Arial]Hi![/font]` would result in `Arial` as argument, where `InnerHtml` is `Hi!`. \n\n### Use customized BBCodes\nTo apply those customizations, you can pass a `Func\u003cIServiceProvider, BBCodeHtmlMapper\u003e` to the `AddBBCodeParser` helper. \nIt's constructor accepts a `List\u003cBBCode\u003e`, which were added to the default ones. If you don't want to use the default ones, \nset `overrideDefaultBBCodes` to true. Then the default ones are replaced by the provided ones.\n\nThe following example adds an additional BBCodes for attachments and replace all attachments with some notice text about the attachment ID:\n\n```csharp\nvar customBBCodes = new List\u003cBBCode\u003e();\nvar attachments = new BBCode(\"[attach]\", (node) =\u003e {\n    return $\"\u003cb\u003eFound Attachment with ID = {node.InnerContent}\";\n});\ncustomBBCodes.Add(attachments);\nFunc\u003cIServiceProvider, BBCodeHtmlMapper\u003e bbCodeHtmlMapperFunc = (sp) =\u003e new BBCodeHtmlMapper(sp.GetRequiredService\u003cRazorLightEngine\u003e(), customBBCodes);\nservices.AddBBCodeParser(bbCodeHtmlMapperFunc);\n```\n\n## Known issues\n### `Cannot find reference assembly 'Microsoft.AspNetCore.Antiforgery.dll'` Exception\nThis exception occurs on .NET Core 3.0 and higher. [To fix it](https://github.com/toddams/RazorLight#im-getting-cannot-find-reference-assembly-microsoftaspnetcoreantiforgerydll-exception-on-net-core-app-30-or-higher),\nadd the following lines to your .csproj file:\n\n```xml\n\u003cPreserveCompilationContext\u003etrue\u003c/PreserveCompilationContext\u003e\n\u003cPreserveCompilationReferences\u003etrue\u003c/PreserveCompilationReferences\u003e\n```\n## Motivation\nThis project is part of my approach to develop on a modern .NET Core application stack for vBulletin. I did some POCs, also on the database.\nBut now it's time to create a better structure. Since I believe in open source and also use a lot of OSS, I'd also like to share my work to\ngive something back for the community. \n\nThe motivation behind this parser was that I couldn't find an reasonably actively maintained project for .NET Core/Standard that is \ncustomizeable or at least supports vBulletin's BBCodes. Since Linux is the target platform, older 4.X Librarys are not suiteable. Even if they\nstill work after years without update. \n\nI also want to avoid parsing using Regular Expression. It seems not the right \ntool for structured BBCode. So I wrote my own, which also gave me some experience how parser work. \n\n## Stability and known limitations\nCurrently, this library is not considered as production ready. Some things doesn't work well yet. For example formatting in lists. \nAnd also attachments from vBulletin aren't parsed yet. I had an approach that works, but since we need  access to VBs database, \nthis part should be kept seperately. \n\nThere are some other bugs for sure. So feel free to test, create issues and even better: Try to help me fixing them with pull requests. \nContributions are welcome! :)\n\n## Contributions/Coding Conventions\n\nAs said above: Every help on this library is welcome! The code in this repository should fit to \n[the official C# Coding Conventions](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions). \nMy only intentionally deviation from this were the curly brackets, which are not placed in an extra line. So code should looke like \n\n```cs\nif(true) {\n\tmyClass.DoAction();\n}\n```\n\ninstead of \n\n```cs\nif(true) \n{\n\tmyClass.DoAction();\n}\n```\n\n## Credits\nThis project itself uses the following external open source libraries to which I would like to express my gratitude:\n* [HtmlSanitizer](https://github.com/mganss/HtmlSanitizer)\n* [RazorLight](https://github.com/toddams/RazorLight)\n* [Html Agility Pack](https://html-agility-pack.net/)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fu-labs%2Fulabs.bbcodeparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fu-labs%2Fulabs.bbcodeparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fu-labs%2Fulabs.bbcodeparser/lists"}