Package: markdown-to-confluence
Publish Markdown files to Confluence wikiContributors to software projects typically write documentation in Markdown format and host Markdown files in collaborative version control systems (VCS) such as GitHub or GitLab to track changes and facilitate the review process. However, not everyone at a company has access to VCS, and documents are often circulated in Confluence wiki instead.Replicating documentation to Confluence by hand is tedious, and a lack of automated synchronization with the project repositories where the documents live leads to outdated documentation.This Python packageparses Markdown files,converts Markdown content into the Confluence Storage Format (XHTML),invokes Confluence API endpoints to upload images and content.FeaturesSections and subsectionsText withbold,italic,monospace, underline andstrikethroughLink toexternal locationsOrdered and unordered listsCode blocks (e.g. Python, JSON, XML)Image references (uploaded as Confluence page attachments)Table of ContentsAdmonitions(converted intoinfo,tip,noteandwarningConfluence panels)Getting startedIn order to get started, you will needyour organization domain name (e.g.instructure.atlassian.net),base path for Confluence wiki (typically/wiki/for managed Confluence,/for on-premise)your Confluence username (e.g.levente.hunyadi@instructure.com) (only if required by your deployment),a Confluence API token (a string of alphanumeric characters), andthe space key in Confluence (e.g.DAP) you are publishing content to.Obtaining an API tokenLog in tohttps://id.atlassian.com/manage/api-tokens.ClickCreate API token.From the dialog that appears, enter a memorable and conciseLabelfor your token and clickCreate.ClickCopy to clipboard, then paste the token to your script, or elsewhere to save.Setting up the environmentConfluence organization domain, base path, username, API token and space key can be specified at runtime or set as Confluence environment variables (e.g. add to your~/.profileon Linux, or~/.bash_profileor~/.zshenvon MacOS):exportCONFLUENCE_DOMAIN='instructure.atlassian.net'exportCONFLUENCE_PATH='/wiki/'exportCONFLUENCE_USER_NAME='levente.hunyadi@instructure.com'exportCONFLUENCE_API_KEY='0123456789abcdef'exportCONFLUENCE_SPACE_KEY='DAP'On Windows, these can be set via system properties.PermissionsThe tool requires appropriate permissions in Confluence in order to invoke endpoints.If a Confluence username is set, the tool uses HTTPBasicauthentication to pass the username and the API key to Confluence REST API endpoints. If no username is provided, the tool authenticates with HTTPBearer, and passes the API key as the bearer token.If you lack appropriate permissions, you will get anUnauthorizedresponse from Confluence. The tool will emit a message that looks as follows:2023-06-30 23:59:59,000 - ERROR - <module> [80] - 401 Client Error: Unauthorized for url: ...Associating a Markdown file with a wiki pageEach Markdown file is associated with a Confluence wiki page with a Markdown comment:<!-- confluence-page-id: 85668266616 -->The above tells the tool to synchronize the Markdown file with the given Confluence page ID. This implies that the Confluence wiki page must exist such that it has an ID. The comment can be placed anywhere in the source file.Setting the Confluence spaceIf you work in an environment where there are multiple Confluence spaces, and some Markdown pages may go into one space, whereas other pages may go into another, you can set the target space on a per-document basis:<!-- confluence-space-key: DAP -->This overrides the default space set via command-line arguments or environment variables.Setting generated-by prompt text for wiki pagesIn order to ensure readers are not editing a generated document, the tool adds a warning message at the top of the Confluence page as aninfo panel. You can customize the text that appears. The text can contain markup as per theConfluence Storage Format, and is emitted directly into theinfo panelmacro.Provide generated-by prompt text in the Markdown file with a tag:<!-- generated-by: Do not edit! Check out the <a href="https://example.com/project">original source</a>. -->Alternatively, use the--generated-by GENERATED_BYoption. The tag takes precedence.Running the toolYou execute the command-line toolmd2confto synchronize the Markdown file with Confluence:$python3-mmd2confsample/example.mdUse the--helpswitch to get a full list of supported command-line options:$python3-mmd2conf--helpusage: md2conf [-h] [-d DOMAIN] [-p PATH] [-u USERNAME] [-a APIKEY] [-s SPACE] [-l {debug,info,warning,error,critical}][--generated-by GENERATED_BY] [--no-generated-by] [--ignore-invalid-url]mdpathpositional arguments:mdpath                Path to Markdown file or directory to convert and publish.options:-h, --help            show this help message and exit-d DOMAIN, --domain DOMAINConfluence organization domain.-p PATH, --path PATH  Base path for Confluece wiki.-u USERNAME, --username USERNAMEConfluence user name.-a APIKEY, --apikey APIKEYConfluence API key. Refer to documentation how to obtain one.-s SPACE, --space SPACEConfluence space key for pages to be published. If omitted, will default to user space.-l {debug,info,warning,error,critical}, --loglevel {debug,info,warning,error,critical}Use this option to set the log verbosity.--generated-by GENERATED_BYAdd prompt to pages (default: 'This page has been generated with a tool.').--no-generated-by     Do not add 'generated by a tool' prompt to pages.--ignore-invalid-url  Emit a warning but otherwise ignore relative URLs that point to ill-specified locations.