epub converter: update data_objects.py

This commit is contained in:
shirshasa
2021-09-01 16:12:10 +03:00
parent b708f73d89
commit 91b722f441

View File

@@ -39,13 +39,17 @@ class NavPoint:
These are data structures which form mapping to livecarta json structure.
"""
atom = lambda x: not isinstance(x, list)
nil = lambda x: not x
car = lambda x: x[0]
cdr = lambda x: x[1:]
cons = lambda x, y: x + y
flatten = lambda x: [x] if atom(x) else x if nil(x) else cons(*map(flatten, [car(x), cdr(x)]))
def flatten(x):
""" magic function from stackoverflow for list flattening """
atom = lambda i: not isinstance(i, list)
nil = lambda i: not i
car = lambda i: i[0]
cdr = lambda i: i[1:]
cons = lambda i, y: i + y
res = [x] if atom(x) else x if nil(x) else cons(*map(flatten, [car(x), cdr(x)]))
return res
class ChapterItem: