Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.0 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
694596b0585c11170ac7c7fc Challenge 164: Markdown Inline Code Parser 29 challenge-164

--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--

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

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(parse_inline_code("Use \`let\` to declare the variable."), "Use <code>let</code> to declare the variable.")`)
}})

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

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(parse_inline_code("Use \`let\` or \`const\` to declare a variable."), "Use <code>let</code> or <code>const</code> to declare a variable.")`)
}})

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

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(parse_inline_code("Run \`npm install\` then \`npm start\`."), "Run <code>npm install</code> then <code>npm start</code>.")`)
}})

--seed--

--seed-contents--

def parse_inline_code(markdown):

    return markdown

--solutions--

import re
def parse_inline_code(markdown):
    return re.sub(r"`([^`]+)`", r"<code>\1</code>", markdown)