Browse Source

Don't lose original formatting on paragraphs if a value has been replaced/displaced. Fix #31

master
Alex Puiu 2 years ago
parent
commit
016dac6646
  1. 44
      app/SearchDisplace/SearchAndDisplaceXML.php

44
app/SearchDisplace/SearchAndDisplaceXML.php

@ -21,10 +21,10 @@ class SearchAndDisplaceXML
{
$this->applySD();
$this->convertToOdt();
$this->convertToOriginalFileType();
}
protected function convertToOdt()
protected function convertToOriginalFileType()
{
(new Process(['soffice', '--convert-to', $this->type, $this->file, '--outdir', storage_path('app/tmp/')]))->run();
}
@ -34,33 +34,23 @@ class SearchAndDisplaceXML
$dom = new \DOMDocument();
$dom->load($this->file);
foreach($dom->getElementsByTagName('p') as $p) {
$is_image = false;
if($p->childNodes) {
foreach($p->childNodes as $child) {
if(isset($child->tagName) && $child->tagName == 'draw:frame') {
$is_image = true;
}
}
}
if(!$is_image) {
$search = new SearchAndDisplace(
stripslashes($p->textContent),
[
'searchers' => $this->searchers,
],
false,
true
);
$changed = $search->execute();
if(!$changed) {
continue;
}
foreach($dom->getElementsByTagName('span') as $p) {
$search = new SearchAndDisplace(
stripslashes($p->textContent),
[
'searchers' => $this->searchers,
],
false,
true
);
$changed = $search->execute();
$p->textContent = $changed['content'];
if(!$changed) {
continue;
}
$p->textContent = $changed['content'];
}
$dom->save($this->file);

Loading…
Cancel
Save