py_microhtml
PyPI release 0.2
파이썬 코드로 유효한 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 > 예, 유니 코드 기호를 복사해야 할 것입니다. 예, 최신 편집기를 사용하고 싶을 것입니다. 그러나 결과 구문은 매우 작고 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를 선호 할 수 있습니다.
Prett Printing에 tidylib 사용합니다. Cenk Altı가 pyhtml 에서 그린 영감.
저작권 2019 Jarno Elonen. MIT 라이센스에 따라 릴리스. 자세한 내용은 라이센스를 참조하십시오.