gon2

Untitled

Oct 24th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. from bs4 import BeautifulSoup as bs4
  2.  
  3. def html(tokens, villur):
  4.     soup = bs4(features="html.parser")
  5.     html = soup.new_tag("html")
  6.     body = soup.new_tag("body", style="margin: 2rem;")
  7.     html.append(body)
  8.     # Fyrirsögn
  9.     texti_tag = soup.new_tag("h1")
  10.     texti_tag.string = "Tilreiddur texti (villur merktar með rauðu):"
  11.     body.append(texti_tag)
  12.     # ítrum í gegnum tokenin og merkjum villur með rauðu
  13.     for t in tokens:
  14.         venjulegur_style = "font-size: 1.5rem; font-weight: bold;"
  15.         villu_style = venjulegur_style + "color: red;"
  16.         if t not in villur:
  17.             tag = soup.new_tag("span", style=venjulegur_style)
  18.         else:
  19.             tag = soup.new_tag("span", style=villu_style)
  20.         tag.string = t
  21.         body.append(tag)
  22.     # skilum fallegum html texta
  23.     return html.prettify()
Advertisement
Add Comment
Please, Sign In to add comment