diff options
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | TODO.md | 2 | ||||
-rwxr-xr-x | divergence | 32 | ||||
-rw-r--r-- | pandoc_confluence.lua | 8 | ||||
-rwxr-xr-x | test-ia-bnewbold.sh | 16 |
5 files changed, 61 insertions, 13 deletions
@@ -31,8 +31,8 @@ it will Just Work without needing any administrative intervention. # Usage - export CONFLUENCE_USER=`whoami` - export CONFLUENCE_PASSWORD="password123" + export CONFLUENCE_USER="user123" + export CONFLUENCE_PASSWORD="password456" export CONFLUENCE_URL="https://evil-corp.jira.com/wiki/" ./divergence -s "PROD25" Acme_Widget_Docs.md @@ -47,8 +47,16 @@ Multiple files can be uploaded at the same time. If you have in-line images you'll need to upload them manually. Haven't tried it yet. -You might want to write a shell script wrapper to help with configuration and -pushing multiple files to multiple spaces. +You might want to write a shell script wrapper to automate configuration; you +could also set these variables in `~/.profile` or similar: + + #!/bin/bash + + export CONFLUENCE_USER=`whoami` + export CONFLUENCE_PASSWORD=`pass evil-corp.jira.com | head -n1` + export CONFLUENCE_URL="https://evil-corp.jira.com/wiki/" + + divergence -v $* It's probably possible to use any pandoc-supported markup file format (not just Markdown), but this hasn't been tested. @@ -4,6 +4,8 @@ TODO: Nice to have, but unlikely to be implemented: - more than just markdown (restructured text, html, etc) - configurable banner at the top of rendered pages ("this uploaded from...") +- generate disclaimer header / banner with link to canonical source + - rather than raw HTML that triggers WARNING: Undefined function 'RawInline' - color output, one line per file - detecting and uploading included image files as attachments. `confluence-sync` does this @@ -18,12 +18,16 @@ import subprocess import logging as log +DEFAULT_HEADER = """This page was generated automatically from Markdown using +the 'divergence' tool. Edits will need to be merged manually.""" + class DivergenceProgram: def __init__(self, user, password, url, space, force_update=False, include_toc=False, - include_header=True): + header=None, + no_header=False): self.api = requests.Session() self.api.auth = (user, password) self.api.headers.update({'Content-Type': 'application/json'}) @@ -31,7 +35,8 @@ class DivergenceProgram: self.default_space = space self.force_update = force_update self.include_toc = include_toc - self.include_header = include_header + self.header = header # from command-line arg + self.no_header = no_header # from command-line arg # TODO: clean up this code duplication... use pandoc data directory # instead? self.pandoc_helper_path = None @@ -139,7 +144,7 @@ class DivergenceProgram: # TODO: only alphanum and spaces? return title - def convert(self, f): + def convert(self, f, header=None): proc = subprocess.run(["pandoc", "-t", self.pandoc_helper_path, f], stdout=subprocess.PIPE) assert proc.returncode == 0 @@ -149,11 +154,10 @@ class DivergenceProgram: <ac:parameter ac:name="minLevel">1</ac:parameter> <ac:parameter ac:name="maxLevel">3</ac:parameter> </ac:structured-macro>""" + body - if self.include_header: + if header: body = """<ac:structured-macro ac:name="info"> <ac:rich-text-body> - <p>This page was generated automatically from Markdown using the - 'divergence' tool. Edits will need to be merged manually. </p> + <p>""" + header + """</p> </ac:rich-text-body> </ac:structured-macro>\n""" + body return body @@ -180,8 +184,12 @@ class DivergenceProgram: space_key = meta.get('confluence-space-key', self.default_space) page_id = meta.get('confluence-page-id') + header = not self.no_header and ( # --no-header trumps all + self.header or # command-line value gets priority + meta.get('disclaimer-header') or # fall back to per-file + DEFAULT_HEADER ) log.debug(title) - body = self.convert(f) + body = self.convert(f, header) prev = self.get_page(title, space_key=space_key, page_id=page_id) log.debug(prev) if prev is None: @@ -225,6 +233,9 @@ required environment variables: parser.add_argument("-f", "--force", action='store_true', help='Forces an update even if we think nothing has changed') + parser.add_argument("--header", + action='store', + help='Specify header to insert into the confluence document') parser.add_argument("--no-header", action='store_true', help='Disables inserting disclaimer headers into the confluence document') @@ -257,7 +268,10 @@ required environment variables: if args.space_key is None: args.space_key = "~" + user - log.warn("Defaulting to home space: %s" % args.space_key) + log.warning("Defaulting to home space: %s" % args.space_key) + + if args.header and args.no_header: + parser.exit(-1, "Pick one of --header and --no_header.\n") try: subprocess.check_output(['pandoc', '--version']) @@ -267,7 +281,7 @@ required environment variables: dp = DivergenceProgram(user,password, url, args.space_key, force_update=args.force, - include_header=not args.no_header, + header=args.header, include_toc=args.toc) dp.run(args.FILE) diff --git a/pandoc_confluence.lua b/pandoc_confluence.lua index 18823a7..78c08d6 100644 --- a/pandoc_confluence.lua +++ b/pandoc_confluence.lua @@ -222,6 +222,14 @@ function Header(lev, s, attr) return anchor(attr.id) .. "<h" .. lev .. attributes(attr) .. ">" .. s .. "</h" .. lev .. ">" end +function SingleQuoted(s) + return "'" .. s .. "'" +end + +function DoubleQuoted(s) + return """ .. s .. """ +end + function BlockQuote(s) return "<blockquote><p>" .. s .. "</p></blockquote>" end diff --git a/test-ia-bnewbold.sh b/test-ia-bnewbold.sh new file mode 100755 index 0000000..2a92a09 --- /dev/null +++ b/test-ia-bnewbold.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +export CONFLUENCE_URL="https://webarchive.jira.com/wiki/" + +# won't work for all users... +export CONFLUENCE_USER=`whoami` +export CONFLUENCE_PASSWORD=`pass archive/webarchive.jira.com | head -n1` +CONFLUENCE_SPACEID="~$CONFLUENCE_USER" + +# TODO: check for variable errors here... + +./divergence \ + --space-key $CONFLUENCE_SPACEID \ + -vvv \ + --toc \ + Brozzler_Docs.md Brozzler_Meta.md |