diff --git a/src/MacroReplacer/AdfPanelReplacer.php b/src/MacroReplacer/AdfPanelReplacer.php new file mode 100644 index 0000000..60e9844 --- /dev/null +++ b/src/MacroReplacer/AdfPanelReplacer.php @@ -0,0 +1,40 @@ + with
+ */ +class AdfPanelReplacer implements MacroReplacerInterface +{ + public function replace(string $haystack): string + { + $result = preg_replace_callback( + '/]*>(.*?)<\/ac:adf-node>/is', + function ($match) { + $content = $match[1]; + + // Extract panel-type + preg_match('/(.*?)<\/ac:adf-attribute>/is', $content, $typeMatch); + $panelType = strtolower($typeMatch[1] ?? 'custom'); + + // Extract inner content + preg_match('/]*>(.*?)<\/ac:adf-content>/is', $content, $bodyMatch); + $body = $bodyMatch[1] ?? $content; + + return sprintf('
%s
', $panelType, $body); + }, + $haystack + ); + + $result = preg_replace( + '/]*>(.*?)<\/ac:adf-extension>/is', + '$1', + $result + ); + + return $result; + } +} diff --git a/src/MacroReplacer/GenericPanelReplacer.php b/src/MacroReplacer/GenericPanelReplacer.php new file mode 100644 index 0000000..c4ce998 --- /dev/null +++ b/src/MacroReplacer/GenericPanelReplacer.php @@ -0,0 +1,39 @@ + (custom panels) + * with
+ */ +class GenericPanelReplacer implements MacroReplacerInterface +{ + public function replace(string $haystack): string + { + return preg_replace_callback( + '/]*>(.*?)<\/ac:structured-macro>/is', + function ($match) { + $content = $match[1]; + + // Extract parameters + preg_match('/#(.*?)<\/ac:parameter>/is', $content, $bgMatch); + preg_match('/:(.*?):<\/ac:parameter>/is', $content, $iconMatch); + preg_match('/]*>(.*?)<\/ac:rich-text-body>/is', $content, $bodyMatch); + + $bgColor = $bgMatch[1] ?? ''; + $icon = $iconMatch[1] ?? ''; + $body = $bodyMatch[1] ?? $content; + + return sprintf( + '
%s
', + htmlspecialchars($bgColor, ENT_QUOTES), + htmlspecialchars($icon, ENT_QUOTES), + $body + ); + }, + $haystack + ); + } +} diff --git a/src/MacroReplacer/StructuredMacroReplacer.php b/src/MacroReplacer/StructuredMacroReplacer.php index d5c7b1a..146bdbc 100755 --- a/src/MacroReplacer/StructuredMacroReplacer.php +++ b/src/MacroReplacer/StructuredMacroReplacer.php @@ -1,24 +1,29 @@ - with
with class - */ -class StructuredMacroReplacer implements MacroReplacerInterface -{ - public function replace(string $haystack): string - { - return preg_replace_callback( - '/]*>(.*?)<\/ac:structured-macro>/is', - function ($match) { - $macroName = $match[1]; - $macroContent = $match[2]; - return '
' . $macroContent . '
'; - }, - $haystack - ); - } -} + with
with class + */ +class StructuredMacroReplacer implements MacroReplacerInterface +{ + public function replace(string $haystack): string + { + return preg_replace_callback( + '/]*>(.*?)<\/ac:structured-macro>/is', + function ($match) { + $macroName = $match[1]; + $macroContent = $match[2]; + + if (preg_match('/]*>(.*?)<\/ac:rich-text-body>/is', $macroContent, $inner)) { + $macroContent = $inner[1]; + } + + return sprintf('
%s
', $macroName, $macroContent); + }, + $haystack + ); + } +}