From 240cb6dc0f59b5c4f4935d5ac528ed7e0af8481d Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Sat, 24 Sep 2022 16:10:15 +0600 Subject: Add user setting for indenting paragraphs (#63) --- epy.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'epy.py') 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 -- cgit