Skip to content

Commit

Permalink
MacroBlockVariableOutput: added automatic identation
Browse files Browse the repository at this point in the history
  • Loading branch information
paveljanda committed Feb 27, 2018
1 parent b0b364d commit ad10720
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/Markdown/Macros/MacroBlockVariableOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,26 @@ protected function runVariableMacro(string & $content): void // Intentionally &
* Remove lines with inline variables definition and put then into DocuScope
*/
$content = preg_replace_callback(
'/\{\$\$([a-zA-Z_0-9]+)\}/m',
'/(^.*)?\{\$\$([a-zA-Z_0-9]+)\}/m',
function(array $input): string {
return $this->docuScope->getBlockVariable($input[1]);
$whitespacePrefix = '';

/**
* Prefix the whole block with current identation
*/
foreach (str_split($input[1]) as $character) {
if ($character === "\t") {
$whitespacePrefix .= $character;

continue;
}

break;
}

$block = $this->docuScope->getBlockVariable($input[2]);

return $input[1] . preg_replace('/\n/m', "\n{$whitespacePrefix}", $block);
},
$content
);
Expand Down

0 comments on commit ad10720

Please sign in to comment.