diff --git a/examples/loremipsum.md b/examples/loremipsum.md index dd78fc1..9d82d30 100644 --- a/examples/loremipsum.md +++ b/examples/loremipsum.md @@ -8,6 +8,8 @@ paragraph_spacing: 2 code_block_line_numbers: false code_block_wrap: 4 blockquote_bars: false +list_marker_indent: 2 +list_text_spacing: 3 hyphenate: true --- @@ -39,6 +41,21 @@ populifer adeunt quicquam cum **ales** Ixion angulus placet reddere. ## Tractaque serpens arva quoque {:.center} +### Unordered + ++ Create a list by starting a line with `+`, `-`, or `*` +- Marker character change forces new list start: +* Ac tristique libero volutpat at jesrh hjsrh sejr hhsjehv sjtrhg jrdth ++ Facilisis in pretium nisl aliquet +- Nulla volutpat aliquam velit ++ Very easy + +### Ordered + +1. Lorem ipsum dolor sit amet +2. Consectetur adipiscing elit +3. Integer molestie lorem at massa + Inprudens dum memor alma, casses dedi Sinuessa iam quid adicit `gate_truncate_wave`. [Geratur de](#salientia-iungit-contra-et), insolida temptat `open` carentia; genitorem solet, potens. Adit vos ramos mundi castris diff --git a/md2txt.py b/md2txt.py index 635bba4..010170e 100644 --- a/md2txt.py +++ b/md2txt.py @@ -95,6 +95,8 @@ def parse_frontmatter(lines: List[str]) -> Tuple[FrontMatter, List[str]]: code_block_wrap_indent = default_wrap_indent if wrap_flag else 0 code_block_line_numbers = _parse_bool(frontmatter.get("code_block_line_numbers"), True) blockquote_bars = _parse_bool(frontmatter.get("blockquote_bars"), True) + list_marker_indent = max(0, _parse_int(frontmatter.get("list_marker_indent"), 0)) + list_text_spacing = max(0, _parse_int(frontmatter.get("list_text_spacing"), 1)) fm = FrontMatter( h1_font=frontmatter.get("h1_font", "standard").strip() or "standard", h2_font=frontmatter.get("h2_font", "standard").strip() or "standard", @@ -110,6 +112,8 @@ def parse_frontmatter(lines: List[str]) -> Tuple[FrontMatter, List[str]]: code_block_wrap_indent=code_block_wrap_indent, code_block_line_numbers=code_block_line_numbers, blockquote_bars=blockquote_bars, + list_marker_indent=list_marker_indent, + list_text_spacing=list_text_spacing, ) return fm, remaining diff --git a/md_types.py b/md_types.py index 3fab78a..7f0e0d9 100644 --- a/md_types.py +++ b/md_types.py @@ -45,6 +45,8 @@ class FrontMatter: code_block_wrap_indent: int = 2 code_block_line_numbers: bool = True blockquote_bars: bool = True + list_marker_indent: int = 0 + list_text_spacing: int = 1 @dataclass diff --git a/text_renderer.py b/text_renderer.py index b5dbd60..3231d78 100644 --- a/text_renderer.py +++ b/text_renderer.py @@ -79,6 +79,8 @@ class TextRenderer: self.wrap_code_blocks_indent = ( max(0, frontmatter.code_block_wrap_indent) if self.wrap_code_blocks else 0 ) + self.list_marker_indent = max(0, frontmatter.list_marker_indent) + self.list_text_spacing = max(0, frontmatter.list_text_spacing) self._base_style = BlockStyle( align="left", margin_left=max(0, frontmatter.margin_left), @@ -175,12 +177,17 @@ class TextRenderer: self._emit_block(wrapped, stylable=False) def _render_list_item(self, payload: ListItemPayload, style: BlockStyle) -> None: - prefix = f"{payload.indent}{payload.marker}{payload.spacing}" + base_indent = payload.indent.replace("\t", " ") + marker_indent = " " * self.list_marker_indent + marker = payload.marker + text_spacing = " " * self.list_text_spacing + initial_indent = f"{base_indent}{marker_indent}{marker}{text_spacing}" + subsequent_indent = f"{base_indent}{marker_indent}{' ' * len(marker)}{text_spacing}" processed = self._process_inline(payload.text) wrapped = self._wrap_text( processed, - initial_indent=prefix, - subsequent_indent=" " * len(prefix), + initial_indent=initial_indent, + subsequent_indent=subsequent_indent, style=style, hyphenate=self.hyphenate, )