Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Composer/_defaultpages/Template/ExcerptEnd

This file was deleted.

2 changes: 0 additions & 2 deletions src/Composer/_defaultpages/Template/ExcerptStart

This file was deleted.

2 changes: 2 additions & 0 deletions src/Converter/ConfluenceConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use HalloWelt\MigrateConfluence\Converter\Postprocessor\FixMultilineTable;
use HalloWelt\MigrateConfluence\Converter\Postprocessor\FixMultilineTemplate;
use HalloWelt\MigrateConfluence\Converter\Postprocessor\NestedHeadings;
use HalloWelt\MigrateConfluence\Converter\Postprocessor\RestoreExcerptBlock;
use HalloWelt\MigrateConfluence\Converter\Postprocessor\RestorePStyleTag;
use HalloWelt\MigrateConfluence\Converter\Postprocessor\RestoreTimeTag;
use HalloWelt\MigrateConfluence\Converter\Postprocessor\TasksReportMacro as RestoreTasksReportMacro;
Expand Down Expand Up @@ -398,6 +399,7 @@ private function runProcessors( DOMDocument $dom ): void {
private function runPostProcessors(): void {
$postProcessors = [
new RestorePStyleTag(),
new RestoreExcerptBlock(),
new RestoreTimeTag(),
new FixLineBreakInHeadings(),
new FixImagesWithExternalUrl(),
Expand Down
24 changes: 24 additions & 0 deletions src/Converter/Postprocessor/RestoreExcerptBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace HalloWelt\MigrateConfluence\Converter\Postprocessor;

use HalloWelt\MigrateConfluence\Converter\IPostprocessor;

class RestoreExcerptBlock implements IPostprocessor {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check other names in post processors that handle macros. You will find at least TasksReportMacro. Stick to naming convention

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


/**
* @inheritDoc
*/
public function postprocess( string $wikiText ): string {
return preg_replace_callback(
'/#####EXCERPTBLOCKOPEN\|(.*?)\|(.*?)#####(.*?)#####EXCERPTBLOCKCLOSE#####/si',
static function ( $matches ) {
$name = $matches[1];
$hidden = $matches[2];
$content = $matches[3];
return "<excerpt-block name=\"$name\" hidden=\"$hidden\">$content</excerpt-block>";
Comment thread
danielriedmueller marked this conversation as resolved.
},
$wikiText
);
}
}
56 changes: 46 additions & 10 deletions src/Converter/Processor/ExcerptMacro.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

namespace HalloWelt\MigrateConfluence\Converter\Processor;

use DOMNode;

/**
* Converts the Confluence excerpt macro to a BlueSpice <excerpt-block> element.
* The broken macro category is added because the BlueSpice Excerpt extension is not yet available.
*
* @see https://confluence.atlassian.com/doc/excerpt-macro-148062.html
* @see https://docs.atlassian.com/DAC/javadoc/confluence/4.0/reference/com/atlassian/confluence/macro/Macro.OutputType.html
*/
class ExcerptMacro extends ConvertMacroToTemplateWithBodyBase {
class ExcerptMacro extends StructuredMacroProcessorBase {

/**
* @inheritDoc
Expand All @@ -17,15 +21,47 @@ protected function getMacroName(): string {

/**
* @inheritDoc
*
* Pandoc strips unknown HTML elements like <excerpt-block> when converting to MediaWiki
* format. To preserve the tag, we insert text placeholders around the content here and
* restore the actual <excerpt-block> tag in the RestoreExcerptBlock postprocessor.
* Placeholders use pipe-separated values to avoid HTML attribute quote encoding issues.
*/
protected function getWikiTextTemplateStartName(): string {
return 'ExcerptStart';
}
protected function doProcessMacro( DOMNode $node ): void {
$macroId = $node->getAttribute( 'ac:macro-id' );
$hidden = 'false';

/**
* @inheritDoc
*/
protected function getWikiTextTemplateEndName(): string {
return 'ExcerptEnd';
foreach ( $node->childNodes as $childNode ) {
if ( $childNode->nodeName === 'ac:parameter'
&& $childNode->getAttribute( 'ac:name' ) === 'hidden' ) {
$hidden = trim( $childNode->nodeValue );
break;
}
}

$parent = $node->parentNode;

$openTag = $node->ownerDocument->createTextNode(
"#####EXCERPTBLOCKOPEN|$macroId|$hidden#####"
);
$parent->insertBefore( $openTag, $node );

foreach ( $node->childNodes as $childNode ) {
if ( $childNode->nodeName === 'ac:rich-text-body' ) {
foreach ( iterator_to_array( $childNode->childNodes ) as $bodyChild ) {
$parent->insertBefore( $bodyChild->cloneNode( true ), $node );
}
}
}

$closeTag = $node->ownerDocument->createTextNode( '#####EXCERPTBLOCKCLOSE#####' );
$parent->insertBefore( $closeTag, $node );

$brokenCategory = $node->ownerDocument->createTextNode(
$this->getBrokenMacroCategory()
);
$parent->insertBefore( $brokenCategory, $node );

$parent->removeChild( $node );
}
}
2 changes: 1 addition & 1 deletion tests/phpunit/data/excerpt-macro-input.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<xml xmlns:ac="sample_namespace" xmlns:ri="sample_second_namespace">
<ac:structured-macro ac:name="excerpt">
<ac:structured-macro ac:name="excerpt" ac:macro-id="b50b3cdb-e32a-447c-8c42-7be043c457ce">
<ac:parameter ac:name="hidden">true</ac:parameter>
<ac:parameter ac:name="atlassian-macro-output-type">BLOCK</ac:parameter>
<ac:rich-text-body>
Expand Down
7 changes: 2 additions & 5 deletions tests/phpunit/data/excerpt-macro-output.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0"?>
<xml xmlns:ac="sample_namespace" xmlns:ri="sample_second_namespace">
{{ExcerptStart###BREAK###
|hidden = true###BREAK###
|atlassian-macro-output-type = BLOCK###BREAK###
}}
#####EXCERPTBLOCKOPEN|b50b3cdb-e32a-447c-8c42-7be043c457ce|true#####
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion it is better to name the params. It could be that one of the params is not set and then you may have a problem with assignment

<p>This is the <strong>text</strong> I want to reuse in other pages. This text is inside an Excerpt macro.</p>
{{ExcerptEnd}}
#####EXCERPTBLOCKCLOSE#####[[Category:Broken_macro/excerpt]]
</xml>
Loading