-
Notifications
You must be signed in to change notification settings - Fork 126
/
HTML_Validator.py
31 lines (23 loc) · 1.15 KB
/
HTML_Validator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/python3
def validate_html(html):
'''
This function performs a limited version of html validation by checking whether every opening tag has a corresponding closing tag.
>>> validate_html('<strong>example</strong>')
True
>>> validate_html('<strong>example')
False
'''
# HINT:
# use the _extract_tags function below to generate a list of html tags without any extra text;
# then process these html tags using the balanced parentheses algorithm from the class/book
# the main difference between your code and the code from class will be that you will have to keep track of not just the 3 types of parentheses,
# but arbitrary text located between the html tags
def _extract_tags(html):
'''
This is a helper function for `validate_html`.
By convention in Python, helper functions that are not meant to be used directly by the user are prefixed with an underscore.
This function returns a list of all the html tags contained in the input string,
stripping out all text not contained within angle brackets.
>>> _extract_tags('Python <strong>rocks</strong>!')
['<strong>', '</strong>']
'''