File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Expand file tree Collapse file tree 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
1212
1313## Usage
1414
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()
2626 $ this ->setCache ($ cacheItemPool );
2727 }
2828
29+ /**
30+ * Set an alternative PSR-6 compliant cache item pool.
31+ *
32+ * @param CacheItemPoolInterface $cacheItemPool
33+ * @return $this
34+ */
2935 public function setCache (CacheItemPoolInterface $ cacheItemPool )
3036 {
3137 $ this ->cache = $ cacheItemPool ;
3238 return $ this ;
3339 }
3440
41+ /**
42+ * Set the Wikitext to parse.
43+ *
44+ * @param string $wikitext
45+ * @return Parser
46+ */
3547 public function setWikitext (string $ wikitext ) : Parser
3648 {
3749 $ this ->wikitext = $ wikitext ;
@@ -52,6 +64,11 @@ public function setFormat(string $format = Format::PLAIN_TEXT) : Parser
5264 return $ this ;
5365 }
5466
67+ /**
68+ * Constructs the Wikitext parser URL.
69+ *
70+ * @return string
71+ */
5572 private function buildUrl ()
5673 {
5774 return $ this ->endpoint .$ this ->queryString .urlencode ($ this ->wikitext );
You can’t perform that action at this time.
0 commit comments