added extract functions
This commit is contained in:
		@@ -1,3 +1,5 @@
 | 
			
		||||
import re
 | 
			
		||||
 | 
			
		||||
from textnode import TextNode
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -21,3 +23,11 @@ def split_nodes_delimiter(old_nodes, delimiter, text_type):
 | 
			
		||||
        final_node_list.extend(node_list)
 | 
			
		||||
 | 
			
		||||
    return final_node_list
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def extract_markdown_images(text):
 | 
			
		||||
    return re.findall(r"!\[(.*?)\]\((.*?)\)", text)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def extract_markdown_links(text):
 | 
			
		||||
    return re.findall(r"\[(.*?)\]\((.*?)\)", text)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,14 +1,9 @@
 | 
			
		||||
import unittest
 | 
			
		||||
 | 
			
		||||
from inline_markdown import split_nodes_delimiter
 | 
			
		||||
 | 
			
		||||
from textnode import (
 | 
			
		||||
    TextNode,
 | 
			
		||||
    text_type_bold,
 | 
			
		||||
    text_type_code,
 | 
			
		||||
    text_type_italic,
 | 
			
		||||
    text_type_text,
 | 
			
		||||
)
 | 
			
		||||
from inline_markdown import (extract_markdown_images, extract_markdown_links,
 | 
			
		||||
                             split_nodes_delimiter)
 | 
			
		||||
from textnode import (TextNode, text_type_bold, text_type_code,
 | 
			
		||||
                      text_type_italic, text_type_text)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TestInlineMarkdown(unittest.TestCase):
 | 
			
		||||
@@ -79,5 +74,25 @@ class TestInlineMarkdown(unittest.TestCase):
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_extract_markdown_images(self):
 | 
			
		||||
    matches = extract_markdown_images(
 | 
			
		||||
        "This is text with an "
 | 
			
		||||
    )
 | 
			
		||||
    self.assertListEqual([("image", "https://i.imgur.com/zjjcJKZ.png")], matches)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_extract_markdown_links(self):
 | 
			
		||||
    matches = extract_markdown_links(
 | 
			
		||||
        "This is text with a [link](https://boot.dev) and [another link](https://blog.boot.dev)"
 | 
			
		||||
    )
 | 
			
		||||
    self.assertListEqual(
 | 
			
		||||
        [
 | 
			
		||||
            ("link", "https://boot.dev"),
 | 
			
		||||
            ("another link", "https://blog.boot.dev"),
 | 
			
		||||
        ],
 | 
			
		||||
        matches,
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    unittest.main()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user