Skip to content

Commit

Permalink
Fixes for tag implementation, use plural 'tags' for internal API, sin…
Browse files Browse the repository at this point in the history
…gular 'tag' for the XML attribute (proycon/folia#93)
  • Loading branch information
proycon committed Apr 2, 2021
1 parent 8986aae commit 629339a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions folia/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def __getattr__(self, attr):
#overriding getattr so we can get defaults here rather than needing a copy on each element, saves memory
if attr in ('set','cls','processor', 'confidence','datetime','n','href','src','speaker','begintime','endtime','xlinktype','xlinktitle','xlinklabel','xlinkrole','xlinkshow','label', 'textclass', 'metadata','exclusive', 'preservespace'):
return None
elif attr == 'tag':
elif attr == 'tags':
return []
elif attr == 'annotator':
if self.processor:
Expand Down Expand Up @@ -2618,9 +2618,6 @@ def xml(self, attribs = None,elements = None, skipchildren = False, form = Form.
if self.metadata and self.metadata in self.doc.submetadata:
attribs['metadata'] = self.metadata

if 'tag' not in attribs: #do not override if caller already set it
if self.tags:
attribs['tag'] = " ".join(self.tags)

if self.XLINK:
if self.href:
Expand Down Expand Up @@ -2657,6 +2654,10 @@ def xml(self, attribs = None,elements = None, skipchildren = False, form = Form.
tag = OLDTAGS_REVERSE[tag]
e = E(tag,**attribs)

if self.tags:
#we have to add this after the creating because ElementMaker treats 'tag' as a reserved keyword parameter
e.attrib['tag'] = " ".join(self.tags) #XML property uses singular, API plural


if not skipchildren and self.data:
#append children,
Expand Down

0 comments on commit 629339a

Please sign in to comment.