diff --git a/Makefile b/Makefile index f8329cf..af96796 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,13 @@ MDPROC = pandoc PANDOCTEMPLATE_TEX = tex/trello.latex #$< is the first "source" #$@ is the "target to generate" + +# to add the table of contents add the following to MDPARAMS_PDF +# --variable=toc:1 + +# to get less margins add the following to MDPARAMS_PDF +# --variable=margin-left:2cm --variable=margin-right:2cm --variable=margin-top:2cm --variable=margin-bottom:2cm + MDPARAMS_PDF = $< -o $@ --template=`pwd`/$(PANDOCTEMPLATE_TEX) MDPARAMS_HTML = $< -o $@ MDPARAMS_TEX = $< -o $@ diff --git a/src/trello2md.py b/src/trello2md.py index faba1f2..211a0f6 100755 --- a/src/trello2md.py +++ b/src/trello2md.py @@ -40,13 +40,41 @@ def prepare_content(content): return '\n'.join(result) ################################################################################ -def print_card(card_id, data, print_labels, print_card_links): - """Print name, content and attachments of a card.""" +def prepare_all_comments(data): + """Returns a dictionary for each card_id with a list of comments""" + ret = {} + + for action in data['actions']: + if action["type"] == "commentCard": + card_id = action["data"]["card"]["id"] + + if not card_id in ret: + ret[card_id] = [] + + name = action["memberCreator"]["fullName"] + date = action["date"] + content = prepare_content(action["data"]["text"]) + + comment_string = "- **{name}** ({date}):\n {content} \n".format( + name=name, date=date, content=content) + + ret[card_id].append(comment_string) + return ret + +################################################################################ +def print_card(card_id, data, comments, print_labels): + """Print name, content, comments and attachments of a card.""" # get card and pre-format content card = next(c for c in data['cards'] if c['id'] == card_id) content = prepare_content(card['desc']) + '\n' + comment_output = '' + #comments are empty if they should not be printed + if card_id in comments: + comment_output = '### Comments ###\n' + comment_output += '\n\n'.join(comments[card_id]) + # format labels, if wanted labels = [] if print_labels and card['labels']: @@ -69,10 +97,11 @@ def print_card(card_id, data, print_labels, print_card_links): attachments_string = '\n\n'.join(attachments) + '\n' # put it together - return '## {name} {lbls} ##\n{cntnt}\n{attms}\n'.format( \ + return '## {name} {lbls} ##\n{cntnt}\n{attms}\n{comments}\n'.format( \ name=unlines(card['name']), \ cntnt=content, \ attms=attachments_string, \ + comments=comment_output, \ lbls=labels_string) ################################################################################ @@ -97,6 +126,7 @@ def main(): parser = argparse.ArgumentParser(description='Convert a JSON export from Trello to Markdown.') parser.add_argument('inputfile', help='Path to the input JSON file') parser.add_argument('-i', '--header', help='Include header page', action='store_true') + parser.add_argument('-m', '--comments', help='Include card comments', action='store_true') parser.add_argument('-l', '--labels', help='Print card labels', action='store_true') parser.add_argument('-a', '--archived', help='Don\'t ignore archived lists', action='store_true') parser.add_argument('-c', '--card-links', help='(Currently not implemented)', action='store_true') @@ -120,7 +150,9 @@ def main(): markdown.append("Number of lists: {0} \n".format(len(data['lists']))) markdown.append("Number of cards in lists: {0} \n".format(len(data['cards']))) markdown.append("Last change: {0}\n\n\n".format(data['dateLastActivity'])) - + comments = {} + if args.comments: + comments = prepare_all_comments(data) # process all lists in 'data', respecting closedness for lst in data['lists']: if not lst['closed'] or args.archived: @@ -132,8 +164,8 @@ def main(): if (not card['closed'] or args.archived) and (card['idList'] == lst['id']): markdown.append(print_card(card['id'], \ data, \ - args.labels, \ - args.card_links)) + comments, \ + args.labels)) markdown.append(print_checklists(card['id'], data)) # save result to file