diff --git a/bin/auto-sync.txt b/bin/auto-sync.txt index ba848805..9094e760 100644 --- a/bin/auto-sync.txt +++ b/bin/auto-sync.txt @@ -45,6 +45,7 @@ line-up linked-list list-ops luhn +markdown matching-brackets meetup micro-blog diff --git a/exercises/practice/markdown/.docs/instructions.md b/exercises/practice/markdown/.docs/instructions.md index 4819b6c2..b3f3044c 100644 --- a/exercises/practice/markdown/.docs/instructions.md +++ b/exercises/practice/markdown/.docs/instructions.md @@ -2,14 +2,12 @@ Refactor a Markdown parser. -The markdown exercise is a refactoring exercise. There is code that parses a -given string with [Markdown -syntax](https://guides.github.com/features/mastering-markdown/) and returns the -associated HTML for that string. Even though this code is confusingly written -and hard to follow, somehow it works and all the tests are passing! Your -challenge is to re-write this code to make it easier to read and maintain -while still making sure that all the tests keep passing. - -It would be helpful if you made notes of what you did in your refactoring in -comments so reviewers can see that, but it isn't strictly necessary. The most -important thing is to make the code better! +The markdown exercise is a refactoring exercise. +There is code that parses a given string with [Markdown syntax][markdown] and returns the associated HTML for that string. +Even though this code is confusingly written and hard to follow, somehow it works and all the tests are passing! +Your challenge is to re-write this code to make it easier to read and maintain while still making sure that all the tests keep passing. + +It would be helpful if you made notes of what you did in your refactoring in comments so reviewers can see that, but it isn't strictly necessary. +The most important thing is to make the code better! + +[markdown]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax diff --git a/exercises/practice/markdown/.meta/config.json b/exercises/practice/markdown/.meta/config.json index 294e9344..460acbed 100644 --- a/exercises/practice/markdown/.meta/config.json +++ b/exercises/practice/markdown/.meta/config.json @@ -5,7 +5,8 @@ "contributors": [ "arueckauer", "kytrinyx", - "yisraeldov" + "yisraeldov", + "Narkunan" ], "files": { "solution": [ @@ -18,5 +19,5 @@ ".meta/example.php" ] }, - "blurb": "Refactor a Markdown parser" + "blurb": "Refactor a Markdown parser." } diff --git a/exercises/practice/markdown/.meta/example.php b/exercises/practice/markdown/.meta/example.php index 5f3a447c..8f4a439b 100644 --- a/exercises/practice/markdown/.meta/example.php +++ b/exercises/practice/markdown/.meta/example.php @@ -31,51 +31,64 @@ function parseMarkdown($markdown) $isInList = false; foreach ($lines as &$line) { - if (preg_match('/^######(.*)/', $line, $matches)) { + if (preg_match('/^####### (.*)/', $line, $matches)) { + $line = "

" . trim($matches[0]) . "

"; + } elseif (preg_match('/^###### (.*)/', $line, $matches)) { $line = "
" . trim($matches[1]) . "
"; - } elseif (preg_match('/^##(.*)/', $line, $matches)) { + } elseif (preg_match('/^##### (.*)/', $line, $matches)) { + $line = "
" . trim($matches[1]) . "
"; + } elseif (preg_match('/^#### (.*)/', $line, $matches)) { + $line = "

" . trim($matches[1]) . "

"; + } elseif (preg_match('/^### (.*)/', $line, $matches)) { + $line = "

" . trim($matches[1]) . "

"; + } elseif (preg_match('/^## (.*)/', $line, $matches)) { $line = "

" . trim($matches[1]) . "

"; - } elseif (preg_match('/^#(.*)/', $line, $matches)) { + } elseif (preg_match('/^# (.*)/', $line, $matches)) { $line = "

" . trim($matches[1]) . "

"; } - if (preg_match('/\*(.*)/', $line, $matches)) { + if (preg_match('/^\s*\*(.*)/', $line, $matches)) { if (!$isInList) { $isInList = true; $isBold = false; $isItalic = false; if (preg_match('/(.*)__(.*)__(.*)/', $matches[1], $matches2)) { - $matches[1] = $matches2[1] . '' . $matches2[2] . '' . $matches2[3]; + $matches[1] = $matches2[1] . '' . $matches2[2] . '' . $matches2[3]; $isBold = true; } if (preg_match('/(.*)_(.*)_(.*)/', $matches[1], $matches3)) { - $matches[1] = $matches3[1] . '' . $matches3[2] . '' . $matches3[3]; + $matches[1] = $matches3[1] . '' . $matches3[2] . '' . $matches3[3]; $isItalic = true; } if ($isItalic || $isBold) { $line = "