使用 SDL Tridion 2011 SP1 在富文本字段中创建锚链接 [英] Creating anchor links in rich text fields with SDL Tridion 2011 SP1

查看:29
本文介绍了使用 SDL Tridion 2011 SP1 在富文本字段中创建锚链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在组件的 RTF 字段中使用定位按钮,但出现意外行为.在设计视图中使用 Chrome 浏览器,我突出显示/选择我想用作锚点的标题(即

My Heading

),然后按下锚点按钮并输入锚点名称(即 my_place).

I am trying to use the anchor button in a RTF field of a Component, and getting unexpected behavior. Using the Chrome Browser from the design view, I highlight/select the heading (i.e. <h2>My Heading</h2>) I want to use as an anchor, and press the anchor button and enter the anchor name (i.e. my_place).

这会导致以下代码显示在我的源标签中:

This results in the following code being displayed in my source tab:

<a name="my_place" id="myplace"/><h2>My Heading</h2>

这会导致在浏览器中显示 HTML 时出现渲染问题,因为 <a/> 标签会自动关闭.

This causes render problems when displaying the HTML in a browser due to the self closing <a/> tag.

我希望将以下三个 HTML 片段之一插入到 HTML 源中:

I would have expected one of the following three HTML fragments being inserted into the HTML source:

<a name="my_place" id="myplace"><h2>My Heading</h2></a>

<h2><a name="my_place" id="myplace">My Heading</a></h2>

<a name="my_place" id="myplace"><a><h2>My Heading</h2>

有没有其他人遇到过这种情况?或者知道一种实现我所期望的方法(无需手动编辑 HTML).或者这是当前版本产品中的错误.

Has anyone else experienced this? or know of a way to achieve what I had expected (without manually editing the HTML). Or is this a bug in the current version of the product.

推荐答案

附上我的示例 XSLT 模板:

Attached is my sample XSLT template:

<template match="a[(@name) and (count(node()) = 0)]">
    <copy>
        <apply-templates select="@*"/>
        <xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" class="hidden"> </xhtml:span>
    </copy>
</template>

这增加了一些超出严格需要的内容,但处理了我们由于内容交付端的 XML 操作而遇到的一些其他问题.

This adds a bit more than strictly needed, but handles some other issues we have due to XML manipulation on the Content Delivery side.

本质上它匹配所有带有 name 属性的空 a 标签,并在它们之间添加一些东西以阻止它们自动关闭.在我们的例子中,我们使用 XSLT 对所有 XML 进行后期处理,因此我们面临着空标签总是被关闭的挑战.因此,作为一个肮脏的黑客,我们现在在空标签之间插入一个隐藏的 span 标签以防止出现问题.

Essentially it matches all empty a tags with a name attribute, and add something between them in order to stop them self closing. In our case we post process all of the XML with XSLT, so we have challenges with empty tags getting closed all the time. So as a dirty hack, we are now inserting a hidden span tag between empty tags to prevent the issue.

这篇关于使用 SDL Tridion 2011 SP1 在富文本字段中创建锚链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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