feat: add inline code, ordered lists, horizontal rules, bold+italic, strikethrough - #1
Open
cyclingwithelephants wants to merge 2 commits into
Open
feat: add inline code, ordered lists, horizontal rules, bold+italic, strikethrough#1cyclingwithelephants wants to merge 2 commits into
cyclingwithelephants wants to merge 2 commits into
Conversation
…strikethrough
Extend parse_inline() with new inline formatting patterns:
- Inline code (`code`) with correct pattern ordering to prevent
backtick content from being parsed as bold/italic
- Bold+italic combo (***text***) matched before bold/italic
- Strikethrough (~~text~~)
Extend from_markdown() with new block-level elements:
- Ordered lists (1. item) mirroring existing bullet list pattern
- Horizontal rules (---, ***, ___) using existing horizontal_rule() method
Fix parse_inline() token format in list items and blockquotes:
- Add tokens_to_text_nodes() helper that converts parse_inline() tokens
({"content": "text"}) to valid ProseMirror text nodes
({"type": "text", "text": "text"}) with marks preserved
- Apply to flush_bullets, flush_ordered, flush_quotes, and single-line
variants — fixes Substack rendering empty body for lists/blockquotes
All features verified against live Substack API.
Includes 33 new unit tests covering all additions plus regression tests.
| if not any(start <= match.start() < end for start, end, _, _, _ in matches): | ||
| matches.append((match.start(), match.end(), "bold_italic", match.group(1), None)) | ||
|
|
||
| # 4. Bold |
Owner
Author
There was a problem hiding this comment.
remove the numbering, keep the section titles
Comment on lines
+5
to
+6
| Post Utilities | ||
|
|
Owner
Author
There was a problem hiding this comment.
this is repeated
| self.add({"type": "paragraph", "content": tokens}) | ||
| # Check for single-line ordered list | ||
| ordered_match = re.match(r'^(\d+)\.\s+(.*)', text_content) | ||
| if ordered_match: |
Owner
Author
There was a problem hiding this comment.
can we use an early return to simplify this?
- Fix duplicate "Post Utilities" in module docstring - Remove numbering from parse_inline section comments - Flatten single-line blockquote/ordered/paragraph branch with elif
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends
parse_inline()andfrom_markdown()with missing markdown features, plus fixes a bug where list items and blockquotes produced invalid ProseMirror JSON.Changes
New inline formatting in
parse_inline()`code`) →{"type": "code"}mark***text***) →[{"type": "strong"}, {"type": "em"}]marks~~text~~) →{"type": "strikethrough"}markNew block elements in
from_markdown()1. item) →{"type": "ordered_list"}node, mirroring existing bullet list pattern---,***,___) → calls existinghorizontal_rule()methodBug fix:
tokens_to_text_nodes()List items and blockquotes were using raw
parse_inline()tokens ({"content": "text"}) instead of valid ProseMirror text nodes ({"type": "text", "text": "text"}). This caused Substack's editor to render empty bodies. Marks were also being dropped in blockquotes.Testing
tests/substack/test_post_extended.pytest_post.pytests pass unchanged