Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup as bs4
- def html(tokens, villur):
- soup = bs4(features="html.parser")
- html = soup.new_tag("html")
- body = soup.new_tag("body", style="margin: 2rem;")
- html.append(body)
- # Fyrirsögn
- texti_tag = soup.new_tag("h1")
- texti_tag.string = "Tilreiddur texti (villur merktar með rauðu):"
- body.append(texti_tag)
- # ítrum í gegnum tokenin og merkjum villur með rauðu
- for t in tokens:
- venjulegur_style = "font-size: 1.5rem; font-weight: bold;"
- villu_style = venjulegur_style + "color: red;"
- if t not in villur:
- tag = soup.new_tag("span", style=venjulegur_style)
- else:
- tag = soup.new_tag("span", style=villu_style)
- tag.string = t
- body.append(tag)
- # skilum fallegum html texta
- return html.prettify()
Advertisement
Add Comment
Please, Sign In to add comment