Back to Freecodecamp

Challenge 164: Markdown Inline Code Parser

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/694596b0585c11170ac7c7fc.md

latest1.6 KB
Original Source

--description--

Given a string of Markdown that includes one or more inline code blocks, return the equivalent HTML string.

Inline code blocks in Markdown use a single backtick (`) at the start and end of the code block text.

Return the given string with all code blocks converted to HTML code tags.

For example, given the string "Use `let` to declare the variable.", return "Use <code>let</code> to declare the variable.".

Note: The console may not display HTML tags in strings when logging messages. Check the browser console to see logs with tags included.

--hints--

parseInlineCode("Use `let` to declare the variable.") should return "Use <code>let</code> to declare the variable.".

js
assert.equal(parseInlineCode("Use `let` to declare the variable."), "Use <code>let</code> to declare the variable.");

parseInlineCode("Use `let` or `const` to declare a variable.") should return "Use <code>let</code> or <code>const</code> to declare a variable.".

js
assert.equal(parseInlineCode("Use `let` or `const` to declare a variable."), "Use <code>let</code> or <code>const</code> to declare a variable.");

parseInlineCode("Run `npm install` then `npm start`.") should return "Run <code>npm install</code> then <code>npm start</code>.".

js
assert.equal(parseInlineCode("Run `npm install` then `npm start`."), "Run <code>npm install</code> then <code>npm start</code>.");

--seed--

--seed-contents--

js
function parseInlineCode(markdown) {

  return markdown;
}

--solutions--

js
function parseInlineCode(markdown) {
  return markdown.replace(/`([^`]+)`/g, "<code>$1</code>");
}