33namespace HalloWelt \MigrateConfluence \Converter \Processor ;
44
55use DOMDocument ;
6+ use DOMNode ;
67use HalloWelt \MigrateConfluence \Converter \IProcessor ;
78
89/**
1819 * ...
1920 * </ac:structured-macro>
2021 */
21- class DetailsMacro implements IProcessor {
22+ class DetailsMacro extends ConvertMacroToTemplateBase {
2223
2324 /**
2425 * @return string
@@ -30,61 +31,7 @@ protected function getMacroName(): string {
3031 /**
3132 * @inheritDoc
3233 */
33- public function process ( DOMDocument $ dom ): void {
34- $ macros = $ dom ->getElementsByTagName ( 'structured-macro ' );
35- $ requiredMacroName = $ this ->getMacroName ();
36-
37- // Collect all DOMElements in a non-live list
38- $ actualMacros = [];
39- foreach ( $ macros as $ macro ) {
40- $ macroName = $ macro ->getAttribute ( 'ac:name ' );
41- if ( $ macroName !== $ requiredMacroName ) {
42- continue ;
43- }
44- $ actualMacros [] = $ macro ;
45- }
46-
47- foreach ( $ actualMacros as $ actualMacro ) {
48- $ parentNode = $ actualMacro ->parentNode ;
49-
50- $ detailsDiv = $ dom ->createElement ( 'div ' );
51- $ detailsDiv ->setAttribute ( 'class ' , 'details ' );
52-
53- // Extract scalar parameters, store them as data attributes of 'div'
54- $ parameterEls = $ actualMacro ->getElementsByTagName ( 'parameter ' );
55- foreach ( $ parameterEls as $ parameterEl ) {
56- $ paramName = $ parameterEl ->getAttribute ( 'ac:name ' );
57- $ paramValue = $ parameterEl ->nodeValue ;
58-
59- $ detailsDiv ->setAttribute ( "data- $ paramName " , $ paramValue );
60- }
61-
62- // Extract rich text bodies
63- /** @var DOMNodeList $richTextBodies */
64- $ richTextBodies = $ actualMacro ->getElementsByTagName ( 'rich-text-body ' );
65- $ richTextBodyEls = [];
66- foreach ( $ richTextBodies as $ richTextBody ) {
67- $ richTextBodyEls [] = $ richTextBody ;
68- }
69-
70- if ( !empty ( $ richTextBodyEls ) ) {
71- foreach ( $ richTextBodyEls as $ richTextBodyEl ) {
72- // For some odd reason, iterating `$richTextBodyEl->childNodes` directly
73- // will give children of `$dom->firstChild`.
74- // Using `iterator_to_array` as an workaround here.
75- $ childNodes = iterator_to_array ( $ richTextBodyEl ->childNodes );
76- foreach ( $ childNodes as $ richTextBodyChildEl ) {
77- if ( $ richTextBodyChildEl === $ actualMacro ) {
78- continue ;
79- }
80- $ detailsDiv ->appendChild ( $ richTextBodyChildEl );
81- }
82- }
83- }
84-
85- $ parentNode ->insertBefore ( $ detailsDiv , $ actualMacro );
86-
87- $ parentNode ->removeChild ( $ actualMacro );
88- }
34+ protected function getWikiTextTemplateName (): string {
35+ return 'Details ' ;
8936 }
9037}
0 commit comments