aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEnan Ajmain <3nan.ajmain@gmail.com>2022-09-24 16:10:15 +0600
committerGitHub <noreply@github.com>2022-09-24 17:10:15 +0700
commit240cb6dc0f59b5c4f4935d5ac528ed7e0af8481d (patch)
treed14815591065f32dfbcdb8da5b3c31f5b99db719
parent50dd4faf4ca095b8f10a1883ca1168a2628e877e (diff)
downloadepy-240cb6dc0f59b5c4f4935d5ac528ed7e0af8481d.tar.gz
Add user setting for indenting paragraphs (#63)
-rwxr-xr-xepy.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/epy.py b/epy.py
index d73389d..ee7362e 100755
--- a/epy.py
+++ b/epy.py
@@ -356,6 +356,7 @@ class Settings:
SeamlessBetweenChapters: bool = False
PreferredTTSEngine: Optional[str] = None
TTSEngineArgs: List[str] = field(default_factory=list)
+ ParaIndent: int = 0
@dataclass(frozen=True)
@@ -1094,7 +1095,7 @@ class HTMLtoLines(HTMLParser):
groups[row] = [block]
return groups
- def __init__(self, sects={""}):
+ def __init__(self, sects={""}, paraindent=0):
HTMLParser.__init__(self)
self.text = [""]
self.ishead = False
@@ -1112,6 +1113,7 @@ class HTMLtoLines(HTMLParser):
self.italic_marks: List[TextMark] = []
self.bold_marks: List[TextMark] = []
self.imgs: Dict[int, str] = dict()
+ self.paraindent: int = paraindent
def handle_starttag(self, tag, attrs):
if re.match("h[1-6]", tag) is not None:
@@ -1293,7 +1295,8 @@ class HTMLtoLines(HTMLParser):
]
text += [""]
else:
- text += textwrap.wrap(line, textwidth) + [""]
+ text += textwrap.wrap(line, textwidth, initial_indent=' '*self.paraindent)
+ text += [""] * (self.paraindent == 0)
endline = len(text) # -1
@@ -1883,6 +1886,7 @@ def parse_html(
textwidth: Optional[int] = None,
section_ids: Optional[Set[str]] = None,
starting_line: int = 0,
+ paraindent: int = 0
) -> Union[Tuple[str, ...], TextStructure]:
"""
Parse html string into TextStructure
@@ -1896,7 +1900,7 @@ def parse_html(
if not section_ids:
section_ids = set()
- parser = HTMLtoLines(section_ids)
+ parser = HTMLtoLines(section_ids, paraindent)
# try:
parser.feed(html_src)
parser.close()
@@ -3079,6 +3083,7 @@ class Reader:
content,
textwidth=reading_state.textwidth,
section_ids=set(toc_entry.section for toc_entry in toc_entries), # type: ignore
+ paraindent=self.setting.ParaIndent
)
return text_structure, toc_entries, contents