fnp
/
librarian.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
wip change fb2 api
[librarian.git]
/
src
/
librarian
/
document.py
diff --git
a/src/librarian/document.py
b/src/librarian/document.py
index
d61abb4
..
7f468fa
100644
(file)
--- a/
src/librarian/document.py
+++ b/
src/librarian/document.py
@@
-1,7
+1,7
@@
# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
#
# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
#
-from collections import Counter
+from collections import
defaultdict,
Counter
import gettext
import os
import re
import gettext
import os
import re
@@
-17,6
+17,7
@@
class WLDocument:
source = filename or urllib.request.urlopen(url)
tree = etree.parse(source, parser=parser)
self.tree = tree
source = filename or urllib.request.urlopen(url)
tree = etree.parse(source, parser=parser)
self.tree = tree
+ self.counters = defaultdict(lambda: 1)
tree.getroot().document = self
self.preprocess()
tree.getroot().document = self
self.preprocess()
@@
-41,6
+42,12
@@
class WLDocument:
for _e, elem in etree.iterwalk(self.tree, ('start',), 'strofa'):
elem.preprocess()
for _e, elem in etree.iterwalk(self.tree, ('start',), 'strofa'):
elem.preprocess()
+ def assign_ids(self):
+ # Assign IDs depth-first, to account for any <numeracja> inside.
+ for _e, elem in etree.iterwalk(self.tree, events=('end',)):
+ if getattr(elem, 'NUMBERING', None):
+ elem.assign_id(self)
+
@property
def children(self):
for part_uri in self.meta.parts or []:
@property
def children(self):
for part_uri in self.meta.parts or []: