I use your library for newsfeed reports generation, and I think it would be great to allow users to substitute ``{hisContents} tag
with raw XML like this:
<w:r>
<w:rPr>
<w:highlight w:val="red"/>
</w:rPr>
<w:t>Some highlighted text</w:t>
</w:r>
It is especially useful when {content}
is itself large (for example, news entry), because it makes possible for user to control underlying styles, colors and etc in some kind of large text entry. In fact, it is one of very few options for supporting such control over big runtime-generated text pieces.
If I try to do this now, my XML is surrounded by <w:r><w:t>myRawXmlHere/w:t/w:r, and MS Word obviously thinks that file is corrupt.
For distinguishing "raw" xml data I see 2 solutions: you may automatically detect XML by using something like XPath //w:r/w:t/w:r/w:t
and act accordingly, or you may use some kind of special tag syntax like {@myXmlData}
, which will prevent library from surrounding contents with <w:r><w:t></w:t></w:r>
. I prefer latter option, because it has explicit behavior.
Although there is one problem with node replacing: it is possible that single text run contains not only you tag, but some extra data:
<w:r>
<w:t>Your complex text i</w:t>
</w:r>
<w:r>
<w:t>s {rawXmlText}.</w:t>
</w:r>
If we are to replace node, we will lose 's' for 'is' and '.' after our tag.
So, we have to split runs with tags like that: [left part, static] [middle part, dynamic] [right part, static]
, where left or right parts may be empty. After that we need to create separate run for left part (if it is non-empty), middle, and for right part. Also, we have to apply run-level formatting of the initial run to them. After that we can just replace initial run with the middle one's XML. It will lose initial formatting, of course, but I am unsure if it is bad thing for control-seeking user. Maybe it should be an option, I don't know. If it have to be there -- we can just copy non-overlapping attributes from initial run to user-supplied one.
And I don't know, but maybe the same for paragraphs?
Thank you for great library!