py_microhtml
PyPI release 0.2
Pythonコードを使用して有効なHTMLを安全に構築します。例:
from microhtml import *
print (
ᑉhtml (
ᑉhead ( ᑉtitle ( 'Test page' )),
ᑉbody ( ᑉspan ( 'Simple example.' , class_ = 'example' ))). pretty ())これにより、有効なフォーマットされたXHTMLドキュメントが印刷されます。
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head >
< title >
Test page
</ title >
</ head >
< body >
< span class = " example " >Simple example.</ span >
</ body >
</ html >はい、おそらくUnicodeシンボルをコピーする必要があります。はい、最新のエディターを使用する必要がありますが、結果の構文は非常にコンパクトであり、 import *であっても識別子と衝突しません。
ミニマリズムも実装にまで及びます - それは非常に短い(v0.3では80行未満)。 microhtml/__init__.pyをご覧ください。
より多くの機能が展示されている長い例:
from microhtml import *
# Rendering a non-indented string (result: <p>Third <em>and last</em> paragraph</p>)
raw_html = str ( ᑉp ( "Third " , ᑉem ( "and last" ), ' paragraph' ))
# Writing a nicely formatted / tidied XHTML document to a file descriptor
print (
ᑉhtml ( lang = 'en_US' )(
ᑉhead ( ᑉtitle ( "Test page" )),
ᑉbody (
ᑉp ( "Hi!" , width = 123 ), # 123 becomes "123"
ᑉhr ( class_ = 'someclass' ), # Reserved words like "class" can be written with a trailing underscore
ᑉp ( 'Literal strings are safely <em>escaped</em> by default.' ),
ᑉrawstr ( raw_html ), # Use ᑉrawstr() if you don't want escaping
ᑉtag ( 'applet' , code = 'Bubbles.class' , width = 350 , height = 350 ), # Tag with custom name
ᑉdiv ( "custom" , data__custom = "abc" ), # '__' in attribute names is replaced with '-'
ᑉdiv ( style = 'float: right' )( # This is how you can type attributes on left and content on right
ᑉdiv ( style = 'border: 1px solid black' )(
ᑉa ( "Nested" , href = '#anchortest' ), '|' , 'link' )))). pretty ())これは出力です:
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
< html lang = " en_US " xmlns = " http://www.w3.org/1999/xhtml " xml : lang = " en_US " >
< head >
< title >
Test page
</ title >
</ head >
< body >
< p width = " 123 " >
Hi!
</ p >
< hr class = " someclass " />
< p >
Literal strings are safely < em > escaped < /em > by default.
</ p >
< p >
Third < em >and last</ em > paragraph
</ p >< applet code = " Bubbles.class " width = " 350 " height = " 350 " >
</ applet >
< div data-custom = " abc " >
custom
</ div >
< div style = " float: right " >
< div style = " border: 1px solid black " >
< a href = " #anchortest " >Nested</ a >|link
</ div >
</ div >
</ body >
</ html >PYPIパッケージを構築するには、単に問題make 。 VENVのインストール、実行テスト、.pyi(タイプ/構文完了スタブ)を生成し、ソースパッケージ(SDIST)を構築します。 make cleanしてクリーンアップを使用してください。
ソースコードのユニコード文字が恐ろしい憎悪であり、式withネストされたエンドレスを気にしない場合は、Yattagを好むかもしれません。
きれいな印刷にtidylib使用します。 CenkAltıによるpyhtmlから描かれたインスピレーション。
Copyright 2019 Jarno Elonen。 MITライセンスの下でリリースされました。詳細については、ライセンスを参照してください。