Mercurial > hg > lxmldump
comparison lxmldump.py @ 59:d52696972bf2
Better way(?) of removing trailing "."
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 31 May 2021 13:28:48 +0300 |
parents | de06d98f82a1 |
children | cbed8ee15701 |
comparison
equal
deleted
inserted
replaced
58:de06d98f82a1 | 59:d52696972bf2 |
---|---|
273 | 273 |
274 ## Format a "Ptr" node as text | 274 ## Format a "Ptr" node as text |
275 def pkk_ptr_to_text(pnode): | 275 def pkk_ptr_to_text(pnode): |
276 pfmt = pkk_get_fmt("ptr_fmt") | 276 pfmt = pkk_get_fmt("ptr_fmt") |
277 return pfmt.format( | 277 return pfmt.format( |
278 text=("".join(pnode.itertext())).strip().rstrip("."), | 278 text=re.sub(r'\.$', '', ("".join(pnode.itertext())).strip()), |
279 href=pnode.attrib["{http://www.w3.org/TR/xlink}href"]) | 279 href=pnode.attrib["{http://www.w3.org/TR/xlink}href"]) |
280 | 280 |
281 | 281 |
282 ## Get text inside a given node | 282 ## Get text inside a given node |
283 def pkk_node_to_text(lnode): | 283 def pkk_node_to_text(lnode): |
290 stmp += pkk_str_annotate(pnode.tag, pkk_str_clean(pnode.text)) | 290 stmp += pkk_str_annotate(pnode.tag, pkk_str_clean(pnode.text)) |
291 | 291 |
292 if isinstance(pnode.tail, str): | 292 if isinstance(pnode.tail, str): |
293 stmp += pkk_str_clean(pnode.tail) | 293 stmp += pkk_str_clean(pnode.tail) |
294 | 294 |
295 return stmp.strip() | 295 return re.sub(r'\.$', '', stmp.strip()) |
296 | 296 |
297 | 297 |
298 ## Simple recursive dump starting at given node | 298 ## Simple recursive dump starting at given node |
299 def pkk_dump_recursive(indent, lnode): | 299 def pkk_dump_recursive(indent, lnode): |
300 if lnode.tag in ["Example"]: | 300 if lnode.tag in ["Example"]: |