【发布时间】:2015-09-28 16:47:26
【问题描述】:
我正在一个需要处理 ODT 文档的系统中实现 TinyButStrong / OpenTBS,我遇到了一个特定模板的问题,该模板在变量名中包含标签。
情况如下:
模板部分:
content.xml的相关部分
<table:table-cell table:style-name="Table3.A1" office:value-type="string">
<text:p text:style-name="P22">Tipo de documento</text:p>
<text:p text:style-name="P29">
<text:span text:style-name="T7">
[b.</text:span>tipoDocumento<text:span text:style-name="T7">]
</text:span>
</text:p>
</table:table-cell>
如您所见,变量名称为</text:span>tipoDocumento<text:span text:style-name="T7">。该文档是在 LibreOffice 中编辑的,并且由于某种未知原因添加了标签。
我以为我可以传递完整的变量名(包括标签),OpenTBS 会正确解析该值,所以我尝试了以下方法:
$data = ['</text:span>tipoDocumento<text:span text:style-name="T7">' => 'somevalue'];
$tbs = new clsTinyButStrong;
$tbs->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$tbs->LoadTemplate($templatePath, OPENTBS_ALREADY_UTF8);
// Note that we need to send an array of arrays to $data,
$tbs->MergeBlock($block, 'array', [$data]);
但这会导致 TBS 错误:
<b>TinyButStrong Error</b> in field &#91;b.</text:span>tipoDocumento<text:span text:style-name...]: item '&lt;/text:span&gt;tipoDocumento&lt;text:span text:style-name' is not an existing key in the array. <em>This message can be cancelled using parameter 'noerr'.</em>
我做了一些调试,发现在核心 tbs_class.php 第 1177 行(在 meth_Locator_Replace() 中,这是引发错误的地方),$Loc->SubLst[$i] 的内容是 </text:span>tipoDocumento<text:span text:style-name,这并不'不匹配我的数组中的值。
所以,我假设由于某种原因,TBS 正在通过等号 (=) 爆炸索引,从而导致此问题。所以,
- 这是故意的吗?
- 能否修复此问题(以防出现错误)以允许带有等号的标签?
- 有没有更好的方法来避免变量中的标签,或者在 LibreOffice 中有没有办法避免这种情况?
【问题讨论】:
标签: php odt opentbs tinybutstrong