Skip to content

Commit 002af4b

Browse files
author
Adam McCann
committed
Fixed offset bug with formatting
Updated test
1 parent c2316d9 commit 002af4b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Components/Formats.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,22 @@ public function __construct(stdClass $json, DOMDocument $dom, DOMElement $paragr
8888
*/
8989
public function render()
9090
{
91+
$offset = 0;
92+
9193
foreach ($this->formats as $format) {
9294

9395
$attrs = $this->attributes($format->type, (! empty($format->attrs) ? $format->attrs : null));
9496

9597
$opening = '<' . $format->type . "$attrs>";
9698
$closing = '</' . $format->type . '>';
9799

98-
$this->text = substr_replace($this->text, $opening, $format->from, 0);
99-
$this->text = substr_replace($this->text, $closing, $format->to + strlen($opening), 0);
100+
$this->text = substr_replace($this->text, $opening, $format->from + $offset, 0);
101+
102+
$offset += strlen($opening);
103+
104+
$this->text = substr_replace($this->text, $closing, $format->to + $offset, 0);
105+
106+
$offset += strlen($closing);
100107
}
101108

102109
// create a temporary document and load the plain html

tests/ConverterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testConvertsJsonToHtml()
3131

3232
$output = $converter->convert($input);
3333

34-
$expected = "<section><div class=\"article__section__aligned\"><figure><div class=\"image-container\"><img src=\"https://www.googleapis.com/download/storage/v1/b/carbon-demo-user-uploads/o/selfie-1462838229973?generation=1462838231280000&amp;alt=media\"></div><figcaption>Uploaded to GCS Bucket, this is temp for demo sake and uploaded images will be deleted regularly.</figcaption></figure></div><div class=\"article__section--gutter\"><h3>The blurring between genres is embodied by your character, a sleeper agent in The Division &ndash; a clandestine task force to restore order when all else fails &ndash; activated after a virus is released in New York, decimating the city and surrounding area. At character creation you go 'Ah yes, an RPG,' but then realise your choice is from a stock set of approximately 16 faces, all of which are a bit amorphous, as if they were molded from brie and then left in the sun.</h3><p>In game your agent is a stoic soldier, trained to dispassionately kill thugs who were once their fellow citizens and never once speaking, so you go 'Ah yes, a shooter.' Except you can also customise their entire outfit, separate to their combat gear, with clothes as described by someone's dad: 'trendy military jacket', 'cool waterproof boots', so you go 'Ah yes, an RPG,' again, before you get to grips with the classless class system, which is decidedly not like an RPG.</p><p><p>Rather t<a href=\"http://www.google.com\" rel=\"nofollow\">han</a> locking your character into one class, you can change your role on the fly by using the interaction between your gear and abilities. The combat gear has different scores which directly change what your character is best at, which, despite being a complex system, works really well in game. Skills (the abilities you can actively trigger in combat) are also well designed to balance with different roles, and, as is the case with the most fun bits of any game, are <em>ridiculous</em>. Aside from area of effect healing and portable cover, you can get yourself a riot shield that heals you as it gets shot, or a sticky bomb that fires long distances and attaches to/explodes that bastard sniper. Having different skills mapped completely changes how you play.</p></p><p>This has all been done in the name of good multiplayer, and it's worked: the multiplayer in The Division is probably the most fun multiplayer has been for literally years. The shining light of the whole game is the PvP in the Dark Zone.</p><p><p>It's in the Dark Zone that you run into other players, and all bets are off. The NPC enemies are tougher too, and you'll often find yourself teaming up with these unknown agents to take them down for the higher level loot. Dark Zone loot is more valuable than loot from outside, and at any point those dudes you were working with a second ago could suddenly decide maybe <em>they</em> want what you've got.</p></p><p>You'll often find groups of hostile players camping around the extraction points. You start to eye up other players suspiciously by default; you can even be fired upon accidentally if a twitchy agent mistakes you for an NPC, and then everything has to be diffused with a hand wave or salute emote. There's proximity voice chat if you all have your mics turned on, leading to heavily accented and tentative hellos, congratulations on stylish kills, and agreements to cover one another on the extraction. It is, genuinely, fantastic, and the unpredictable nature of the Dark Zone is what makes it so.</p><p>In comparison the PvE missions can be fatiguing, boiling down to shooting increasingly difficult waves of enemies, no matter if it's dressed up as a hostage situation or a main story mission. The emphasis is on cover shooting, and while the cover system is great the actual shooting still feels like firing nerf darts at mannequins.</p><p></p><p></p></div></section>";
34+
$expected = "<section><div class=\"article__section__aligned\"><figure><div class=\"image-container\"><img src=\"https://www.googleapis.com/download/storage/v1/b/carbon-demo-user-uploads/o/selfie-1462838229973?generation=1462838231280000&amp;alt=media\"></div><figcaption>Uploaded to GCS Bucket, this is temp for demo sake and uploaded images will be deleted regularly.</figcaption></figure></div><div class=\"article__section--gutter\"><h3>The blurring between genres is embodied by your character, a sleeper agent in The Division &ndash; a clandestine task force to restore order when all else fails &ndash; activated after a virus is released in New York, decimating the city and surrounding area. At character creation you go 'Ah yes, an RPG,' but then realise your choice is from a stock set of approximately 16 faces, all of which are a bit amorphous, as if they were molded from brie and then left in the sun.</h3><p>In game your agent is a stoic soldier, trained to dispassionately kill thugs who were once their fellow citizens and never once speaking, so you go 'Ah yes, a shooter.' Except you can also customise their entire outfit, separate to their combat gear, with clothes as described by someone's dad: 'trendy military jacket', 'cool waterproof boots', so you go 'Ah yes, an RPG,' again, before you get to grips with the classless class system, which is decidedly not like an RPG.</p><p><p>Rather than locki<a href=\"http://www.google.com\" rel=\"nofollow\">ng </a>your character into one class, you can change your role on the fly by using the interaction between your gear and abilities. The combat gear has different scores which directly change what your character is best at, which, despite being a complex system, works really well in game. Skills (the abilities you can actively trigger in combat) are also well designed to balance with different roles, and, as is the case with the most fun bits of any game, are <em>ridiculous</em>. Aside from area of effect healing and portable cover, you can get yourself a riot shield that heals you as it gets shot, or a sticky bomb that fires long distances and attaches to/explodes that bastard sniper. Having different skills mapped completely changes how you play.</p></p><p>This has all been done in the name of good multiplayer, and it's worked: the multiplayer in The Division is probably the most fun multiplayer has been for literally years. The shining light of the whole game is the PvP in the Dark Zone.</p><p><p>It's in the Dark Zone that you run into other players, and all bets are off. The NPC enemies are tougher too, and you'll often find yourself teaming up with these unknown agents to take them down for the higher level loot. Dark Zone loot is more valuable than loot from outside, and at any point those dudes you were working with a second ago could suddenly decide maybe <em>they</em> want what you've got.</p></p><p>You'll often find groups of hostile players camping around the extraction points. You start to eye up other players suspiciously by default; you can even be fired upon accidentally if a twitchy agent mistakes you for an NPC, and then everything has to be diffused with a hand wave or salute emote. There's proximity voice chat if you all have your mics turned on, leading to heavily accented and tentative hellos, congratulations on stylish kills, and agreements to cover one another on the extraction. It is, genuinely, fantastic, and the unpredictable nature of the Dark Zone is what makes it so.</p><p>In comparison the PvE missions can be fatiguing, boiling down to shooting increasingly difficult waves of enemies, no matter if it's dressed up as a hostage situation or a main story mission. The emphasis is on cover shooting, and while the cover system is great the actual shooting still feels like firing nerf darts at mannequins.</p><p></p><p></p></div></section>";
3535

3636
$this->assertSame($expected, $output);
3737
}

0 commit comments

Comments
 (0)