Pablissimo / CodeKicker.BBCode-Mod

Modifications to CodeKicker.BBCode at http://bbcode.codeplex.com/
MIT License
8 stars 9 forks source link

Multiple tags with the same name #2

Open NickThissen opened 7 years ago

NickThissen commented 7 years ago

Hi! Thanks for these fixes to the BBCode parser. I hope you are still reading this. I am having some parsing trouble and hoped you could help.

I am trying to parse two possible flavors of the [url] tag:

1. [url]http://www.google.com[/url]
2. [url=http://www.google.com]Google[/url]

This is my desired output:

1. <a href="http://www.google.com" />
2. <a href="http://www.google.com">Google</a>

I know how to configure either of these, e.g.:

1. new BBTag("url", "<a href=\"${content}\" />", "", false, true)
2. new BBTag("url", "<a href=\"${href}\">", "</a>", new BBAttribute("href", ""))

The problem is, I cannot declare both of these at the same time because tags should have unique names. Both of these tags are named "url" so there's an error in the parser where it tries to obtain the tag by name.

Is this not supported? Isn't this an extremely common use-case and how pretty much every forum works?

I suppose to fix you'd have to get a list of all matching tags, and then figure out by their attributes which one is meant... But I haven't been able to get anywhere close to this. Hope you have an idea!

Jetski5822 commented 6 years ago

Just hit this.... to fix it do this..

new BBAttribute("href", "", GetHRef, HtmlEncodingMode.UnsafeDontEncode), // Default Attribute
new BBAttribute("href", "href", GetHRef, HtmlEncodingMode.UnsafeDontEncode),

private string GetHRef(IAttributeRenderingContext attributeRenderingContext)
{
    var href = attributeRenderingContext.GetAttributeValueByID("href");

    if (href == null)
    {
        return attributeRenderingContext.GetAttributeValueByID("content");
    }

    return href;
}
alex-jitbit commented 6 years ago

Here's what I did:

new BBTag("url", "<a href=\"${href}\">", "</a>", new BBAttribute("href", ""), new BBAttribute("href", "href"))