-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block clone suddenly stopped working after applying formatting #867
Comments
The '/(<\?xml.*)(<w:p.*>\${' . $blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/' . $blockname . '}<\/w:.*?p>)/is' That's crudely looking for a |
So I guess what needs to happen is a search for the clone tags in the XML structure, then walking up the tree to the Of course NONE of that can be done with a REGEX. The document source is structured XML and needs to be treated as such. Here is the source of my document that is failing to match the |
Trying this preg match offline to see if I can see the problem, it seems that it is this at the start that is causing it to not match:
That has me totally baffled, because that does match everything when used on its own |
Also finding the regex replacements that Looking at it, a REGEX replace is performed if only replacing some of the fields, otherwise a string replace is done. Ouch Edit: I just tried a string replace, using protected function setValueForPart($search, $replace, $documentPartXML, $limit)
{
// Note: we can't use the same function for both cases here, because of performance considerations.
if (self::MAXIMUM_REPLACEMENTS_DEFAULT === $limit) {
return str_replace($search, $replace, $documentPartXML);
} else {
if (is_string($documentPartXML)) {
for($i = 1; $i <= $limit; $i++) {
$pos = strpos($documentPartXML, $search);
if ($pos === false) {
return $documentPartXML;
}
// Chop the string before and after the search text, then join it back
// together around the replace text. Still slow for 8M documents!
$documentPartXML = substr($documentPartXML, 0, $pos)
. $replace .
substr($documentPartXML, $pos + strlen($search));
}
return $documentPartXML;
}
$regExpEscaper = new RegExp();
return preg_replace($regExpEscaper->escape($search), $replace, $documentPartXML, $limit);
}
} |
@judgej About the But the solution for your block cloning problem is to delete the closing tag, press enter, and write it again. This will ensure it being again inside 1 |
@FBnil Big fan of you right now, your code fixed the clone block for me! |
I enconter this problem |
I had a simple block that covered an entire page, and was cloned N times right at the start before substitution variables were filled in with data:
Opening as a template, cloning, putting in data and saving working great.
Then I tried adding some formatting to the source document, starting by setting the entire document to Arial, and the
${PAGE}
tags are no longer recognised at all.Looking in the template source, the lines with the tags had font formatting applied, so I removed that (using the ctrl-space technique that has been around since MS Word 2.0). This gives me a source now without the formatting, that looks like this (saved from MS Word):
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: