HTMLフォーマットオンラインツール
についてHTMLフォーマットオンラインツール:
このオンラインHTMLフォーマットツールを使用すると、わかりにくいHTMLファイルを読みやすいHTMLファイルにフォーマットできます。
このツールは、入力が公式のHTML構文に準拠していない場合でも、不適切なHTMLファイルのフォーマットを強制することがあります.
HTML(ハイパーテキストマークアップ言語)へのリンク:
W3 HTML 5.2規格: https://www.w3.org/TR/html5/
RFC 7992(HTML): https://tools.ietf.org/html/rfc7992
PythonのHTML(BeautifulSoup): https://www.crummy.com/software/BeautifulSoup/
PythonでHTMLをフォーマットする(BeautifulSoupパッケージを使用):
def html_beautify(input_str):
input_str = BeautifulSoup(input_str, 'html.parser').prettify()
result = ''
indent_str = ' '
for line in input_str.split('\n'):
lstrip_line = line.lstrip(' ')
indent_len = len(line) - len(lstrip_line)
formatted_line = indent_len * indent_str + lstrip_line
result = result + formatted_line + '\n'
return result