Skip to content

Commit 066296e

Browse files
author
Genert Org
committed
Add parser functionality
1 parent 9c5f0fc commit 066296e

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

CHANGELOG.MD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ All notable changes to this project will be documented in this file.
33

44
The project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
55

6+
## [1.0.1] - 2017-07-17
7+
### Added
8+
- Add parser functionality.
9+
10+
### Changed
11+
- Added more tests.
12+
- Minor code refactoring.
13+
614
## [1.0.0] - 2017-07-13

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ $bbCode->except('bold')->convertToHtml('[b]Bold[/b] [i]italic[/i]');
9898
$bbCode->except(['bold'])->convertToHtml('[b]Bold[/b] [i]italic[/i]');
9999
```
100100

101-
### `addParser(string $name, string $pattern, string $replace)`
101+
### `addParser(string $name, string $pattern, string $replace, string $content)`
102102
Add regex based BBCode parser to translate found pattern to desired one.
103103

104104
Example:
@@ -111,7 +111,8 @@ $bbCode = new BBCode();
111111
$bbCode->addParser(
112112
'custom-link',
113113
'/\[link target\=(.*?)\](.*?)\[\/link\]/s',
114-
'<a href="$1">$2</a>'
114+
'<a href="$1">$2</a>',
115+
'$1'
115116
);
116117

117118
// Output: '<a href="www.yourlinkhere.com">Text to be displayed</a>.'

src/BBCode.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ public function convertToHtml(string $text, $caseSensitive = null): string
5454
return $this->bbCodeParser->parse($text, $caseSensitive);
5555
}
5656

57-
public function addParser(string $name, string $pattern, string $replace)
57+
public function addParser(string $name, string $pattern, string $replace, string $content)
5858
{
59-
$this->bbCodeParser->addParser($name, $pattern, $replace);
59+
$this->bbCodeParser->addParser($name, $pattern, $replace, $content);
60+
61+
return $this;
6062
}
6163
}

src/Parser/Parser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ public function except($except = null)
4444
return $this;
4545
}
4646

47-
public function addParser(string $name, string $pattern, string $replace)
47+
public function addParser(string $name, string $pattern, string $replace, string $content)
4848
{
4949
$this->parsers[$name] = [
5050
'pattern' => $pattern,
5151
'replace' => $replace,
52+
'content' => $content,
5253
];
5354
}
5455
}

tests/ParserTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ public function testAddParser()
215215
$bbCode->addParser(
216216
'custom-link',
217217
'/\[link target\=(.*?)\](.*?)\[\/link\]/s',
218-
'<a href="$1">$2</a>'
218+
'<a href="$1">$2</a>',
219+
'$2'
219220
);
220221

221222
$this->assertEquals(

0 commit comments

Comments
 (0)