【问题标题】:How to parse html tags in CodeKicker BB Code Core如何在 CodeKicker BB Code Core 中解析 html 标签
【发布时间】:2022-01-22 11:11:36
【问题描述】:

我正在尝试使用 CodeKicker BBCode Core 解析以下字符串内容。

String to parse = [urltab=www.google.com]www.google.com[/urltab]
Expected output = <a href="www.google.com" target="_blank">www.google.com</a>

Actual output = <a href="www.google.com" target="_blank">&lt;!-- m --&gt;&lt;a href=&quot;//www.google.com&quot; target=&quot;_blank&quot;&gt;www.google.com&lt;/a&gt;&lt;!-- m --&gt;</a>

如您所见,实际输出中还有其他标签。

我正在使用以下方法将字符串解析为html内容。

public string ParseStringToBBCode(string content)
{
    var htmlBbCodeParser = GetHtmlBbParser();
    var htmlContent = htmlBbCodeParser.ToHtml(content);
            
    return htmlContent;
}

有没有办法获得本场景中提到的预期输出?

【问题讨论】:

    标签: html html-parsing bbcode


    【解决方案1】:

    答案 1:

    创建了一个新标签作为 [noparse] 并将不需要在该标签中传递的内容包装起来。

    例子:

    修改输入为

    [urltab=www.google.com][noparse]www.google.com[/noparse][/urltab]
    

    修改 GetHtmlBbParser() 方法并添加新标签。

    new BBCodeParser(new []
    {
       new BBTag("noparse", "", "", 1, allowUrlProcessingAsText: false),
    }
    

    答案 2: 修改 [url] 和 [urltab] 标签初始化。

    设置allowUrlProcessingAsText: false

    new BBCodeParser(new []
    {
        new BBTag("url", "<a href=\"${href}\" target=\"${target}\">", "</a>", 19, allowUrlProcessingAsText: false,attributes: new BBAttribute[] { new BBAttribute("href", ""), new BBAttribute("href", "href"), new BBAttribute("target", ""), new BBAttribute("target", "target") }),
        new BBTag("urltab", "<a href=\"${href}\" target=\"_blank\">", "</a>", 20, allowUrlProcessingAsText: false, attributes: new BBAttribute[] { new BBAttribute("href", ""), new BBAttribute("href", "href") })
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      • 2013-01-05
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      相关资源
      最近更新 更多