leforestier / yattag

Python library to generate HTML or XML in a readable, concise and pythonic way.
333 stars 31 forks source link

stag attributes #68

Closed war21x3b closed 3 years ago

war21x3b commented 3 years ago

Hello. I try to add attributes to stag. If I do something like that

doc.stag('link:roleRef', roleURI='http://site.com/page')

it's working fine. But when I try use more complex attributes, like link:roleURI='http://site.com/page' - it not work.

For 'tag' I can do next:

with tag('link:linkbase'):
 doc.attr(
  ("xmlns:link", "http://www.xbrl.org/2003/linkbase")
 )

and that works fine, but for 'stag' - is not!

How I can use attributes like link:roleURI='http://site.com/page' for 'stag'?

leforestier commented 3 years ago

Hello,

you can supply attributes as (name, value) pairs with stag as well. For example:

doc.stag('link:linkbase', ('xmlns:link', 'http://www.xbrl.org/2003/linkbase'))

Then you get:

<link:linkbase xmlns:link="http://www.xbrl.org/2003/linkbase" />
war21x3b commented 3 years ago

Thanks, that is works for me.

I think will be fine to add that example to manual. In manual I seen text about pairs of (name, value), but without example.

Thank you!