diff --git a/examples/loremipsum.ama b/examples/loremipsum.ama index f8d664f..e3808e6 100644 --- a/examples/loremipsum.ama +++ b/examples/loremipsum.ama @@ -1,12 +1,13 @@ - ___ _ _ _ _ - / __| __ _| (_)___ _ _| |_(_)__ _ - \__ \/ _` | | / -_) ' \ _| / _` | - |___/\__,_|_|_\___|_||_\__|_\__,_| + ___ _ _ _ _ + / __| __ _| (_)___ _ _| |_(_)__ _ + \__ \/ _` | | / -_) ' \ _| / _` | + |___/\__,_|_|_\___|_||_\__|_\__,_| -%h Structa hinc vetitus factum + + %h Structa hinc vetitus factum Lorem markdownum omnes tellus, in, Herculeis `=reciprocalPower`= neque @@ -15,7 +16,7 @@ -%h Fuit video longique dedisse + %h Fuit video longique dedisse Ille stupet, ultra %!INCUNABULA AGENDUM URBES%t mirer %!APER%t, metu. @@ -34,154 +35,24 @@ -%h Tractaque serpens arva quoque - - - _ _ _ _ _ _ ___ __ - | |_ / | | || |___ __ _ __| (_)_ _ __ _ ( _ )__\ \ - | ' \| | | __ / -_) _` / _` | | ' \/ _` | / _ \___| | - |_||_|_| |_||_\___\__,_\__,_|_|_||_\__, | \___/ | | - |___/ /_/ - - -%h h2 Heading - - -%h h3 Heading - - - _ _ _ _ _ _ _ - | |__ | || | | | | | ___ __ _ __| (_)_ __ __ _ - | '_ \| || |_ | |_| |/ _ \/ _` |/ _` | | '_ \ / _` | - | | | |__ _| | _ | __/ (_| | (_| | | | | | (_| | - |_| |_| |_| |_| |_|\___|\__,_|\__,_|_|_| |_|\__, | - |___/ - - - _ ____ _ _ _ _ - | |__ | ___| | | | | ___ __ _ __| (_)_ __ __ _ - | '_ \|___ \ | |_| |/ _ \/ _` |/ _` | | '_ \ / _` | - | | | |___) | | _ | __/ (_| | (_| | | | | | (_| | - |_| |_|____/ |_| |_|\___|\__,_|\__,_|_|_| |_|\__, | - |___/ - - - _ __ _ _ _ _ - | |__ / /_ | | | | ___ __ _ __| (_)_ __ __ _ - | '_ \| '_ \ | |_| |/ _ \/ _` |/ _` | | '_ \ / _` | - | | | | (_) | | _ | __/ (_| | (_| | | | | | (_| | - |_| |_|\___/ |_| |_|\___|\__,_|\__,_|_|_| |_|\__, | - |___/ - - -%h Horizontal Rules - - - ---------------------------------------------------------------------- - - ---------------------------------------------------------------------- - - ---------------------------------------------------------------------- - - -%h Emphasis - - - %!THIS IS BOLD TEXT%t %bTHIS IS BOLD TEXT%t %!This is italic text%t %- - bThis is italic text%t Strikethrough - - - -%h Blockquotes - - - Blockquotes can also be nested... - by using additional greater-than signs right next to each oth- - er... - or with spaces between arrows. - - -%h Lists - - -%h Unordered - - - + Create a list by starting a line with `=+`=, `=-`=, or `=*`= - - Marker character change forces new list start: - * Ac tristique libero volutpat at - + Facilisis in pretium nisl aliquet - - Nulla volutpat aliquam velit - + Very easy - - -%h Ordered - - - 1. Lorem ipsum dolor sit amet - 2. Consectetur adipiscing elit - 3. Integer molestie lorem at massa - - -%h Code - - - Inline `=code`= - - - - Indented code - - - - `= - // Some comments - line 1 of code - line 2 of code - line 3 of code - `= - - - Block code "fences" - - - - `= - Sample text here... - `= - - Syntax highlighting - - - - `= - var foo = function (bar) { - return bar++; - }; - - console.log(foo(5)); - `= - - -%h Links - - - link text () - - - - link with title () - - - -%h Images - - - Minion () Stormtroopocat - () - - + %h Tractaque serpens arva quoque + + + <>=======() + (/\___ /|\\ ()==========<>_ + \_/ | \\ //|\ ______/ \) + \_| \\ // | \_/ + \|\/|\_ // /\/ + (oo)\ \_// / + //_/\_\/ / | + @@/ |=\ \ | + \_=\_ \ | + \==\ \|\_ snd + __(\===\( )\ + (((~) __(_/ | + (((~) \ / + ______/ / + '------' Inprudens dum memor alma, casses dedi Sinuessa iam quid adicit `=gate- _truncate_wave`=. Geratur de (<#salientia-iungit-contra-et>), insolida @@ -195,7 +66,7 @@ -%h Quantaque augent + %h Quantaque augent Acuti ignotis ignis, ostendit nostras terras nondum, petit utque utero @@ -228,7 +99,7 @@ `= -%h Mille parva + %h Mille parva %!MINETUR ET%t aurum! Charaxi sanguine quo; vires subnectite %!PIGNOR- diff --git a/examples/loremipsum.md b/examples/loremipsum.md index 5b7af59..9f81442 100644 --- a/examples/loremipsum.md +++ b/examples/loremipsum.md @@ -39,7 +39,7 @@ populifer adeunt quicquam cum **ales** Ixion angulus placet reddere. ## Tractaque serpens arva quoque {:.center} -![[markdown.md]] +#[dragon :center](dragon.txt) Inprudens dum memor alma, casses dedi Sinuessa iam quid adicit `gate_truncate_wave`. [Geratur de](#salientia-iungit-contra-et), insolida diff --git a/examples/loremipsum.mu b/examples/loremipsum.mu index 7493d13..36c0d2e 100644 --- a/examples/loremipsum.mu +++ b/examples/loremipsum.mu @@ -1,19 +1,19 @@ - ___ _ _ _ _ - / __| __ _| (_)___ _ _| |_(_)__ _ - \__ \/ _` | | / -_) ' \ _| / _` | - |___/\__,_|_|_\___|_||_\__|_\__,_| + ___ _ _ _ _ + / __| __ _| (_)___ _ _| |_(_)__ _ + \__ \/ _` | | / -_) ' \ _| / _` | + |___/\__,_|_|_\___|_||_\__|_\__,_| ->> Structa hinc vetitus factum + >> Structa hinc vetitus factum Lorem markdownum omnes tellus, in, Herculeis `=reciprocalPower`= neque promissa est Latiae caput umero talia fidissima, nymphae. Foedera et sa- gittas tenetur adde matri esse: talia manibus. ->> Fuit video longique dedisse + >> Fuit video longique dedisse Ille stupet, ultra `!incunabula agendum urbes`! mirer `!aper`!, metu. A- egides novissima sunt turis quatiebant umbrosaque `[putares`#mille-parv- @@ -29,138 +29,23 @@ Ixion angulus placet reddere. ->> Tractaque serpens arva quoque - - - _ _ _ _ _ _ ___ __ - | |_ / | | || |___ __ _ __| (_)_ _ __ _ ( _ )__\ \ - | ' \| | | __ / -_) _` / _` | | ' \/ _` | / _ \___| | - |_||_|_| |_||_\___\__,_\__,_|_|_||_\__, | \___/ | | - |___/ /_/ - - ->> h2 Heading - - ->>> h3 Heading - - - _ _ _ _ _ _ _ - | |__ | || | | | | | ___ __ _ __| (_)_ __ __ _ - | '_ \| || |_ | |_| |/ _ \/ _` |/ _` | | '_ \ / _` | - | | | |__ _| | _ | __/ (_| | (_| | | | | | (_| | - |_| |_| |_| |_| |_|\___|\__,_|\__,_|_|_| |_|\__, | - |___/ - - - _ ____ _ _ _ _ - | |__ | ___| | | | | ___ __ _ __| (_)_ __ __ _ - | '_ \|___ \ | |_| |/ _ \/ _` |/ _` | | '_ \ / _` | - | | | |___) | | _ | __/ (_| | (_| | | | | | (_| | - |_| |_|____/ |_| |_|\___|\__,_|\__,_|_|_| |_|\__, | - |___/ - - - _ __ _ _ _ _ - | |__ / /_ | | | | ___ __ _ __| (_)_ __ __ _ - | '_ \| '_ \ | |_| |/ _ \/ _` |/ _` | | '_ \ / _` | - | | | | (_) | | _ | __/ (_| | (_| | | | | | (_| | - |_| |_|\___/ |_| |_|\___|\__,_|\__,_|_|_| |_|\__, | - |___/ - - ->> Horizontal Rules - - ------------------------------------------------------------------------ - ------------------------------------------------------------------------ - ------------------------------------------------------------------------ - - ->> Emphasis - - `!This is bold text`! `!This is bold text`! `*This is italic text`* `*T- - his is italic text`* ~~Strikethrough~~ - - ->> Blockquotes - - >>>>Blockquotes can also be nested... - - >>>>>>>>by using additional greater-than signs right next to each oth- - >>>>>>>>er... - - >>>>>>>>>>>>or with spaces between arrows. - - ->> Lists - - ->>> Unordered - - + Create a list by starting a line with `=+`=, `=-`=, or `=*`= - - Marker character change forces new list start: - * Ac tristique libero volutpat at - + 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 - - ->> Code - - Inline `=code`= - - - Indented code - - - `= - // Some comments - line 1 of code - line 2 of code - line 3 of code - `= - - Block code "fences" - - - `= - Sample text here... - `= - - Syntax highlighting - - - `= - var foo = function (bar) { - return bar++; - }; - - console.log(foo(5)); - `= - - ->> Links - - `[link text`http://dev.nodeca.com] - - - `[link with title`http://nodeca.github.io/pica/demo/ "title text!"] - - ->> Images - - `[Minion`https://octodex.github.com/images/minion.png] `[Stormtroopocat- - `https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopoc- - at"] - + >> Tractaque serpens arva quoque + <>=======() + (/\___ /|\\ ()==========<>_ + \_/ | \\ //|\ ______/ \) + \_| \\ // | \_/ + \|\/|\_ // /\/ + (oo)\ \_// / + //_/\_\/ / | + @@/ |=\ \ | + \_=\_ \ | + \==\ \|\_ snd + __(\===\( )\ + (((~) __(_/ | + (((~) \ / + ______/ / + '------' Inprudens dum memor alma, casses dedi Sinuessa iam quid adicit `=gate_t- runcate_wave`=. `[Geratur de`#salientia-iungit-contra-et], insolida tem- ptat `=open`= carentia; genitorem solet, potens. Adit vos ramos mundi c- @@ -171,7 +56,7 @@ el et at `=printerWildcardParallel`= inquit positosque comites ultra. ->> Quantaque augent + >> Quantaque augent Acuti ignotis ignis, ostendit nostras terras nondum, `[petit utque uter- o`#structa-hinc-vetitus-factum] sepulcrales, pluma reseratis Ismario. T- @@ -199,7 +84,7 @@ `= ->>> Mille parva + >>> Mille parva `!Minetur et`! aurum! Charaxi sanguine quo; vires subnectite `!pigno- ra`!, omnique hostibus loquerentur aquae Solis ferox? `!Cum ne`!, putat diff --git a/examples/markdown.ama b/examples/markdown.ama index 998b067..990eb07 100644 --- a/examples/markdown.ama +++ b/examples/markdown.ama @@ -7,10 +7,10 @@ |___/ /_/ -%h h2 Heading + %h h2 Heading -%h h3 Heading + %h h3 Heading _ _ _ _ _ _ _ @@ -37,7 +37,7 @@ |___/ -%h Horizontal Rules + %h Horizontal Rules -------------------------------------------------------------------------- @@ -47,7 +47,7 @@ -------------------------------------------------------------------------- -%h Emphasis + %h Emphasis %!THIS IS BOLD TEXT%t %bTHIS IS BOLD TEXT%t %!This is italic text%t %bThis @@ -55,7 +55,7 @@ -%h Blockquotes + %h Blockquotes Blockquotes can also be nested... @@ -63,10 +63,10 @@ or with spaces between arrows. -%h Lists + %h Lists -%h Unordered + %h Unordered + Create a list by starting a line with `=+`=, `=-`=, or `=*`= @@ -77,7 +77,7 @@ + Very easy -%h Ordered + %h Ordered 1. Lorem ipsum dolor sit amet @@ -85,7 +85,7 @@ 3. Integer molestie lorem at massa -%h Code + %h Code Inline `=code`= @@ -125,7 +125,7 @@ `= -%h Links + %h Links link text () @@ -136,7 +136,7 @@ -%h Images + %h Images Minion () Stormtroopocat diff --git a/examples/markdown.mu b/examples/markdown.mu index 2b36b50..a4371f9 100644 --- a/examples/markdown.mu +++ b/examples/markdown.mu @@ -7,10 +7,10 @@ |___/ /_/ ->> h2 Heading + >> h2 Heading ->>> h3 Heading + >>> h3 Heading _ _ _ _ _ _ _ @@ -37,20 +37,20 @@ |___/ ->> Horizontal Rules + >> Horizontal Rules ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ->> Emphasis + >> Emphasis `!This is bold text`! `!This is bold text`! `*This is italic text`* `*This is italic text`* ~~Strikethrough~~ ->> Blockquotes + >> Blockquotes >>>>Blockquotes can also be nested... @@ -59,10 +59,10 @@ >>>>>>>>>>>>or with spaces between arrows. ->> Lists + >> Lists ->>> Unordered + >>> Unordered + Create a list by starting a line with `=+`=, `=-`=, or `=*`= - Marker character change forces new list start: @@ -72,14 +72,14 @@ + Very easy ->>> Ordered + >>> Ordered 1. Lorem ipsum dolor sit amet 2. Consectetur adipiscing elit 3. Integer molestie lorem at massa ->> Code + >> Code Inline `=code`= @@ -113,7 +113,7 @@ `= ->> Links + >> Links `[link text`http://dev.nodeca.com] @@ -121,7 +121,7 @@ `[link with title`http://nodeca.github.io/pica/demo/ "title text!"] ->> Images + >> Images `[Minion`https://octodex.github.com/images/minion.png] `[Stormtroopocat`https://octodex.github.com/images/stormtroopocat.jpg "The diff --git a/src/md2txt/renderers/ama.py b/src/md2txt/renderers/ama.py index 185af07..3003713 100644 --- a/src/md2txt/renderers/ama.py +++ b/src/md2txt/renderers/ama.py @@ -50,12 +50,22 @@ class AmaRenderer(TextRenderer): def _render_heading(self, payload: HeadingPayload, style: BlockStyle) -> None: self._ensure_header_spacing() - figlet = self._render_figlet_heading(payload.level, payload.text, style) - if figlet and all(len(line.rstrip()) <= self.width for line in figlet): - self._emit_block(figlet, stylable=False) - return - heading = self._process_inline(payload.text) - self._emit_block([f"%h {heading}", ""], stylable=False) + def render_fn(target_style: BlockStyle) -> List[str]: + figlet = self._render_figlet_heading(payload.level, payload.text, target_style) + if figlet and all(len(line.rstrip()) <= self.width for line in figlet): + return [*figlet, ""] + heading = self._process_inline(payload.text) + wrapped = self._wrap_text( + heading, + style=target_style, + initial_indent="%h ", + subsequent_indent="%h ", + ) + if not wrapped or wrapped[-1] != "": + wrapped.append("") + return wrapped + + self._emit_block(render_fn(style), stylable=True, render_fn=render_fn, style=style) def _render_code_block(self, payload: CodeBlockPayload, style: BlockStyle) -> None: margin_left, _, _ = self._margins(style) diff --git a/src/md2txt/renderers/micron.py b/src/md2txt/renderers/micron.py index 38a1992..95d500c 100644 --- a/src/md2txt/renderers/micron.py +++ b/src/md2txt/renderers/micron.py @@ -42,14 +42,24 @@ class MicronRenderer(TextRenderer): def _render_heading(self, payload: HeadingPayload, style: BlockStyle) -> None: self._ensure_header_spacing() - figlet = self._render_figlet_heading(payload.level, payload.text, style) - if figlet and all(len(line.rstrip()) <= self.width for line in figlet): - self._emit_block(figlet, stylable=False) - return - level = max(1, min(3, payload.level)) - marker = ">" * level - line = f"{marker} {self._process_inline(payload.text)}".rstrip() - self._emit_block([line, ""], stylable=False) + def render_fn(target_style: BlockStyle) -> List[str]: + figlet = self._render_figlet_heading(payload.level, payload.text, target_style) + if figlet and all(len(line.rstrip()) <= self.width for line in figlet): + return [*figlet, ""] + level = max(1, min(3, payload.level)) + marker = ">" * level + heading = f"{marker} {self._process_inline(payload.text)}".rstrip() + wrapped = self._wrap_text( + heading, + style=target_style, + initial_indent="", + subsequent_indent="", + ) + if not wrapped or wrapped[-1] != "": + wrapped.append("") + return wrapped + + self._emit_block(render_fn(style), stylable=True, render_fn=render_fn, style=style) def _render_code_block(self, payload: CodeBlockPayload, style: BlockStyle) -> None: margin_left, _, _ = self._margins(style)