def editor_to_storage(con: Confluence, source: str) -> str: """ Convert source string from confluence editor format to storage format and return it. This method required a confluence connection. `con` — a Confluence connection; `source` — original source in editor format. Returns a converted source in storage format. """ data = {"value": source, "representation": "editor"} res = con.post('rest/api/contentbody/convert/storage', data=data) if res and 'value' in res: return res['value'] else: raise RuntimeError('Cannot convert editor to storage. Got response:' f'\n{res}')
def post_to_convert_api(confluence: Confluence, text: str) -> str: url = "rest/tinymce/1/markdownxhtmlconverter" # the endpoint returns plain text, need to redefine the default header headers = {"Content-Type": "application/json"} # Keep until https://github.com/atlassian-api/atlassian-python-api/pull/684 is released original_advanced_mode = confluence.advanced_mode if confluence.advanced_mode is False or confluence.advanced_mode is None: confluence.advanced_mode = True response: Response = confluence.post(url, data={"wiki": text}, headers=headers) # No way to trigger failure for this during tests response.raise_for_status() # pragma: no cover confluence.advanced_mode = original_advanced_mode return response.text