René's URL Explorer Experiment


Title: Mark down to post style is not there. · Issue #31 · ma2za/python-substack · GitHub

Open Graph Title: Mark down to post style is not there. · Issue #31 · ma2za/python-substack

X Title: Mark down to post style is not there. · Issue #31 · ma2za/python-substack

Description: This solution adds Markdown support to your Substack newsletter workflow. It includes a parser for inline Markdown formatting (supporting bold and italic text) and a function that processes a Markdown file to create a structured post dra...

Open Graph Description: This solution adds Markdown support to your Substack newsletter workflow. It includes a parser for inline Markdown formatting (supporting bold and italic text) and a function that processes a Markd...

X Description: This solution adds Markdown support to your Substack newsletter workflow. It includes a parser for inline Markdown formatting (supporting bold and italic text) and a function that processes a Markd...

Opengraph URL: https://github.com/ma2za/python-substack/issues/31

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mark down to post style is not there.","articleBody":"This solution adds Markdown support to your Substack newsletter workflow. It includes a parser for inline Markdown formatting (supporting **bold** and *italic* text) and a function that processes a Markdown file to create a structured post draft. \n\nFor those who might be doubting if it works, here’s a link as evidence of its functionality: [[Check if it works](https://gist.github.com/Duartemartins/98afb33ca5eae545e909df41be45f39e)](https://gist.github.com/Duartemartins/98afb33ca5eae545e909df41be45f39e).\n\n---\n\n### Overview\n\n- **Inline Markdown Parsing:**  \n  The `parse_inline` function scans a text string for inline Markdown patterns (like **bold** and *italic*) and converts them into tokens with corresponding formatting marks.\n\n- **Post Draft Creation:**  \n  The `publish_newsletter_to_substack` function reads a Markdown file, splits its content into blocks (headings, images, paragraphs, or bullet lists), and converts these into a structured Post object. It then creates and pre-publishes a draft on Substack.\n\n---\n\n### Code Implementation\n\n```python\nimport re\n\ndef parse_inline(text):\n    \"\"\"\n    Convert inline Markdown in a text string into a list of tokens\n    for use in the post content.\n\n    Supported formatting:\n      - **Bold**: Text wrapped in double asterisks.\n      - *Italic*: Text wrapped in single asterisks.\n    \"\"\"\n    tokens = []\n    # Pattern matches either **bold** or *italic* text.\n    pattern = r'(\\*\\*.*?\\*\\*|\\*.*?\\*)'\n    parts = re.split(pattern, text)\n    \n    for part in parts:\n        if not part:\n            continue\n        if part.startswith(\"**\") and part.endswith(\"**\"):\n            content = part[2:-2]\n            tokens.append({\"content\": content, \"marks\": [{\"type\": \"strong\"}]})\n        elif part.startswith(\"*\") and part.endswith(\"*\"):\n            content = part[1:-1]\n            tokens.append({\"content\": content, \"marks\": [{\"type\": \"em\"}]})\n        else:\n            tokens.append({\"content\": part})\n    \n    return tokens\n\ndef publish_newsletter_to_substack(api):\n    \"\"\"\n    Reads a Markdown file, converts its content into a structured Post,\n    and creates a draft post on Substack.\n\n    Workflow:\n      1. Retrieve the user profile to extract the user ID.\n      2. Read and parse the Markdown file.\n      3. Convert Markdown blocks into post elements:\n         - Headings (lines starting with '#' characters).\n         - Images (using Markdown image syntax: ![Alt](URL)).\n         - Paragraphs and bullet lists with inline Markdown formatting.\n      4. Create and update the draft post.\n    \"\"\"\n    # Retrieve user profile to extract user ID.\n    profile = retry_on_502(lambda: api.get_user_profile())\n    user_id = profile.get(\"id\")\n    if not user_id:\n        raise ValueError(\"Could not get user ID from profile\")\n    \n    # Create a Post instance.\n    post = Post(\n        title=\"FIX TITLE\",  # Replace with the desired title.\n        subtitle=\"\",        # Optionally customize the subtitle.\n        user_id=user_id\n    )\n    \n    # Read the Markdown file.\n    with open(\"blog_0_2025-03-28T19-46-34-098Z.md\", 'r', encoding='utf-8') as f:\n        md_content = f.read()\n    \n    # Split content into blocks separated by double newlines.\n    blocks = md_content.split(\"\\n\\n\")\n    \n    for block in blocks:\n        block = block.strip()\n        if not block:\n            continue\n        \n        # Process headings (lines starting with '#' characters).\n        if block.startswith(\"#\"):\n            level = len(block) - len(block.lstrip('#'))\n            heading_text = block.lstrip('#').strip()\n            post.heading(content=heading_text, level=level)\n        \n        # Process images using Markdown image syntax: ![Alt](URL)\n        elif block.startswith(\"!\"):\n            m = re.match(r'!\\[.*?\\]\\((.*?)\\)', block)\n            if m:\n                image_url = m.group(1)\n                # Adjust image URL if it starts with a slash.\n                image_url = image_url[1:] if image_url.startswith('/') else image_url\n                image = api.get_image(image_url)\n                post.add({\"type\": \"captionedImage\", \"src\": image.get(\"url\")})\n        \n        # Process paragraphs or bullet lists.\n        else:\n            if \"\\n\" in block:\n                # Process each line separately.\n                for line in block.split(\"\\n\"):\n                    line = line.strip()\n                    if not line:\n                        continue\n                    # Remove bullet marker if present.\n                    if line.startswith(\"*\"):\n                        line = line.lstrip(\"*\").strip()\n                    tokens = parse_inline(line)\n                    post.add({\"type\": \"paragraph\", \"content\": tokens})\n            else:\n                tokens = parse_inline(block)\n                post.add({\"type\": \"paragraph\", \"content\": tokens})\n    \n    # Create and update the draft post.\n    draft = api.post_draft(post.get_draft())\n    api.put_draft(draft.get(\"id\"), draft_section_id=post.draft_section_id)\n    api.prepublish_draft(draft.get(\"id\"))\n    \n    print(\"Newsletter published (drafted) successfully!\")\n```\n\n---","author":{"url":"https://github.com/a1111198","@type":"Person","name":"a1111198"},"datePublished":"2025-04-01T12:40:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/31/python-substack/issues/31"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:06799b70-eb95-eaed-c056-c76863e31056
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDE9A:1D22:80522D:AA3700:698D8946
html-safe-nonceda352e180df8001f436d06499bc732b020f99e1f81f8968d057e047dbe55a939
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTlBOjFEMjI6ODA1MjJEOkFBMzcwMDo2OThEODk0NiIsInZpc2l0b3JfaWQiOiIzMTYwMjEyMTI2MTQxNjE0NDA2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac200d820e4d5ddb14a6c428346f8569b016cb9309ae29ed616d0071dea6036fea
hovercard-subject-tagissue:2963327876
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/ma2za/python-substack/31/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6ba0e9ffde57293cafdcf55fcefd4a5d7728c5c5d5f4d33b338ca0a65f2ea5bb/ma2za/python-substack/issues/31
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6ba0e9ffde57293cafdcf55fcefd4a5d7728c5c5d5f4d33b338ca0a65f2ea5bb/ma2za/python-substack/issues/31
og:image:altThis solution adds Markdown support to your Substack newsletter workflow. It includes a parser for inline Markdown formatting (supporting bold and italic text) and a function that processes a Markd...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamea1111198
hostnamegithub.com
expected-hostnamegithub.com
Nonec0818105fa276287e9369cfdefa0a0fa7953719791ceff9b94d69623c0a4fe8a
turbo-cache-controlno-preview
go-importgithub.com/ma2za/python-substack git https://github.com/ma2za/python-substack.git
octolytics-dimension-user_id59370937
octolytics-dimension-user_loginma2za
octolytics-dimension-repository_id507708304
octolytics-dimension-repository_nwoma2za/python-substack
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id507708304
octolytics-dimension-repository_network_root_nwoma2za/python-substack
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release4c8f4bd0b67d7f1472d0ab3f49827eaae062a36b
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/ma2za/python-substack/issues/31#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fma2za%2Fpython-substack%2Fissues%2F31
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fma2za%2Fpython-substack%2Fissues%2F31
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=ma2za%2Fpython-substack
Reloadhttps://patch-diff.githubusercontent.com/ma2za/python-substack/issues/31
Reloadhttps://patch-diff.githubusercontent.com/ma2za/python-substack/issues/31
Reloadhttps://patch-diff.githubusercontent.com/ma2za/python-substack/issues/31
ma2za https://patch-diff.githubusercontent.com/ma2za
python-substackhttps://patch-diff.githubusercontent.com/ma2za/python-substack
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fma2za%2Fpython-substack
Fork 21 https://patch-diff.githubusercontent.com/login?return_to=%2Fma2za%2Fpython-substack
Star 136 https://patch-diff.githubusercontent.com/login?return_to=%2Fma2za%2Fpython-substack
Code https://patch-diff.githubusercontent.com/ma2za/python-substack
Issues 5 https://patch-diff.githubusercontent.com/ma2za/python-substack/issues
Pull requests 0 https://patch-diff.githubusercontent.com/ma2za/python-substack/pulls
Actions https://patch-diff.githubusercontent.com/ma2za/python-substack/actions
Projects 0 https://patch-diff.githubusercontent.com/ma2za/python-substack/projects
Security 0 https://patch-diff.githubusercontent.com/ma2za/python-substack/security
Insights https://patch-diff.githubusercontent.com/ma2za/python-substack/pulse
Code https://patch-diff.githubusercontent.com/ma2za/python-substack
Issues https://patch-diff.githubusercontent.com/ma2za/python-substack/issues
Pull requests https://patch-diff.githubusercontent.com/ma2za/python-substack/pulls
Actions https://patch-diff.githubusercontent.com/ma2za/python-substack/actions
Projects https://patch-diff.githubusercontent.com/ma2za/python-substack/projects
Security https://patch-diff.githubusercontent.com/ma2za/python-substack/security
Insights https://patch-diff.githubusercontent.com/ma2za/python-substack/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/ma2za/python-substack/issues/31
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/ma2za/python-substack/issues/31
Mark down to post style is not there.https://patch-diff.githubusercontent.com/ma2za/python-substack/issues/31#top
https://github.com/a1111198
https://github.com/a1111198
a1111198https://github.com/a1111198
on Apr 1, 2025https://github.com/ma2za/python-substack/issues/31#issue-2963327876
Check if it workshttps://gist.github.com/Duartemartins/98afb33ca5eae545e909df41be45f39e
https://gist.github.com/Duartemartins/98afb33ca5eae545e909df41be45f39ehttps://gist.github.com/Duartemartins/98afb33ca5eae545e909df41be45f39e
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.