list formatting

This commit is contained in:
randogoth 2025-10-20 12:16:20 +03:00
parent c57cfc4747
commit ad70e8dcd8
4 changed files with 33 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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,
)