forked from LiveCarta/BookConverter
epub converter: update data_objects.py
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user