ToptalSeptember 2026
Interview question
Write a Python function solution(S) that converts an HTML fragment into normalized text. Remove HTML tags except links and images. Replace an opening <a href="url"> tag with {link:url} and an <img src="url"> tag with {image:url}, preserving the original URL. Outside these URLs, remove symbols other than English letters and digits, convert words to lowercase, and separate words by one space. For example, <p>hello, ... WORLD!</p> becomes "hello world". The fragment <a href="toptal.com">Toptal_URL</a>now<img src="logo.png">end :: becomes "{link:toptal.com} toptal url now {image:logo.png} end". Use only the standard Python library.