File tree 2 files changed +56
-1
lines changed
2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -12,4 +12,42 @@ composer require divineomega/php-wikitext-parser
12
12
13
13
## Usage
14
14
15
- TODO
15
+ The most basic usage is to convert a Wikitext formatted
16
+ string to plain text.
17
+
18
+ ``` php
19
+ $plainText = (new WikitextParser())
20
+ ->setWikitext($wikitext)
21
+ ->parse();
22
+ ```
23
+
24
+ ### Alternative Format
25
+
26
+ You are also able to specify alternative formats to
27
+ convert to, using the ` setFormat ` method. By default,
28
+ this is set to plain text.
29
+
30
+ For example, you can convert Wikitext to HTML, as shown
31
+ below.
32
+
33
+ ``` php
34
+ $plainText = (new WikitextParser())
35
+ ->setWikitext($wikitext)
36
+ ->setFormat(Format::HTML)
37
+ ->parse();
38
+ ```
39
+
40
+ ### Caching
41
+
42
+ By default, file caching is used. If you wish, you can
43
+ specify any PSR-6 compliant caching library. This is
44
+ done using the ` setCache ` method as should below.
45
+
46
+ ``` php
47
+ $cache = new OtherPsr6CacheItemPool();
48
+
49
+ $plainText = (new WikitextParser())
50
+ ->setCache($cache)
51
+ ->setWikitext($wikitext)
52
+ ->parse();
53
+ ```
Original file line number Diff line number Diff line change @@ -26,12 +26,24 @@ public function __construct()
26
26
$ this ->setCache ($ cacheItemPool );
27
27
}
28
28
29
+ /**
30
+ * Set an alternative PSR-6 compliant cache item pool.
31
+ *
32
+ * @param CacheItemPoolInterface $cacheItemPool
33
+ * @return $this
34
+ */
29
35
public function setCache (CacheItemPoolInterface $ cacheItemPool )
30
36
{
31
37
$ this ->cache = $ cacheItemPool ;
32
38
return $ this ;
33
39
}
34
40
41
+ /**
42
+ * Set the Wikitext to parse.
43
+ *
44
+ * @param string $wikitext
45
+ * @return Parser
46
+ */
35
47
public function setWikitext (string $ wikitext ) : Parser
36
48
{
37
49
$ this ->wikitext = $ wikitext ;
@@ -52,6 +64,11 @@ public function setFormat(string $format = Format::PLAIN_TEXT) : Parser
52
64
return $ this ;
53
65
}
54
66
67
+ /**
68
+ * Constructs the Wikitext parser URL.
69
+ *
70
+ * @return string
71
+ */
55
72
private function buildUrl ()
56
73
{
57
74
return $ this ->endpoint .$ this ->queryString .urlencode ($ this ->wikitext );
You can’t perform that action at this time.
0 commit comments