ParsedownTest.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. <?php
  2. use Codeception\Util\Fixtures;
  3. use Grav\Common\Grav;
  4. use Grav\Common\Uri;
  5. use Grav\Common\Config\Config;
  6. use Grav\Common\Page\Pages;
  7. use Grav\Common\Markdown\Parsedown;
  8. use Grav\Common\Language\Language;
  9. /**
  10. * Class ParsedownTest
  11. */
  12. class ParsedownTest extends \Codeception\TestCase\Test
  13. {
  14. /** @var Parsedown $parsedown */
  15. protected $parsedown;
  16. /** @var Grav $grav */
  17. protected $grav;
  18. /** @var Pages $pages */
  19. protected $pages;
  20. /** @var Config $config */
  21. protected $config;
  22. /** @var Uri $uri */
  23. protected $uri;
  24. /** @var Language $language */
  25. protected $language;
  26. protected $old_home;
  27. protected function _before()
  28. {
  29. $grav = Fixtures::get('grav');
  30. $this->grav = $grav();
  31. $this->pages = $this->grav['pages'];
  32. $this->config = $this->grav['config'];
  33. $this->uri = $this->grav['uri'];
  34. $this->language = $this->grav['language'];
  35. $this->old_home = $this->config->get('system.home.alias');
  36. $this->config->set('system.home.alias', '/item1');
  37. $this->config->set('system.absolute_urls', false);
  38. $this->config->set('system.languages.supported', []);
  39. unset($this->grav['language']);
  40. $this->grav['language'] = new Language($this->grav);
  41. /** @var UniformResourceLocator $locator */
  42. $locator = $this->grav['locator'];
  43. $locator->addPath('page', '', 'tests/fake/nested-site/user/pages', false);
  44. $this->pages->init();
  45. $defaults = [
  46. 'extra' => false,
  47. 'auto_line_breaks' => false,
  48. 'auto_url_links' => false,
  49. 'escape_markup' => false,
  50. 'special_chars' => ['>' => 'gt', '<' => 'lt'],
  51. ];
  52. $page = $this->pages->dispatch('/item2/item2-2');
  53. $this->parsedown = new Parsedown($page, $defaults);
  54. }
  55. protected function _after()
  56. {
  57. $this->config->set('system.home.alias', $this->old_home);
  58. }
  59. public function testImages()
  60. {
  61. $this->config->set('system.languages.supported', ['fr','en']);
  62. unset($this->grav['language']);
  63. $this->grav['language'] = new Language($this->grav);
  64. $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
  65. $this->assertSame('<p><img alt="" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  66. $this->parsedown->text('![](sample-image.jpg)'));
  67. $this->assertRegexp('|<p><img alt="" src="\/images\/.*-cache-image.jpe?g\?foo=1" \/><\/p>|',
  68. $this->parsedown->text('![](cache-image.jpg?cropResize=200,200&foo)'));
  69. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  70. $this->assertSame('<p><img alt="" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  71. $this->parsedown->text('![](sample-image.jpg)'));
  72. $this->assertRegexp('|<p><img alt="" src="\/images\/.*-cache-image.jpe?g\?foo=1" \/><\/p>|',
  73. $this->parsedown->text('![](cache-image.jpg?cropResize=200,200&foo)'));
  74. $this->assertRegexp('|<p><img alt="" src="\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  75. $this->parsedown->text('![](/home-cache-image.jpg?cache)'));
  76. $this->assertSame('<p><img src="/item2/item2-2/missing-image.jpg" alt="" /></p>',
  77. $this->parsedown->text('![](missing-image.jpg)'));
  78. $this->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
  79. $this->parsedown->text('![](/home-missing-image.jpg)'));
  80. $this->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
  81. $this->parsedown->text('![](/home-missing-image.jpg)'));
  82. $this->assertSame('<p><img src="https://getgrav-grav.netdna-ssl.com/user/pages/media/grav-logo.svg" alt="" /></p>',
  83. $this->parsedown->text('![](https://getgrav-grav.netdna-ssl.com/user/pages/media/grav-logo.svg)'));
  84. }
  85. public function testImagesSubDir()
  86. {
  87. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  88. $this->assertRegexp('|<p><img alt="" src="\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  89. $this->parsedown->text('![](/home-cache-image.jpg?cache)'));
  90. $this->assertSame('<p><img alt="" src="/subdir/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  91. $this->parsedown->text('![](sample-image.jpg)'));
  92. $this->assertRegexp('|<p><img alt="" src="\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
  93. $this->parsedown->text('![](cache-image.jpg?cache)'));
  94. $this->assertSame('<p><img src="/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
  95. $this->parsedown->text('![](missing-image.jpg)'));
  96. $this->assertSame('<p><img src="/subdir/home-missing-image.jpg" alt="" /></p>',
  97. $this->parsedown->text('![](/home-missing-image.jpg)'));
  98. }
  99. public function testImagesAbsoluteUrls()
  100. {
  101. $this->config->set('system.absolute_urls', true);
  102. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  103. $this->assertSame('<p><img alt="" src="http://testing.dev/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  104. $this->parsedown->text('![](sample-image.jpg)'));
  105. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/images\/.*-cache-image.jpe?g" \/><\/p>|',
  106. $this->parsedown->text('![](cache-image.jpg?cache)'));
  107. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  108. $this->parsedown->text('![](/home-cache-image.jpg?cache)'));
  109. $this->assertSame('<p><img src="http://testing.dev/item2/item2-2/missing-image.jpg" alt="" /></p>',
  110. $this->parsedown->text('![](missing-image.jpg)'));
  111. $this->assertSame('<p><img src="http://testing.dev/home-missing-image.jpg" alt="" /></p>',
  112. $this->parsedown->text('![](/home-missing-image.jpg)'));
  113. }
  114. public function testImagesSubDirAbsoluteUrls()
  115. {
  116. $this->config->set('system.absolute_urls', true);
  117. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  118. $this->assertSame('<p><img alt="" src="http://testing.dev/subdir/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  119. $this->parsedown->text('![](sample-image.jpg)'));
  120. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
  121. $this->parsedown->text('![](cache-image.jpg?cache)'));
  122. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  123. $this->parsedown->text('![](/home-cache-image.jpg?cropResize=200,200)'));
  124. $this->assertSame('<p><img src="http://testing.dev/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
  125. $this->parsedown->text('![](missing-image.jpg)'));
  126. $this->assertSame('<p><img src="http://testing.dev/subdir/home-missing-image.jpg" alt="" /></p>',
  127. $this->parsedown->text('![](/home-missing-image.jpg)'));
  128. }
  129. public function testImagesAttributes()
  130. {
  131. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  132. $this->assertSame('<p><img title="My Title" alt="" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  133. $this->parsedown->text('![](sample-image.jpg "My Title")'));
  134. $this->assertSame('<p><img alt="" class="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  135. $this->parsedown->text('![](sample-image.jpg?classes=foo)'));
  136. $this->assertSame('<p><img alt="" class="foo bar" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  137. $this->parsedown->text('![](sample-image.jpg?classes=foo,bar)'));
  138. $this->assertSame('<p><img alt="" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  139. $this->parsedown->text('![](sample-image.jpg?id=foo)'));
  140. $this->assertSame('<p><img alt="Alt Text" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  141. $this->parsedown->text('![Alt Text](sample-image.jpg?id=foo)'));
  142. $this->assertSame('<p><img alt="Alt Text" class="bar" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  143. $this->parsedown->text('![Alt Text](sample-image.jpg?class=bar&id=foo)'));
  144. $this->assertSame('<p><img title="My Title" alt="Alt Text" class="bar" id="foo" src="/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  145. $this->parsedown->text('![Alt Text](sample-image.jpg?class=bar&id=foo "My Title")'));
  146. }
  147. public function testRootImages()
  148. {
  149. $this->uri->initializeWithURL('http://testing.dev/')->init();
  150. $defaults = [
  151. 'extra' => false,
  152. 'auto_line_breaks' => false,
  153. 'auto_url_links' => false,
  154. 'escape_markup' => false,
  155. 'special_chars' => ['>' => 'gt', '<' => 'lt'],
  156. ];
  157. $page = $this->pages->dispatch('/');
  158. $this->parsedown = new Parsedown($page, $defaults);
  159. $this->assertSame('<p><img alt="" src="/tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg" /></p>',
  160. $this->parsedown->text('![](home-sample-image.jpg)'));
  161. $this->assertRegexp('|<p><img alt="" src="\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  162. $this->parsedown->text('![](home-cache-image.jpg?cache)'));
  163. $this->assertRegexp('|<p><img alt="" src="\/images\/.*-home-cache-image.jpe?g\?foo=1" \/><\/p>|',
  164. $this->parsedown->text('![](home-cache-image.jpg?cropResize=200,200&foo)'));
  165. $this->assertSame('<p><img src="/home-missing-image.jpg" alt="" /></p>',
  166. $this->parsedown->text('![](/home-missing-image.jpg)'));
  167. $this->config->set('system.languages.supported', ['fr','en']);
  168. unset($this->grav['language']);
  169. $this->grav['language'] = new Language($this->grav);
  170. $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
  171. $this->assertSame('<p><img alt="" src="/tests/fake/nested-site/user/pages/01.item1/home-sample-image.jpg" /></p>',
  172. $this->parsedown->text('![](home-sample-image.jpg)'));
  173. }
  174. public function testRootImagesSubDirAbsoluteUrls()
  175. {
  176. $this->config->set('system.absolute_urls', true);
  177. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  178. $this->assertSame('<p><img alt="" src="http://testing.dev/subdir/tests/fake/nested-site/user/pages/02.item2/02.item2-2/sample-image.jpg" /></p>',
  179. $this->parsedown->text('![](sample-image.jpg)'));
  180. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/subdir\/images\/.*-cache-image.jpe?g" \/><\/p>|',
  181. $this->parsedown->text('![](cache-image.jpg?cache)'));
  182. $this->assertRegexp('|<p><img alt="" src="http:\/\/testing.dev\/subdir\/images\/.*-home-cache-image.jpe?g" \/><\/p>|',
  183. $this->parsedown->text('![](/home-cache-image.jpg?cropResize=200,200)'));
  184. $this->assertSame('<p><img src="http://testing.dev/subdir/item2/item2-2/missing-image.jpg" alt="" /></p>',
  185. $this->parsedown->text('![](missing-image.jpg)'));
  186. $this->assertSame('<p><img src="http://testing.dev/subdir/home-missing-image.jpg" alt="" /></p>',
  187. $this->parsedown->text('![](/home-missing-image.jpg)'));
  188. }
  189. public function testRootAbsoluteLinks()
  190. {
  191. $this->uri->initializeWithURL('http://testing.dev/')->init();
  192. $defaults = [
  193. 'extra' => false,
  194. 'auto_line_breaks' => false,
  195. 'auto_url_links' => false,
  196. 'escape_markup' => false,
  197. 'special_chars' => ['>' => 'gt', '<' => 'lt'],
  198. ];
  199. $page = $this->pages->dispatch('/');
  200. $this->parsedown = new Parsedown($page, $defaults);
  201. $this->assertSame('<p><a href="/item1/item1-3">Down a Level</a></p>',
  202. $this->parsedown->text('[Down a Level](item1-3)'));
  203. $this->assertSame('<p><a href="/item2">Peer Page</a></p>',
  204. $this->parsedown->text('[Peer Page](../item2)'));
  205. $this->assertSame('<p><a href="/?foo=bar">With Query</a></p>',
  206. $this->parsedown->text('[With Query](?foo=bar)'));
  207. $this->assertSame('<p><a href="/foo:bar">With Param</a></p>',
  208. $this->parsedown->text('[With Param](/foo:bar)'));
  209. $this->assertSame('<p><a href="#foo">With Anchor</a></p>',
  210. $this->parsedown->text('[With Anchor](#foo)'));
  211. $this->config->set('system.languages.supported', ['fr','en']);
  212. unset($this->grav['language']);
  213. $this->grav['language'] = new Language($this->grav);
  214. $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
  215. $this->assertSame('<p><a href="/fr/item2">Peer Page</a></p>',
  216. $this->parsedown->text('[Peer Page](../item2)'));
  217. $this->assertSame('<p><a href="/fr/item1/item1-3">Down a Level</a></p>',
  218. $this->parsedown->text('[Down a Level](item1-3)'));
  219. $this->assertSame('<p><a href="/fr/?foo=bar">With Query</a></p>',
  220. $this->parsedown->text('[With Query](?foo=bar)'));
  221. $this->assertSame('<p><a href="/fr/foo:bar">With Param</a></p>',
  222. $this->parsedown->text('[With Param](/foo:bar)'));
  223. $this->assertSame('<p><a href="#foo">With Anchor</a></p>',
  224. $this->parsedown->text('[With Anchor](#foo)'));
  225. }
  226. public function testAnchorLinksLangRelativeUrls()
  227. {
  228. $this->config->set('system.languages.supported', ['fr','en']);
  229. unset($this->grav['language']);
  230. $this->grav['language'] = new Language($this->grav);
  231. $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
  232. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  233. $this->parsedown->text('[Current Anchor](#foo)'));
  234. $this->assertSame('<p><a href="/fr/#foo">Root Anchor</a></p>',
  235. $this->parsedown->text('[Root Anchor](/#foo)'));
  236. $this->assertSame('<p><a href="/fr/item2/item2-1#foo">Peer Anchor</a></p>',
  237. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  238. $this->assertSame('<p><a href="/fr/item2/item2-1#foo">Peer Anchor 2</a></p>',
  239. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  240. }
  241. public function testAnchorLinksLangAbsoluteUrls()
  242. {
  243. $this->config->set('system.absolute_urls', true);
  244. $this->config->set('system.languages.supported', ['fr','en']);
  245. unset($this->grav['language']);
  246. $this->grav['language'] = new Language($this->grav);
  247. $this->uri->initializeWithURL('http://testing.dev/fr/item2/item2-2')->init();
  248. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  249. $this->parsedown->text('[Current Anchor](#foo)'));
  250. $this->assertSame('<p><a href="http://testing.dev/fr/item2/item2-1#foo">Peer Anchor</a></p>',
  251. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  252. $this->assertSame('<p><a href="http://testing.dev/fr/item2/item2-1#foo">Peer Anchor 2</a></p>',
  253. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  254. $this->assertSame('<p><a href="http://testing.dev/fr/#foo">Root Anchor</a></p>',
  255. $this->parsedown->text('[Root Anchor](/#foo)'));
  256. }
  257. public function testExternalLinks()
  258. {
  259. $this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
  260. $this->parsedown->text('[cnn.com](http://www.cnn.com)'));
  261. $this->assertSame('<p><a href="https://www.google.com">google.com</a></p>',
  262. $this->parsedown->text('[google.com](https://www.google.com)'));
  263. $this->assertSame('<p><a href="https://github.com/getgrav/grav/issues/new?title=%5Badd-resource%5D%20New%20Plugin%2FTheme&body=Hello%20%2A%2AThere%2A%2A">complex url</a></p>',
  264. $this->parsedown->text('[complex url](https://github.com/getgrav/grav/issues/new?title=[add-resource]%20New%20Plugin/Theme&body=Hello%20**There**)'));
  265. }
  266. public function testExternalLinksSubDir()
  267. {
  268. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  269. $this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
  270. $this->parsedown->text('[cnn.com](http://www.cnn.com)'));
  271. $this->assertSame('<p><a href="https://www.google.com">google.com</a></p>',
  272. $this->parsedown->text('[google.com](https://www.google.com)'));
  273. }
  274. public function testExternalLinksSubDirAbsoluteUrls()
  275. {
  276. $this->config->set('system.absolute_urls', true);
  277. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  278. $this->assertSame('<p><a href="http://www.cnn.com">cnn.com</a></p>',
  279. $this->parsedown->text('[cnn.com](http://www.cnn.com)'));
  280. $this->assertSame('<p><a href="https://www.google.com">google.com</a></p>',
  281. $this->parsedown->text('[google.com](https://www.google.com)'));
  282. }
  283. public function testAnchorLinksRelativeUrls()
  284. {
  285. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  286. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  287. $this->parsedown->text('[Current Anchor](#foo)'));
  288. $this->assertSame('<p><a href="/#foo">Root Anchor</a></p>',
  289. $this->parsedown->text('[Root Anchor](/#foo)'));
  290. $this->assertSame('<p><a href="/item2/item2-1#foo">Peer Anchor</a></p>',
  291. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  292. $this->assertSame('<p><a href="/item2/item2-1#foo">Peer Anchor 2</a></p>',
  293. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  294. }
  295. public function testAnchorLinksAbsoluteUrls()
  296. {
  297. $this->config->set('system.absolute_urls', true);
  298. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  299. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  300. $this->parsedown->text('[Current Anchor](#foo)'));
  301. $this->assertSame('<p><a href="http://testing.dev/item2/item2-1#foo">Peer Anchor</a></p>',
  302. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  303. $this->assertSame('<p><a href="http://testing.dev/item2/item2-1#foo">Peer Anchor 2</a></p>',
  304. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  305. $this->assertSame('<p><a href="http://testing.dev/#foo">Root Anchor</a></p>',
  306. $this->parsedown->text('[Root Anchor](/#foo)'));
  307. }
  308. public function testAnchorLinksWithPortAbsoluteUrls()
  309. {
  310. $this->config->set('system.absolute_urls', true);
  311. $this->uri->initializeWithURL('http://testing.dev:8080/item2/item2-2')->init();
  312. $this->assertSame('<p><a href="http://testing.dev:8080/item2/item2-1#foo">Peer Anchor</a></p>',
  313. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  314. $this->assertSame('<p><a href="http://testing.dev:8080/item2/item2-1#foo">Peer Anchor 2</a></p>',
  315. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  316. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  317. $this->parsedown->text('[Current Anchor](#foo)'));
  318. $this->assertSame('<p><a href="http://testing.dev:8080/#foo">Root Anchor</a></p>',
  319. $this->parsedown->text('[Root Anchor](/#foo)'));
  320. }
  321. public function testAnchorLinksSubDirRelativeUrls()
  322. {
  323. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  324. $this->assertSame('<p><a href="/subdir/item2/item2-1#foo">Peer Anchor</a></p>',
  325. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  326. $this->assertSame('<p><a href="/subdir/item2/item2-1#foo">Peer Anchor 2</a></p>',
  327. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  328. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  329. $this->parsedown->text('[Current Anchor](#foo)'));
  330. $this->assertSame('<p><a href="/subdir/#foo">Root Anchor</a></p>',
  331. $this->parsedown->text('[Root Anchor](/#foo)'));
  332. }
  333. public function testAnchorLinksSubDirAbsoluteUrls()
  334. {
  335. $this->config->set('system.absolute_urls', true);
  336. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  337. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1#foo">Peer Anchor</a></p>',
  338. $this->parsedown->text('[Peer Anchor](../item2-1#foo)'));
  339. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1#foo">Peer Anchor 2</a></p>',
  340. $this->parsedown->text('[Peer Anchor 2](../item2-1/#foo)'));
  341. $this->assertSame('<p><a href="#foo">Current Anchor</a></p>',
  342. $this->parsedown->text('[Current Anchor](#foo)'));
  343. $this->assertSame('<p><a href="http://testing.dev/subdir/#foo">Root Anchor</a></p>',
  344. $this->parsedown->text('[Root Anchor](/#foo)'));
  345. }
  346. public function testSlugRelativeLinks()
  347. {
  348. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  349. $this->assertSame('<p><a href="/">Up to Root Level</a></p>',
  350. $this->parsedown->text('[Up to Root Level](../..)'));
  351. $this->assertSame('<p><a href="/item2/item2-1">Peer Page</a></p>',
  352. $this->parsedown->text('[Peer Page](../item2-1)'));
  353. $this->assertSame('<p><a href="/item2/item2-2/item2-2-1">Down a Level</a></p>',
  354. $this->parsedown->text('[Down a Level](item2-2-1)'));
  355. $this->assertSame('<p><a href="/item2">Up a Level</a></p>',
  356. $this->parsedown->text('[Up a Level](..)'));
  357. $this->assertSame('<p><a href="/item3/item3-3">Up and Down</a></p>',
  358. $this->parsedown->text('[Up and Down](../../item3/item3-3)'));
  359. $this->assertSame('<p><a href="/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
  360. $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
  361. $this->assertSame('<p><a href="/item2?foo=bar">Up a Level with Query</a></p>',
  362. $this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
  363. $this->assertSame('<p><a href="/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
  364. $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
  365. $this->assertSame('<p><a href="/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
  366. $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
  367. $this->assertSame('<p><a href="/item3/item3-3#foo">Up and Down with Anchor</a></p>',
  368. $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
  369. }
  370. public function testSlugRelativeLinksAbsoluteUrls()
  371. {
  372. $this->config->set('system.absolute_urls', true);
  373. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  374. $this->assertSame('<p><a href="http://testing.dev/item2/item2-1">Peer Page</a></p>',
  375. $this->parsedown->text('[Peer Page](../item2-1)'));
  376. $this->assertSame('<p><a href="http://testing.dev/item2/item2-2/item2-2-1">Down a Level</a></p>',
  377. $this->parsedown->text('[Down a Level](item2-2-1)'));
  378. $this->assertSame('<p><a href="http://testing.dev/item2">Up a Level</a></p>',
  379. $this->parsedown->text('[Up a Level](..)'));
  380. $this->assertSame('<p><a href="http://testing.dev/">Up to Root Level</a></p>',
  381. $this->parsedown->text('[Up to Root Level](../..)'));
  382. $this->assertSame('<p><a href="http://testing.dev/item3/item3-3">Up and Down</a></p>',
  383. $this->parsedown->text('[Up and Down](../../item3/item3-3)'));
  384. $this->assertSame('<p><a href="http://testing.dev/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
  385. $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
  386. $this->assertSame('<p><a href="http://testing.dev/item2?foo=bar">Up a Level with Query</a></p>',
  387. $this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
  388. $this->assertSame('<p><a href="http://testing.dev/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
  389. $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
  390. $this->assertSame('<p><a href="http://testing.dev/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
  391. $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
  392. $this->assertSame('<p><a href="http://testing.dev/item3/item3-3#foo">Up and Down with Anchor</a></p>',
  393. $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
  394. }
  395. public function testSlugRelativeLinksSubDir()
  396. {
  397. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  398. $this->assertSame('<p><a href="/subdir/item2/item2-1">Peer Page</a></p>',
  399. $this->parsedown->text('[Peer Page](../item2-1)'));
  400. $this->assertSame('<p><a href="/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
  401. $this->parsedown->text('[Down a Level](item2-2-1)'));
  402. $this->assertSame('<p><a href="/subdir/item2">Up a Level</a></p>',
  403. $this->parsedown->text('[Up a Level](..)'));
  404. $this->assertSame('<p><a href="/subdir">Up to Root Level</a></p>',
  405. $this->parsedown->text('[Up to Root Level](../..)'));
  406. $this->assertSame('<p><a href="/subdir/item3/item3-3">Up and Down</a></p>',
  407. $this->parsedown->text('[Up and Down](../../item3/item3-3)'));
  408. $this->assertSame('<p><a href="/subdir/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
  409. $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
  410. $this->assertSame('<p><a href="/subdir/item2?foo=bar">Up a Level with Query</a></p>',
  411. $this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
  412. $this->assertSame('<p><a href="/subdir/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
  413. $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
  414. $this->assertSame('<p><a href="/subdir/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
  415. $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
  416. $this->assertSame('<p><a href="/subdir/item3/item3-3#foo">Up and Down with Anchor</a></p>',
  417. $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
  418. }
  419. public function testSlugRelativeLinksSubDirAbsoluteUrls()
  420. {
  421. $this->config->set('system.absolute_urls', true);
  422. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  423. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1">Peer Page</a></p>',
  424. $this->parsedown->text('[Peer Page](../item2-1)'));
  425. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
  426. $this->parsedown->text('[Down a Level](item2-2-1)'));
  427. $this->assertSame('<p><a href="http://testing.dev/subdir/item2">Up a Level</a></p>',
  428. $this->parsedown->text('[Up a Level](..)'));
  429. $this->assertSame('<p><a href="http://testing.dev/subdir">Up to Root Level</a></p>',
  430. $this->parsedown->text('[Up to Root Level](../..)'));
  431. $this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3">Up and Down</a></p>',
  432. $this->parsedown->text('[Up and Down](../../item3/item3-3)'));
  433. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
  434. $this->parsedown->text('[Down a Level with Query](item2-2-1?foo=bar)'));
  435. $this->assertSame('<p><a href="http://testing.dev/subdir/item2?foo=bar">Up a Level with Query</a></p>',
  436. $this->parsedown->text('[Up a Level with Query](../?foo=bar)'));
  437. $this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
  438. $this->parsedown->text('[Up and Down with Query](../../item3/item3-3?foo=bar)'));
  439. $this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
  440. $this->parsedown->text('[Up and Down with Param](../../item3/item3-3/foo:bar)'));
  441. $this->assertSame('<p><a href="http://testing.dev/subdir/item3/item3-3#foo">Up and Down with Anchor</a></p>',
  442. $this->parsedown->text('[Up and Down with Anchor](../../item3/item3-3#foo)'));
  443. }
  444. public function testDirectoryRelativeLinks()
  445. {
  446. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  447. $this->assertSame('<p><a href="/item3/item3-3/foo:bar">Up and Down with Param</a></p>',
  448. $this->parsedown->text('[Up and Down with Param](../../03.item3/03.item3-3/foo:bar)'));
  449. $this->assertSame('<p><a href="/item2/item2-1">Peer Page</a></p>',
  450. $this->parsedown->text('[Peer Page](../01.item2-1)'));
  451. $this->assertSame('<p><a href="/item2/item2-2/item2-2-1">Down a Level</a></p>',
  452. $this->parsedown->text('[Down a Level](01.item2-2-1)'));
  453. $this->assertSame('<p><a href="/item3/item3-3">Up and Down</a></p>',
  454. $this->parsedown->text('[Up and Down](../../03.item3/03.item3-3)'));
  455. $this->assertSame('<p><a href="/item2/item2-2/item2-2-1?foo=bar">Down a Level with Query</a></p>',
  456. $this->parsedown->text('[Down a Level with Query](01.item2-2-1?foo=bar)'));
  457. $this->assertSame('<p><a href="/item3/item3-3?foo=bar">Up and Down with Query</a></p>',
  458. $this->parsedown->text('[Up and Down with Query](../../03.item3/03.item3-3?foo=bar)'));
  459. $this->assertSame('<p><a href="/item3/item3-3#foo">Up and Down with Anchor</a></p>',
  460. $this->parsedown->text('[Up and Down with Anchor](../../03.item3/03.item3-3#foo)'));
  461. }
  462. public function testAbsoluteLinks()
  463. {
  464. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  465. $this->assertSame('<p><a href="/">Root</a></p>',
  466. $this->parsedown->text('[Root](/)'));
  467. $this->assertSame('<p><a href="/item2/item2-1">Peer Page</a></p>',
  468. $this->parsedown->text('[Peer Page](/item2/item2-1)'));
  469. $this->assertSame('<p><a href="/item2/item2-2/item2-2-1">Down a Level</a></p>',
  470. $this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
  471. $this->assertSame('<p><a href="/item2">Up a Level</a></p>',
  472. $this->parsedown->text('[Up a Level](/item2)'));
  473. $this->assertSame('<p><a href="/item2?foo=bar">With Query</a></p>',
  474. $this->parsedown->text('[With Query](/item2?foo=bar)'));
  475. $this->assertSame('<p><a href="/item2/foo:bar">With Param</a></p>',
  476. $this->parsedown->text('[With Param](/item2/foo:bar)'));
  477. $this->assertSame('<p><a href="/item2#foo">With Anchor</a></p>',
  478. $this->parsedown->text('[With Anchor](/item2#foo)'));
  479. }
  480. public function testDirectoryAbsoluteLinksSubDir()
  481. {
  482. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  483. $this->assertSame('<p><a href="/subdir/">Root</a></p>',
  484. $this->parsedown->text('[Root](/)'));
  485. $this->assertSame('<p><a href="/subdir/item2/item2-1">Peer Page</a></p>',
  486. $this->parsedown->text('[Peer Page](/item2/item2-1)'));
  487. $this->assertSame('<p><a href="/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
  488. $this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
  489. $this->assertSame('<p><a href="/subdir/item2">Up a Level</a></p>',
  490. $this->parsedown->text('[Up a Level](/item2)'));
  491. $this->assertSame('<p><a href="/subdir/item2?foo=bar">With Query</a></p>',
  492. $this->parsedown->text('[With Query](/item2?foo=bar)'));
  493. $this->assertSame('<p><a href="/subdir/item2/foo:bar">With Param</a></p>',
  494. $this->parsedown->text('[With Param](/item2/foo:bar)'));
  495. $this->assertSame('<p><a href="/subdir/item2#foo">With Anchor</a></p>',
  496. $this->parsedown->text('[With Anchor](/item2#foo)'));
  497. }
  498. public function testDirectoryAbsoluteLinksSubDirAbsoluteUrl()
  499. {
  500. $this->config->set('system.absolute_urls', true);
  501. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  502. $this->assertSame('<p><a href="http://testing.dev/subdir/">Root</a></p>',
  503. $this->parsedown->text('[Root](/)'));
  504. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-1">Peer Page</a></p>',
  505. $this->parsedown->text('[Peer Page](/item2/item2-1)'));
  506. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/item2-2-1">Down a Level</a></p>',
  507. $this->parsedown->text('[Down a Level](/item2/item2-2/item2-2-1)'));
  508. $this->assertSame('<p><a href="http://testing.dev/subdir/item2">Up a Level</a></p>',
  509. $this->parsedown->text('[Up a Level](/item2)'));
  510. $this->assertSame('<p><a href="http://testing.dev/subdir/item2?foo=bar">With Query</a></p>',
  511. $this->parsedown->text('[With Query](/item2?foo=bar)'));
  512. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/foo:bar">With Param</a></p>',
  513. $this->parsedown->text('[With Param](/item2/foo:bar)'));
  514. $this->assertSame('<p><a href="http://testing.dev/subdir/item2#foo">With Anchor</a></p>',
  515. $this->parsedown->text('[With Anchor](/item2#foo)'));
  516. }
  517. public function testSpecialProtocols()
  518. {
  519. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  520. $this->assertSame('<p><a href="mailto:user@domain.com">mailto</a></p>',
  521. $this->parsedown->text('[mailto](mailto:user@domain.com)'));
  522. $this->assertSame('<p><a href="xmpp:xyx@domain.com">xmpp</a></p>',
  523. $this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
  524. $this->assertSame('<p><a href="tel:123-555-12345">tel</a></p>',
  525. $this->parsedown->text('[tel](tel:123-555-12345)'));
  526. $this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
  527. $this->parsedown->text('[sms](sms:123-555-12345)'));
  528. $this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
  529. $this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
  530. }
  531. public function testSpecialProtocolsSubDir()
  532. {
  533. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  534. $this->assertSame('<p><a href="mailto:user@domain.com">mailto</a></p>',
  535. $this->parsedown->text('[mailto](mailto:user@domain.com)'));
  536. $this->assertSame('<p><a href="xmpp:xyx@domain.com">xmpp</a></p>',
  537. $this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
  538. $this->assertSame('<p><a href="tel:123-555-12345">tel</a></p>',
  539. $this->parsedown->text('[tel](tel:123-555-12345)'));
  540. $this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
  541. $this->parsedown->text('[sms](sms:123-555-12345)'));
  542. $this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
  543. $this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
  544. }
  545. public function testSpecialProtocolsSubDirAbsoluteUrl()
  546. {
  547. $this->config->set('system.absolute_urls', true);
  548. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  549. $this->assertSame('<p><a href="mailto:user@domain.com">mailto</a></p>',
  550. $this->parsedown->text('[mailto](mailto:user@domain.com)'));
  551. $this->assertSame('<p><a href="xmpp:xyx@domain.com">xmpp</a></p>',
  552. $this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'));
  553. $this->assertSame('<p><a href="tel:123-555-12345">tel</a></p>',
  554. $this->parsedown->text('[tel](tel:123-555-12345)'));
  555. $this->assertSame('<p><a href="sms:123-555-12345">sms</a></p>',
  556. $this->parsedown->text('[sms](sms:123-555-12345)'));
  557. $this->assertSame('<p><a href="rdp://ts.example.com">ts.example.com</a></p>',
  558. $this->parsedown->text('[ts.example.com](rdp://ts.example.com)'));
  559. }
  560. public function testReferenceLinks()
  561. {
  562. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  563. $sample = '[relative link][r_relative]
  564. [r_relative]: ../item2-3#blah';
  565. $this->assertSame('<p><a href="/item2/item2-3#blah">relative link</a></p>',
  566. $this->parsedown->text($sample));
  567. $sample = '[absolute link][r_absolute]
  568. [r_absolute]: /item3#blah';
  569. $this->assertSame('<p><a href="/item3#blah">absolute link</a></p>',
  570. $this->parsedown->text($sample));
  571. $sample = '[external link][r_external]
  572. [r_external]: http://www.cnn.com';
  573. $this->assertSame('<p><a href="http://www.cnn.com">external link</a></p>',
  574. $this->parsedown->text($sample));
  575. }
  576. public function testAttributeLinks()
  577. {
  578. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  579. $this->assertSame('<p><a href="#something" class="button">Anchor Class</a></p>',
  580. $this->parsedown->text('[Anchor Class](?classes=button#something)'));
  581. $this->assertSame('<p><a href="/item2/item2-3" class="button">Relative Class</a></p>',
  582. $this->parsedown->text('[Relative Class](../item2-3?classes=button)'));
  583. $this->assertSame('<p><a href="/item2/item2-3" id="unique">Relative ID</a></p>',
  584. $this->parsedown->text('[Relative ID](../item2-3?id=unique)'));
  585. $this->assertSame('<p><a href="https://github.com/getgrav/grav" class="button big">External</a></p>',
  586. $this->parsedown->text('[External](https://github.com/getgrav/grav?classes=button,big)'));
  587. $this->assertSame('<p><a href="/item2/item2-3?id=unique">Relative Noprocess</a></p>',
  588. $this->parsedown->text('[Relative Noprocess](../item2-3?id=unique&noprocess)'));
  589. $this->assertSame('<p><a href="/item2/item2-3" target="_blank">Relative Target</a></p>',
  590. $this->parsedown->text('[Relative Target](../item2-3?target=_blank)'));
  591. $this->assertSame('<p><a href="/item2/item2-3" rel="nofollow">Relative Rel</a></p>',
  592. $this->parsedown->text('[Relative Rel](../item2-3?rel=nofollow)'));
  593. $this->assertSame('<p><a href="/item2/item2-3?foo=bar&baz=qux" rel="nofollow" class="button">Relative Mixed</a></p>',
  594. $this->parsedown->text('[Relative Mixed](../item2-3?foo=bar&baz=qux&rel=nofollow&class=button)'));
  595. }
  596. public function testInvalidLinks()
  597. {
  598. $this->uri->initializeWithURL('http://testing.dev/item2/item2-2')->init();
  599. $this->assertSame('<p><a href="/item2/item2-2/no-page">Non Existent Page</a></p>',
  600. $this->parsedown->text('[Non Existent Page](no-page)'));
  601. $this->assertSame('<p><a href="/item2/item2-2/existing-file.zip">Existent File</a></p>',
  602. $this->parsedown->text('[Existent File](existing-file.zip)'));
  603. $this->assertSame('<p><a href="/item2/item2-2/missing-file.zip">Non Existent File</a></p>',
  604. $this->parsedown->text('[Non Existent File](missing-file.zip)'));
  605. }
  606. public function testInvalidLinksSubDir()
  607. {
  608. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  609. $this->assertSame('<p><a href="/subdir/item2/item2-2/no-page">Non Existent Page</a></p>',
  610. $this->parsedown->text('[Non Existent Page](no-page)'));
  611. $this->assertSame('<p><a href="/subdir/item2/item2-2/existing-file.zip">Existent File</a></p>',
  612. $this->parsedown->text('[Existent File](existing-file.zip)'));
  613. $this->assertSame('<p><a href="/subdir/item2/item2-2/missing-file.zip">Non Existent File</a></p>',
  614. $this->parsedown->text('[Non Existent File](missing-file.zip)'));
  615. }
  616. public function testInvalidLinksSubDirAbsoluteUrl()
  617. {
  618. $this->config->set('system.absolute_urls', true);
  619. $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init();
  620. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/no-page">Non Existent Page</a></p>',
  621. $this->parsedown->text('[Non Existent Page](no-page)'));
  622. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/existing-file.zip">Existent File</a></p>',
  623. $this->parsedown->text('[Existent File](existing-file.zip)'));
  624. $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/missing-file.zip">Non Existent File</a></p>',
  625. $this->parsedown->text('[Non Existent File](missing-file.zip)'));
  626. }
  627. /**
  628. * @param $string
  629. *
  630. * @return mixed
  631. */
  632. private function stripLeadingWhitespace($string)
  633. {
  634. return preg_replace('/^\s*(.*)/', '', $string);
  635. }
  636. }