fixed paragraph and heading
This commit is contained in:
parent
b41b595dee
commit
c44046e6ce
@ -103,4 +103,5 @@ def text_to_textnodes(text):
|
|||||||
nodes = split_nodes_delimiter(nodes, "*", text_type_italic)
|
nodes = split_nodes_delimiter(nodes, "*", text_type_italic)
|
||||||
nodes = split_nodes_delimiter(nodes, "`", text_type_code)
|
nodes = split_nodes_delimiter(nodes, "`", text_type_code)
|
||||||
nodes = split_nodes_image(nodes)
|
nodes = split_nodes_image(nodes)
|
||||||
nodes = split_nodes_link(nodes)
|
nodes = split_nodes_link(nodes)
|
||||||
|
return nodes
|
@ -1,6 +1,8 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from htmlnode import LeafNode, ParentNode
|
from htmlnode import LeafNode, ParentNode
|
||||||
|
from inline_markdown import text_to_textnodes
|
||||||
|
from textnode import text_node_to_html_node
|
||||||
|
|
||||||
block_type_paragraph = "paragraph"
|
block_type_paragraph = "paragraph"
|
||||||
block_type_heading = "heading"
|
block_type_heading = "heading"
|
||||||
@ -60,14 +62,28 @@ def block_to_block_type(block):
|
|||||||
else:
|
else:
|
||||||
return block_type_paragraph
|
return block_type_paragraph
|
||||||
|
|
||||||
|
def text_to_children(text):
|
||||||
|
text_nodes = text_to_textnodes(text)
|
||||||
|
children = []
|
||||||
|
for text_node in text_nodes:
|
||||||
|
html_node = text_node_to_html_node(text_node)
|
||||||
|
children.append(html_node)
|
||||||
|
return children
|
||||||
|
|
||||||
def paragraph_to_html_node(block):
|
def paragraph_to_html_node(block):
|
||||||
return LeafNode("p", block)
|
lines = block.split("\n")
|
||||||
|
paragraph = " ".join(lines)
|
||||||
|
children = text_to_children(paragraph)
|
||||||
|
return ParentNode("p", children)
|
||||||
|
|
||||||
def heading_to_html_node(block):
|
def heading_to_html_node(block):
|
||||||
regexed_block = re.search("(^#{1,6}) (.*)", block)
|
regexed_block = re.search("(^#{1,6}) (.*)", block)
|
||||||
count = len(regexed_block.groups(1))
|
if regexed_block == None:
|
||||||
data = regexed_block.groups(2)
|
raise ValueError("Invalid heading level")
|
||||||
return LeafNode(f"h{count}", data)
|
count = len(regexed_block.groups()[0])
|
||||||
|
data = regexed_block.groups()[1]
|
||||||
|
data = text_to_children(data)
|
||||||
|
return ParentNode(f"h{count}", data)
|
||||||
|
|
||||||
def code_to_html_node(block):
|
def code_to_html_node(block):
|
||||||
code_data = re.search("^```(.*)```$", block).groups(1)[0]
|
code_data = re.search("^```(.*)```$", block).groups(1)[0]
|
||||||
@ -125,5 +141,5 @@ def markdown_to_html_node(markdown):
|
|||||||
return ParentNode("div", nodes)
|
return ParentNode("div", nodes)
|
||||||
|
|
||||||
|
|
||||||
quote_block = "> quote first line\n> quote second line"
|
quote_block = "### This is a h3 heading."
|
||||||
print(quote_to_html_node(quote_block))
|
print(heading_to_html_node(quote_block))
|
Loading…
Reference in New Issue
Block a user