0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
Our grug-brain static site generator only cares about two things:
Inline markdown is what we just took care of. It's the stuff that's inside of a block. For example, the bolded text in this sentence is inline markdown.
Block-level markdown is just the separation of different sections of an entire document. In well-written markdown (which we'll just assume is the only thing going into our generator) blocks are separated by a single blank line. Here are 3 distinct blocks:
# This is a heading
This is a paragraph of text. It has some **bold** and _italic_ words inside of it.
- This is the first list item in a list block
- This is a list item
- This is another list item
The heading, the paragraph, and the unordered list are all separate blocks. The blank line between them is what separates them.
# This is a heading
This is a paragraph of text. It has some **bold** and _italic_ words inside of it.
- This is the first list item in a list block
- This is a list item
- This is another list item
.split()
method can be used to split a string into blocks based on a delimiter (\n\n
is a double newline)..strip()
any leading or trailing whitespace from each block.Notice the indentation of the multiline string! Newlines shouldn't be indented because the tab will be included in the string and your tests will fail.
def test_markdown_to_blocks(self):
md = """
This is **bolded** paragraph
This is another paragraph with _italic_ text and `code` here
This is the same paragraph on a new line
- This is a list
- with items
"""
blocks = markdown_to_blocks(md)
self.assertEqual(
blocks,
[
"This is **bolded** paragraph",
"This is another paragraph with _italic_ text and `code` here\nThis is the same paragraph on a new line",
"- This is a list\n- with items",
],
)
Run and submit the CLI tests from the root of the project.
The Boot.dev CLI requires you to be signed in to submit your solution!
Copy/paste one of the following commands into your terminal:
Run
bootdev run c416bebd-7f50-40eb-bf24-d882770d6f9a
Submit
bootdev run c416bebd-7f50-40eb-bf24-d882770d6f9a -s
To run and submit the tests for this lesson, you must have an active Boot.dev membership
Become a member to view solution
Using the Bootdev CLI
The Bootdev CLI is the only way to submit your solution for this type of lesson. We need to be able to run commands in your environment to verify your solution.
You can install it here. It's a Go program hosted on GitHub, so you'll need Go installed as well. Instructions are on the GitHub page.