mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Increase heading levels on Markdown export
This commit is contained in:
parent
6cdf2f90c5
commit
defd81631b
1 changed files with 23 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
from .text_exporter import TextExporter
|
from .text_exporter import TextExporter
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
class MarkdownExporter(TextExporter):
|
class MarkdownExporter(TextExporter):
|
||||||
|
@ -22,11 +23,32 @@ class MarkdownExporter(TextExporter):
|
||||||
else:
|
else:
|
||||||
heading = '###'
|
heading = '###'
|
||||||
|
|
||||||
|
'''Increase heading levels in body text'''
|
||||||
|
newbody = ''
|
||||||
|
previous_line = ''
|
||||||
|
for line in body.splitlines(True):
|
||||||
|
if re.match(r"#+ ", line):
|
||||||
|
"""ATX style headings"""
|
||||||
|
newbody = newbody + previous_line + heading + line
|
||||||
|
line = ''
|
||||||
|
elif re.match(r"=+$", line) and not re.match(r"^$", previous_line):
|
||||||
|
"""Setext style H1"""
|
||||||
|
newbody = newbody + heading + "# " + previous_line
|
||||||
|
line = ''
|
||||||
|
elif re.match(r"-+$", line) and not re.match(r"^$", previous_line):
|
||||||
|
"""Setext style H2"""
|
||||||
|
newbody = newbody + heading + "## " + previous_line
|
||||||
|
line = ''
|
||||||
|
else:
|
||||||
|
newbody = newbody + previous_line
|
||||||
|
previous_line = line
|
||||||
|
newbody = newbody + previous_line
|
||||||
|
|
||||||
return "{md} {date} {title} {body} {space}".format(
|
return "{md} {date} {title} {body} {space}".format(
|
||||||
md=heading,
|
md=heading,
|
||||||
date=date_str,
|
date=date_str,
|
||||||
title=entry.title,
|
title=entry.title,
|
||||||
body=body,
|
body=newbody,
|
||||||
space=""
|
space=""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue