Python HTML Generator using Yattag Part 2
Python HTML Generator 5. Shortcut for nodes that contain only text If you're producing HTML or XML, you've probably realized that most tag nodes contain only text. In order to write these in a terser way, use the line method. doc, tag, text, line=Doc().ttl() with tag('ul', id='course'): line('li', 'BCA', klass="degree") line('li', 'BBA') line('li', 'BSW') You'll get: <ul id="course"> <li class="degree">BCA</li> <li>BBA</li> <li>BSW</li> </ul> Oh, I forgot to introduce the ttl method I just used in the example above. It works just like the tagtext method I've talked about in the beginning of the tutorial, but instead of returning the triplet (doc, doc.tag, doc.text) , it returns the quadruplet (doc, doc.tag, doc.text, doc.line) . 6. Indentation We've added indentation in the ...