mirror of
https://github.com/olivierkes/manuskript.git
synced 2024-05-19 04:12:29 +12:00
Improve optimized MMD loading to skip empty files later on
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
parent
8029522563
commit
d9c0938614
|
@ -156,8 +156,9 @@ class OutlineText(OutlineItem):
|
||||||
metadata, body = self.file.loadMMD(optimized)
|
metadata, body = self.file.loadMMD(optimized)
|
||||||
OutlineItem.loadMetadata(self, metadata)
|
OutlineItem.loadMetadata(self, metadata)
|
||||||
|
|
||||||
if not optimized:
|
if body is not None:
|
||||||
self.text = body
|
self.text = body
|
||||||
|
optimized = False
|
||||||
|
|
||||||
self.complete(optimized=optimized)
|
self.complete(optimized=optimized)
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ class MmdFile(AbstractFile):
|
||||||
metaValue = None
|
metaValue = None
|
||||||
|
|
||||||
with open(self.path, 'rt', encoding='utf-8') as file:
|
with open(self.path, 'rt', encoding='utf-8') as file:
|
||||||
for line in file:
|
line = file.readline()
|
||||||
|
while line:
|
||||||
m = metaPattern.match(line)
|
m = metaPattern.match(line)
|
||||||
|
|
||||||
if not (m is None):
|
if not (m is None):
|
||||||
|
@ -33,14 +34,15 @@ class MmdFile(AbstractFile):
|
||||||
|
|
||||||
metaKey = m.group(1)
|
metaKey = m.group(1)
|
||||||
metaValue = m.group(2)
|
metaValue = m.group(2)
|
||||||
continue
|
else:
|
||||||
|
m = metaValuePattern.match(line)
|
||||||
|
|
||||||
m = metaValuePattern.match(line)
|
if not (m is None):
|
||||||
|
metaValue += "\n" + m.group(2)
|
||||||
|
elif line == "\n":
|
||||||
|
break
|
||||||
|
|
||||||
if not (m is None):
|
line = file.readline()
|
||||||
metaValue += "\n" + m.group(2)
|
|
||||||
elif line == "\n":
|
|
||||||
break
|
|
||||||
|
|
||||||
if not (metaKey is None):
|
if not (metaKey is None):
|
||||||
metadata[metaKey] = metaValue
|
metadata[metaKey] = metaValue
|
||||||
|
@ -50,6 +52,14 @@ class MmdFile(AbstractFile):
|
||||||
|
|
||||||
if (len(body) > 0) and (body[0] == "\n"):
|
if (len(body) > 0) and (body[0] == "\n"):
|
||||||
body = body[1:]
|
body = body[1:]
|
||||||
|
elif file.seekable():
|
||||||
|
currentPosition = file.tell()
|
||||||
|
|
||||||
|
file.seek(0, 2)
|
||||||
|
endPosition = file.tell()
|
||||||
|
|
||||||
|
if endPosition - currentPosition == 1:
|
||||||
|
body = ""
|
||||||
|
|
||||||
return metadata, body
|
return metadata, body
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue