Skip to content

Instantly share code, notes, and snippets.

@quest4i
Created June 12, 2023 02:00
Show Gist options
  • Save quest4i/3b8b287e8158b63220550ecbcb98555f to your computer and use it in GitHub Desktop.
Save quest4i/3b8b287e8158b63220550ecbcb98555f to your computer and use it in GitHub Desktop.
Convert Cofluence wiki page to markdown
# pip module - atlassian-python-api, markdownify
from atlassian import Confluence
from markdownify import markdownify as md
page = confluence.get_page_by_id(261095431, expand='body.storage')
body_html = page['body']['storage']['value']
body_markdown = md(body_html)
@vigneshwaran-arumugam
Copy link

This code made my day.

@Aktsvigun
Copy link

Aktsvigun commented Aug 6, 2024

Amazing job, really works nice, thank you! In my case, it handled ~ 80% cases. I used the following function to remove the html trash from the rest 20%:

def clean_markdown(text):
    # Match everything up to the first occurrence of a JSON-like structure
    match = re.search(r'([\s\S]*?)\{\s*"id":', text)
    if match:
        return match.group(1).strip()
    return text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment