ULabs.BBCodeParser
0.1.0
See the version list below for details.
dotnet add package ULabs.BBCodeParser --version 0.1.0
NuGet\Install-Package ULabs.BBCodeParser -Version 0.1.0
<PackageReference Include="ULabs.BBCodeParser" Version="0.1.0" />
paket add ULabs.BBCodeParser --version 0.1.0
#r "nuget: ULabs.BBCodeParser, 0.1.0"
// Install ULabs.BBCodeParser as a Cake Addin #addin nuget:?package=ULabs.BBCodeParser&version=0.1.0 // Install ULabs.BBCodeParser as a Cake Tool #tool nuget:?package=ULabs.BBCodeParser&version=0.1.0
U-Labs BBCode-Parser
A vBulletin 4 compatible BB-Code parser for .NET Standard 2 OSS under GNU GPLv3.
Usage
You need to inject an instance of BBCodeToHtml
and pass the BBCode to the Parse(string bbCode)
method like this:
string html = BBCodeToHtml.Parse("This is [b]Bold[/b]");
The solution contains a simple Razor views based demo project with our markup from the demo screenshot above. See Index.html with the sample code. A simple integration into other projects using a NuGet package is planned.
Dependency injection
We don't have interfaces yet for clean dependency injection, but a helper method is already avaliable:
using ULabs.BBCodeParser.Html;
namespace ULabs.BBCodeParserDemo {
public class Startup {
public void ConfigureServices(IServiceCollection services) {
services.AddBBCodeParser();
// ...
}
}
}
The AddBBCodeParser()
method can register all services with their default configuration. Changes are only required if you would like to
modify or extend BBCodes.
Customizing BBCodes
Common BBCodes like formattings were already covered by this library. This happens in
BBCodeHtmlMapper. However, you're able to customize them like removing some BBCodes or
add new ones. To do this, simple create a instance of BBCodeHtmlMapper
and modify Codes
as you want. Every BBCode is covered by
an instance of the BBCode
class. Simple ones like bold formattings only contains their corresponding HTML tag:
var boldCode = new BBCode("[b]", "<strong>");
This simply replaces [b]
with <b>
and it's corresponding close tag.
Fore more complex tags, the BBCode
class has an overload for some delegate method that get all required information in a Node
object:
var complexCustomCode = new BBCode("[shadow]", (node) => $"<span class='text-shadow'>{node.InnerHtml}</span>");
You can also fetch the argument, which may got passed to the BBCode. This is everything after {tagName}=
. A good example to explain this
is [font]
:
var fontCode = new BBCode("[font]", (node) => $"<span style='font-family: {node.Argument}'>{node.InnerHtml}</span>");
So [font=Arial]Hi![/font]
would result in Arial
as argument, where InnerHtml
is Hi!
.
Motivation
This 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. But 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 give something back for the community.
The motivation behind this parser was that I couldn't find an reasonably actively maintained project for .NET Core/Standard that is customizeable or at least supports vBulletin's BBCodes. And I also want to avoid parsing using Regular Expression. It seems not the right tool for structured BBCode. So I wrote my own, which also gave me some experience how parser work.
Stabilits and known limitations
Currently, this library is not considered as production ready. Some things doesn't work well yet. For example formatting in lists, handling multiple headlines. And also attachments from vBulletin aren't parsed yet. I had an approach that works, but since we need access to VBs database, this part should be kept seperately.
There are some other bugs for sure. So feel free to create issues and even better: Try to help me fixing them with pull requests. Contributions are welcome! 😃
Contributions/Coding Conventions
As said above: Every help on this library is welcome! The code in this repository should fit to the official C# Coding Conventions. My only intentionally deviation from this were the curly brackets, which are not placed in an extra line. So code should looke like
if(true) {
myClass.DoAction();
}
instead of
if(true)
{
myClass.DoAction();
}
Credits
This project itself uses the following external open source libraries to which I would like to express my gratitude:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- HtmlSanitizer (>= 4.0.217)
- RazorLight (>= 2.0.0-beta1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.1.10 | 509 | 10/14/2021 |
0.1.9.3 | 532 | 7/17/2020 |
0.1.9.2 | 456 | 7/5/2020 |
0.1.9.1 | 492 | 6/10/2020 |
0.1.9 | 481 | 6/9/2020 |
0.1.8 | 490 | 6/6/2020 |
0.1.7.1 | 528 | 5/9/2020 |
0.1.7 | 529 | 5/6/2020 |
0.1.6 | 485 | 5/1/2020 |
0.1.5 | 512 | 5/1/2020 |
0.1.4.1 | 478 | 4/24/2020 |
0.1.4 | 595 | 2/8/2020 |
0.1.3 | 681 | 8/10/2019 |
0.1.2 | 565 | 8/10/2019 |
0.1.1 | 570 | 8/1/2019 |
0.1.0 | 537 | 8/1/2019 |