def update_from_editor(self):
# Example Data:
"""
{
"id": "3604482",
"type": "page",
"title": "new page",
"space": {
"key": "TST"
},
"body": {
"storage": {
"value": "<p>This is the updated text for the new page</p>",
"representation": "storage"
}
},
"version": {
"number": 2
}
}
"""
content_id = self.content["id"]
title = self.content["title"]
space_key = self.content["space"]["key"]
version_number = self.content["version"]["number"] + 1
region = sublime.Region(0, self.view.size())
contents = self.view.substr(region)
syntax = self.view.settings().get("syntax")
if "HTML" in syntax:
new_content = "".join(contents.split("\n"))
else:
markup = Markup()
meta, content = markup.get_meta_and_content(contents)
new_content = markup.to_html("\n".join(content), syntax)
space = dict(key=space_key)
version = dict(number=version_number, minorEdit=False)
body = dict(storage=dict(value=new_content, representation="storage"))
data = dict(id=content_id, type="page", title=title,
space=space, version=version, body=body)
try:
self.confluence_api = ConfluenceApi(self.username, self.password, self.base_uri)
response = self.confluence_api.update_content(content_id, data)
if response.ok:
content_uri = self.confluence_api.get_content_uri(self.content)
sublime.set_clipboard(content_uri)
sublime.status_message(self.MSG_SUCCESS)
self.view.settings().set("confluence_content", response.json())
else:
print(response.text)
sublime.error_message("Can't update content, reason: {}".format(response.reason))
except Exception:
print(response.text)
sublime.error_message("Can't update content, reason: {}".format(response.reason))
评论列表
文章目录