Skip to content

Commit 3891e4b

Browse files
author
Martin Brecht-Precht
committed
Added the link attribute title.
1 parent e0b4c09 commit 3891e4b

File tree

7 files changed

+32
-10
lines changed

7 files changed

+32
-10
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.3",
27+
"markdom/handler-interface": "^1.0.4",
2828
"markenwerk/stack-util": "~1.0",
2929
"markenwerk/string-builder": "~1.0",
3030
"markenwerk/json-pretty-printer": "~1.0"

src/Dispatcher/EventDispatcher/SimpleMarkdomEventDispatcher.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ final class SimpleMarkdomEventDispatcher
5555
*/
5656
private $linkUriStack;
5757

58+
/**
59+
* @var Stack
60+
*/
61+
private $linkTitleStack;
62+
5863
/**
5964
* @param HandlerInterface $markdomHandler
6065
*/
@@ -67,6 +72,7 @@ public function __construct(HandlerInterface $markdomHandler)
6772
$this->orderedListStartIndexStack = new Stack();
6873
$this->emphasisLevelStack = new Stack();
6974
$this->linkUriStack = new Stack();
75+
$this->linkTitleStack = new Stack();
7076
$this->markdomHandler = $markdomHandler;
7177
}
7278

@@ -310,14 +316,16 @@ public function onLineBreakContent($hard)
310316

311317
/**
312318
* @param string $uri
319+
* @param string $title
313320
* @return void
314321
*/
315-
public function onLinkContentBegin($uri)
322+
public function onLinkContentBegin($uri, $title)
316323
{
317324
$this->onContentBegin(ContentType::TYPE_LINK);
318-
$this->markdomHandler->onLinkContentBegin($uri);
325+
$this->markdomHandler->onLinkContentBegin($uri, $title);
319326
$this->onContentsBegin();
320327
$this->linkUriStack->push($uri);
328+
$this->linkTitleStack->push($title);
321329
}
322330

323331
/**
@@ -326,7 +334,7 @@ public function onLinkContentBegin($uri)
326334
public function onLinkContentEnd()
327335
{
328336
$this->onContentsEnd();
329-
$this->markdomHandler->onLinkContentEnd($this->linkUriStack->pop());
337+
$this->markdomHandler->onLinkContentEnd($this->linkUriStack->pop(), $this->linkTitleStack->pop());
330338
$this->onContentEnd(ContentType::TYPE_LINK);
331339
}
332340

src/Dispatcher/PhpObjectDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private function processContents(array $contents)
175175
$this->eventDispatcher->onLineBreakContent($node->hard);
176176
break;
177177
case KeyNameTranslator::TYPE_LINK:
178-
$this->eventDispatcher->onLinkContentBegin($node->uri);
178+
$this->eventDispatcher->onLinkContentBegin($node->uri, $node->title);
179179
$this->processContents($node->contents);
180180
$this->eventDispatcher->onLinkContentEnd();
181181
break;

src/Dispatcher/XmlDispatcher.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,13 @@ private function processContents(\DOMNodeList $contents)
185185
);
186186
break;
187187
case KeyNameTranslator::TYPE_LINK:
188+
$title = null;
189+
if ($node->hasAttribute(KeyNameTranslator::ATTRIBUTE_LINK_TITLE)) {
190+
$title = $node->getAttribute(KeyNameTranslator::ATTRIBUTE_LINK_TITLE);
191+
}
188192
$this->eventDispatcher->onLinkContentBegin(
189-
$node->getAttribute(KeyNameTranslator::ATTRIBUTE_LINK_URI)
193+
$node->getAttribute(KeyNameTranslator::ATTRIBUTE_LINK_URI),
194+
$title
190195
);
191196
$this->processContents($node->childNodes);
192197
$this->eventDispatcher->onLinkContentEnd();

src/Handler/PhpObjectHandler.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,15 @@ public function onLineBreakContent($hard)
382382

383383
/**
384384
* @param string $uri
385+
* @param string $title
385386
* @return void
386387
*/
387-
public function onLinkContentBegin($uri)
388+
public function onLinkContentBegin($uri, $title)
388389
{
389390
$link = (object)array(
390391
KeyNameTranslator::ATTRIBUTE_COMMON_TYPE => KeyNameTranslator::TYPE_LINK,
391392
KeyNameTranslator::ATTRIBUTE_LINK_URI => $uri,
393+
KeyNameTranslator::ATTRIBUTE_LINK_TITLE => $title,
392394
KeyNameTranslator::ATTRIBUTE_COMMON_CONTENTS => array(),
393395
);
394396
$parent = $this->contentParents->get();
@@ -398,9 +400,10 @@ public function onLinkContentBegin($uri)
398400

399401
/**
400402
* @param string $uri
403+
* @param string $title
401404
* @return void
402405
*/
403-
public function onLinkContentEnd($uri)
406+
public function onLinkContentEnd($uri, $title)
404407
{
405408
$this->contentParents->pop();
406409
}

src/Handler/TypeNameTranslator/KeyNameTranslator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ final class KeyNameTranslator
4545
const ATTRIBUTE_EMPHASIS_LEVEL = 'level';
4646
const ATTRIBUTE_LINE_BREAK_HARD = 'hard';
4747
const ATTRIBUTE_LINK_URI = 'uri';
48+
const ATTRIBUTE_LINK_TITLE = 'title';
4849
const ATTRIBUTE_TEXT_TEXT = 'text';
4950

5051
}

src/Handler/XmlHandler.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,18 @@ public function onLineBreakContent($hard)
417417

418418
/**
419419
* @param string $uri
420+
* @param string $title
420421
* @return void
421422
*/
422-
public function onLinkContentBegin($uri)
423+
public function onLinkContentBegin($uri, $title)
423424
{
424425
$linkNode = $this->document->createElement(KeyNameTranslator::TYPE_LINK);
425426
$uriAttribute = $this->document->createAttribute(KeyNameTranslator::ATTRIBUTE_LINK_URI);
426427
$uriAttribute->appendChild($this->document->createTextNode($uri));
427428
$linkNode->appendChild($uriAttribute);
429+
$titleAttribute = $this->document->createAttribute(KeyNameTranslator::ATTRIBUTE_LINK_TITLE);
430+
$titleAttribute->appendChild($this->document->createTextNode($title));
431+
$linkNode->appendChild($titleAttribute);
428432
/** @var \DOMElement $parent */
429433
$parent = $this->contentParents->get();
430434
$parent->appendChild($linkNode);
@@ -433,9 +437,10 @@ public function onLinkContentBegin($uri)
433437

434438
/**
435439
* @param string $uri
440+
* @param string $title
436441
* @return void
437442
*/
438-
public function onLinkContentEnd($uri)
443+
public function onLinkContentEnd($uri, $title)
439444
{
440445
$this->contentParents->pop();
441446
}

0 commit comments

Comments
 (0)