diff --git a/config.json b/config.json index d657ac36a8..f7354b254c 100644 --- a/config.json +++ b/config.json @@ -369,6 +369,20 @@ "strings" ] }, + { + "slug": "markdown", + "name": "Markdown", + "uuid": "3994ee58-0d75-4c46-afe1-666466470255", + "practices": ["regular-expressions", "functions"], + "prerequisites": [], + "difficulty": 4, + "topics": [ + "conditionals", + "pattern_recognition", + "regular_expressions", + "strings" + ] + }, { "slug": "book-store", "name": "Book Store", diff --git a/exercises/practice/markdown/.docs/instructions.md b/exercises/practice/markdown/.docs/instructions.md new file mode 100644 index 0000000000..8e716f88c7 --- /dev/null +++ b/exercises/practice/markdown/.docs/instructions.md @@ -0,0 +1,15 @@ +# Description + +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! diff --git a/exercises/practice/markdown/.eslintrc b/exercises/practice/markdown/.eslintrc new file mode 100644 index 0000000000..1d4446029c --- /dev/null +++ b/exercises/practice/markdown/.eslintrc @@ -0,0 +1,14 @@ +{ + "root": true, + "extends": "@exercism/eslint-config-javascript", + "env": { + "jest": true + }, + "overrides": [ + { + "files": [".meta/proof.ci.js", ".meta/exemplar.js", "*.spec.js"], + "excludedFiles": ["custom.spec.js"], + "extends": "@exercism/eslint-config-javascript/maintainers" + } + ] +} diff --git a/exercises/practice/markdown/.meta/config.json b/exercises/practice/markdown/.meta/config.json new file mode 100644 index 0000000000..ff3a79dba4 --- /dev/null +++ b/exercises/practice/markdown/.meta/config.json @@ -0,0 +1,10 @@ +{ + "blurb": "Refactor a Markdown parser.", + "authors": ["kmelow"], + "contributors": [], + "files": { + "solution": ["markdown.js"], + "test": ["markdown.spec.js"], + "example": [".meta/proof.ci.js"] + } +} diff --git a/exercises/practice/markdown/.meta/proof.ci.js b/exercises/practice/markdown/.meta/proof.ci.js new file mode 100644 index 0000000000..da9fc7df01 --- /dev/null +++ b/exercises/practice/markdown/.meta/proof.ci.js @@ -0,0 +1,72 @@ +// +// This is only a SKELETON file for the 'Matrix' exercise. It's been provided as a +// convenience to get you started writing code faster. +// + +export const parse = (markdown) => { + if (markdown.includes(' __')) { + markdown = markdown.replace(' __', ' '); + } + if (markdown.includes(' _')) { + markdown = markdown.replace(' _', ' '); + } + + if (markdown.includes('__ ')) { + markdown = markdown.replace('__ ', ' '); + } + if (markdown.includes('_ ')) { + markdown = markdown.replace('_ ', ' '); + } + + if (markdown.match(/__\w/g)) { + markdown = markdown.replace('__', ''); + } + if (markdown.match(/\w__/g)) { + markdown = markdown.replace('__', ''); + } + + if (markdown.match(/_\w/g)) { + markdown = markdown.replace('_', ''); + } + if (markdown.match(/\w_/g)) { + markdown = markdown.replace('_', ''); + } + + if (markdown.startsWith('# ')) { + markdown = markdown.replace('# ', '

'); + if (markdown.match(/\n\*/gm)) { + markdown = markdown.replace('\n* ', '

'); + markdown = markdown + '

'; + } else { + markdown = markdown + ''; + } + } else { + markdown = markdown + ''; + } + } else if (markdown.startsWith('## ')) { + markdown = markdown.replace('## ', '

') + '

'; + } else if (markdown.startsWith('### ')) { + markdown = markdown.replace('### ', '

') + '

'; + } else if (markdown.startsWith('#### ')) { + markdown = markdown.replace('#### ', '

') + '

'; + } else if (markdown.startsWith('##### ')) { + markdown = markdown.replace('##### ', '
') + '
'; + } else if (markdown.startsWith('###### ')) { + markdown = markdown.replace('###### ', '
') + '
'; + } else if (markdown.startsWith('* ')) { + markdown = markdown.replace('* ', ''; + } else { + markdown = `

${markdown}

`; + } + + markdown = markdown.replace('\n* ', '