forked from extern/egroupware
minimal support for yaml files in document merge: multi-line replacements get prefixed with as many space as the placeholder
This commit is contained in:
parent
aa651be625
commit
46c8c6e318
@ -174,6 +174,8 @@ abstract class bo_merge
|
||||
return true; // alias for text/xml, eg. ms office 2003 word format
|
||||
case 'message/rfc822':
|
||||
return true; // ToDo: check if you are theoretical able to send mail
|
||||
case 'application/x-yaml':
|
||||
return true; // yaml file, plain text with marginal syntax support for multiline replacements
|
||||
default:
|
||||
if (substr($mimetype,0,5) == 'text/')
|
||||
{
|
||||
@ -687,7 +689,7 @@ abstract class bo_merge
|
||||
{
|
||||
$content = preg_replace('/\\\{\\\{([^\\}]+)\\\}\\\}/i','$$\1$$',$content);
|
||||
}
|
||||
|
||||
|
||||
// make currently processed mimetype available to class methods;
|
||||
$this->mimetype = $mimetype;
|
||||
|
||||
@ -1085,6 +1087,19 @@ abstract class bo_merge
|
||||
// Check for encoded >< getting double-encoded
|
||||
$replacements = str_replace(array('&',"\r","\n",'&lt;','&gt;'),array('&','',$break,'<','>'),$replacements);
|
||||
}
|
||||
if ($mimetype == 'application/x-yaml')
|
||||
{
|
||||
$content = preg_replace_callback('/^( +)(\$\$[^$]+\$\$)/m', function($matches) use ($replacements)
|
||||
{
|
||||
$replacement = $replacements[$matches[2]];
|
||||
// replacement with multiple lines --> add same number of space as before placeholder
|
||||
if (isset($replacement) && strpos($replacement, "\n") !== false)
|
||||
{
|
||||
return $matches[1].implode("\n".$matches[1], preg_split("/\r?\n/", $replacement));
|
||||
}
|
||||
return $matches[0]; // regular replacement below
|
||||
}, $content);
|
||||
}
|
||||
return str_replace(array_keys($replacements),array_values($replacements),$content);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user