如何将HTML转换为BBCode [英] How to convert HTML to BBCode

查看:120
本文介绍了如何将HTML转换为BBCode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我维护一个公告牌,以HTML格式保存富文本消息。现在我需要将所有这些消息迁移到需要BBC代表HTML的Joomla Kunena公告板。

是否有任何库可以干净地将HTML转换为BBCode。有很多脚本可以用于BBCode到HTML,但不是其他方式。



谢谢...

解决方案

它应该可以在文本输出模式中使用XSLT

 < xsl:output method =text> 
...
< xsl:template match =b | strong> [b]< xsl:apply-templates /> [/ b]< / xsl:template>
< xsl:template match =br>&#10;< / xsl:template>
< xsl:template match =p>&#10;< xsl:apply-templates />&#10;< / xsl:template>
< xsl:template match =a> [url =< xls:value-of select =@ href/>]< xsl:apply-templates /> [/ URL]< / XSL:模板>

到那里解析HTML 并使用内置XSLT处理器


I maintain a bulletin board that saves rich text messages in HTML. Now I need to migrate all those messages into Joomla Kunena bulletin board that requires BBCode representation of HTML.

Is there any library to convert HTML to BBCode cleanly. There are bunch of scripts out there for BBCode to HTML but not the other way around.

Thanks...

解决方案

It should be doable with XSLT in text output mode:

<xsl:output method="text">
…
<xsl:template match="b|strong">[b]<xsl:apply-templates/>[/b]</xsl:template>
<xsl:template match="br">&#10;</xsl:template>
<xsl:template match="p">&#10;<xsl:apply-templates/>&#10;</xsl:template>
<xsl:template match="a">[url="<xls:value-of select="@href"/>"]<xsl:apply-templates/>[/url]</xsl:template>
<xsl:template match="text()"><x:value-of select="normalize-space(.)"/></xsl:template>

To get there parse HTML and use built-in XSLT processor.

这篇关于如何将HTML转换为BBCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆