Xwiki Import Markdown Now
--- title: My Document author: John Doe date: 2024-01-01 tags: [wiki, markdown] --- Convert to XWiki properties:
data = { "title": page_name, "content": wiki_content, "syntaxId": "xwiki/2.1" }
# Wrap in markdown macro wiki_content = f"{{{{markdown}}}}\n{markdown_content}\n{{{{/markdown}}}}" xwiki import markdown
# Headers markdown_text = re.sub(r'^# (.*?)$', r'= \1 =', markdown_text, flags=re.M) markdown_text = re.sub(r'^## (.*?)$', r'== \1 ==', markdown_text, flags=re.M) markdown_text = re.sub(r'^### (.*?)$', r'=== \1 ===', markdown_text, flags=re.M)
return markdown_text with open('document.md', 'r') as f: md_content = f.read() --- title: My Document author: John Doe date:
# Bold and Italic markdown_text = re.sub(r'\*\*(.*?)\*\*', r'**\1**', markdown_text) markdown_text = re.sub(r'\*(.*?)\*', r'//\1//', markdown_text)
Link {{/markdown}} Copy-paste your Markdown file content between the {{markdown}} tags. Method 2: Using REST API (For Batch Import) Python Script Example import requests import os from requests.auth import HTTPBasicAuth Configuration XWIKI_URL = "http://localhost:8080/xwiki" USERNAME = "Admin" PASSWORD = "admin" SPACE = "Main" r'= \1 ='
# Prepare API request url = f"{XWIKI_URL}/rest/wikis/xwiki/spaces/{SPACE}/pages/{page_name}"
# Read markdown content with open(file_path, 'r', encoding='utf-8') as f: markdown_content = f.read()
# Links markdown_text = re.sub(r'\[(.*?)\]\((.*?)\)', r'[[\1>>\2]]', markdown_text)
# Inline code markdown_text = re.sub(r'`(.*?)`', r'{{code}}\1{{/code}}', markdown_text)