Skip to content

Commit 8f73f14

Browse files
author
Martin Brecht-Precht
committed
Added CommentBlock handling.
1 parent 5ad4982 commit 8f73f14

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"require": {
2626
"php": ">=5.3",
27-
"markdom/handler-interface": "^1.0.2",
27+
"markdom/handler-interface": "^1.0.3",
2828
"markenwerk/stack-util": "~1.0",
2929
"markenwerk/string-builder": "~1.0",
3030
"markenwerk/json-pretty-printer": "~1.0"

src/Handler/PhpObjectHandler.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ public function onCodeBlock($code, $hint = null)
9090
);
9191
}
9292

93+
/**
94+
* @param string $comment
95+
* @return void
96+
*/
97+
public function onCommentBlock($comment)
98+
{
99+
$parent = $this->blockParents->get();
100+
$parent->blocks[] = (object)array(
101+
KeyNameTranslator::ATTRIBUTE_COMMON_TYPE => KeyNameTranslator::TYPE_COMMENT,
102+
KeyNameTranslator::ATTRIBUTE_COMMENT_COMMENT => $comment,
103+
);
104+
}
105+
93106
/**
94107
* @return void
95108
*/

src/Handler/TypeNameTranslator/KeyNameTranslator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ final class KeyNameTranslator
1212

1313
const TYPE_DOCUMENT = 'Document';
1414
const TYPE_CODE = 'Code';
15+
const TYPE_COMMENT = 'Comment';
1516
const TYPE_DIVISION = 'Division';
1617
const TYPE_HEADING = 'Heading';
1718
const TYPE_UNORDERED_LIST = 'UnorderedList';
@@ -35,6 +36,7 @@ final class KeyNameTranslator
3536
const ATTRIBUTE_DOCUMENT_VERSION_MINOR = 'minor';
3637
const ATTRIBUTE_CODE_CODE = 'code';
3738
const ATTRIBUTE_CODE_HINT = 'hint';
39+
const ATTRIBUTE_COMMENT_COMMENT = 'comment';
3840
const ATTRIBUTE_HEADING_LEVEL = 'level';
3941
const ATTRIBUTE_ORDERED_LIST_START_INDEX = 'startIndex';
4042
const ATTRIBUTE_IMAGE_URI = 'uri';

src/Handler/XmlHandler.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ public function onCodeBlock($code, $hint = null)
123123
$parent->appendChild($codeNode);
124124
}
125125

126+
/**
127+
* @param string $comment
128+
* @return void
129+
*/
130+
public function onCommentBlock($comment)
131+
{
132+
$commentNode = $this->document->createElement(KeyNameTranslator::TYPE_COMMENT);
133+
if (!empty($comment)) {
134+
$commentNode->appendChild($this->createTextNode($comment));
135+
}
136+
/** @var \DOMElement $parent */
137+
$parent = $this->blockParents->get();
138+
$parent->appendChild($commentNode);
139+
}
140+
126141
/**
127142
* @return void
128143
*/

0 commit comments

Comments
 (0)