Skip to content
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

Update regexp used in cloneBlock operation in TemplateProcessor #1478

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

babache
Copy link

@babache babache commented Sep 26, 2018

Description

cloneBlock does not work with some model

Fixes #1477

Checklist:

  • I run with sample with "Sample_23_TemplateBlock.docx"

@troosan troosan changed the title cloneBlock fix Update regexp used in cloneBlock operation in TemplateProcessor Dec 26, 2018
@troosan
Copy link
Contributor

troosan commented Dec 28, 2018

@babache Please provide a document that does not work

@troosan troosan added the Waiting for feedback Question has been asked, waiting for response from PR author label Dec 28, 2018
@babache
Copy link
Author

babache commented Dec 29, 2018

I have change regex with other method using a specific method in class, when i can, i send my new commit

@troosan
Copy link
Contributor

troosan commented Dec 29, 2018

@babache thanks, please also check against the latest code from de develop stream, your fix might not be needed anymore.

@babache
Copy link
Author

babache commented Jan 7, 2019

I'm sorry but i dont' kwnow how i can send my solution.
My new code for cloneBlock and my new fonction use in cloneBlock here : https://pastebin.com/2YBKVj4m

I use the branch develop and no develop_v1

@troosan troosan self-assigned this Jan 7, 2019
@nogenem
Copy link

nogenem commented Feb 11, 2019

Just to add to this, i'm also having problems with replaceBlock, which uses the same Regex.

When you change the font of a template using MS Word, the <w:p> of a paragraph gets a <w:pPr> inside it for the <w:rFonts>, which breaks the .xml generated, because it will be missing a </w:p>, since the Regex will get the <w:pPr> instead of the <w:p>.

<w:p w:rsidR="00DE14AC" w:rsidRPr="00660CA2" w:rsidRDefault="00DE14AC">
  <w:pPr>
    <w:rPr>
      <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
    </w:rPr>
  </w:pPr>
  <w:r w:rsidRPr="00660CA2">
    <w:rPr>
      <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
    </w:rPr>
    <w:t>${block1}</w:t>
  </w:r>
</w:p>
<w:p w:rsidR="00DE14AC" w:rsidRPr="00660CA2" w:rsidRDefault="00DE14AC">
  <w:pPr>
    <w:rPr>
      <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
    </w:rPr>
  </w:pPr>
  <w:r w:rsidRPr="00660CA2">
    <w:rPr>
      <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
    </w:rPr>
    <w:t>${/block1}</w:t>
  </w:r>
</w:p>

My simple solution was to add a space at the beginning of the regex: <w:p .*>, but i guess this would break in cases of a simple <w:p>...

Edit: Could do something like this too...

public function replaceBlock($blockname, $replacement)
{
  $ret = preg_match(
    // '/(<\?xml.*)(<w:p.*>\${' . $blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/' . $blockname . '}<\/w:.*?p>)/is',
    // changed here \/
    '/(<\?xml.*)(<w:p(\s.*)?>\${' . $blockname . '}<\/w:.*?p>)(.*)(<w:p.*\${\/' . $blockname . '}<\/w:.*?p>)/is', 
    $this->tempDocumentMainPart,
    $matches
  );
  
  if (isset($matches[4])) { // changed here <
    $this->tempDocumentMainPart = str_replace(
      $matches[2] . $matches[4] . $matches[5], // changed here <
      $replacement,
      $this->tempDocumentMainPart
    );
  }
}

@spam-n-eggs
Copy link

This is an old PR, and I'm having the same problem. Is there any chance this can get reworked and pulled into the main branch?

@PowerKiKi PowerKiKi changed the base branch from develop to master November 16, 2022 21:11
@Progi1984 Progi1984 force-pushed the master branch 3 times, most recently from 2d9f999 to e458249 Compare August 30, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting for feedback Question has been asked, waiting for response from PR author
Development

Successfully merging this pull request may close these issues.

cloneBlock not working
4 participants