def test_renderer_header_lower_level_does_not_set_title(): test_header = "this is a header" renderer = ConfluenceRenderer() renderer.header(test_header, 2) assert renderer.title is None
def test_renderer_header_sets_title(): test_header = "this is a header" renderer = ConfluenceRenderer() renderer.header(test_header, 1) assert renderer.title == test_header
def test_renderer_block_code(): test_code = 'this is a piece of code' test_markup = '<ac:structured-macro ac:name="code"><ac:parameter ac:name="linenumbers">true</ac:parameter>\n' \ '<ac:plain-text-body><![CDATA[this is a piece of code]]></ac:plain-text-body>\n' \ '</ac:structured-macro>\n' renderer = ConfluenceRenderer() assert renderer.block_code(test_code) == test_markup
def test_renderer_image_external(): test_image_src = "http://example.com/image.jpg" test_image_markup = ( '<ac:image ac:alt=""><ri:url ri:value="{}"></ri:url>\n' "</ac:image>\n".format(test_image_src)) renderer = ConfluenceRenderer() assert renderer.image(test_image_src, "", "") == test_image_markup assert not renderer.attachments
def test_renderer_image_internal_relative(): test_image_file = "image.jpg" test_image_src = "test/images/" + test_image_file test_image_markup = ( '<ac:image ac:alt=""><ri:attachment ri:filename="{}"></ri:attachment>\n' "</ac:image>\n".format(test_image_file)) renderer = ConfluenceRenderer() assert renderer.image(test_image_src, "", "") == test_image_markup assert renderer.attachments == [test_image_src]
def test_renderer_block_code_with_language(): test_code = "this is a piece of code" test_language = "whitespace" test_markup = ( '<ac:structured-macro ac:name="code"><ac:parameter ac:name="language">whitespace</ac:parameter>\n' '<ac:parameter ac:name="linenumbers">true</ac:parameter>\n' "<ac:plain-text-body><![CDATA[this is a piece of code]]></ac:plain-text-body>\n" "</ac:structured-macro>\n") renderer = ConfluenceRenderer() assert renderer.block_code(test_code, lang=test_language) == test_markup
def test_renderer_image_external_alt_and_title(): test_image_src = "http://example.com/image.jpg" test_image_alt = "alt text" test_image_title = "title" test_image_markup = ( '<ac:image ac:alt="{}" ac:title="{}"><ri:url ri:value="{}"></ri:url>\n' "</ac:image>\n".format(test_image_alt, test_image_title, test_image_src)) renderer = ConfluenceRenderer() assert (renderer.image(test_image_src, test_image_title, test_image_alt) == test_image_markup)
def __init__(self): self.enabled = True self.confluence_renderer = ConfluenceRenderer(use_xhtml=True) self.confluence_mistune = mistune.Markdown( renderer=self.confluence_renderer) self.simple_log = False self.flen = 1
def parse_page(markdown_lines: List[str]) -> Page: renderer = ConfluenceRenderer(use_xhtml=True) confluence_mistune = mistune.Markdown(renderer=renderer) confluence_content = confluence_mistune("".join(markdown_lines)) page = Page(title=renderer.title, body=confluence_content, attachments=renderer.attachments) return page
def test_full_document(script_loc): with open(str(script_loc.join('test.md'))) as test_file: markdown_data = test_file.read() with open(str(script_loc.join('result.xml'))) as result_file: result_data = result_file.read() renderer = ConfluenceRenderer(use_xhtml=True) confluence_mistune = mistune.Markdown(renderer=renderer) confluence_content = confluence_mistune(markdown_data) assert confluence_content == result_data
def test_renderer_header_only_sets_first_title(): test_header = "this is a header" test_second_header = "this is another header" renderer = ConfluenceRenderer() renderer.header(test_header, 1) renderer.header(test_second_header, 1) assert renderer.title is test_header
def test_renderer_header_later_level_sets_title(): test_lower_header = "this is a lower header" test_header = "this is a header" renderer = ConfluenceRenderer() renderer.header(test_lower_header, 2) renderer.header(test_header, 1) assert renderer.title is test_header
def page_data_from_file_name(file_name): with open(file_name) as file_handle: markdown_data = file_handle.read() renderer = ConfluenceRenderer(use_xhtml=True) html_mistune = mistune.Markdown() html_content = html_mistune(markdown_data) confluence_mistune = mistune.Markdown(renderer=renderer) confluence_content = confluence_mistune(markdown_data) soup = bs4.BeautifulSoup(html_content, features='lxml') page_title = soup.h1.text or file_name page_data = {'title': page_title, 'body': confluence_content} return page_data
def page_data_from_file_name(file_name): with open(file_name) as file_handle: markdown_data = file_handle.read() renderer = ConfluenceRenderer(use_xhtml=True) html_mistune = mistune.Markdown() html_content = html_mistune(markdown_data) confluence_mistune = mistune.Markdown(renderer=renderer) confluence_content = confluence_mistune(markdown_data) soup = bs4.BeautifulSoup(html_content, features='lxml') try: page_title = soup.h1.text except AttributeError: page_title = os.path.splitext(os.path.basename(file_name))[0] page_data = {'title': page_title, 'body': confluence_content} return page_data
import os import sys import ntpath import mistune from md2cf.confluence_renderer import ConfluenceRenderer import re import time dir = sys.argv[1] #confluence = MinimalConfluence(host='https://somewiki.com/rest/api', username='', password='') confluence = MinimalConfluence(host=os.environ['CFHOST'], username=os.environ['CFUSER'], password=os.environ['CFPASS']) renderer = ConfluenceRenderer(use_xhtml=True) confluence_mistune = mistune.Markdown(renderer=renderer) parentPage = confluence.get_page(title=os.environ['CFPARENT'], space_key=os.environ['CFSPACE']) regex = re.compile(r"(<ri:url ri:value=\"data:image/png;base64.*)</ri:url>", re.IGNORECASE) for root, subdirs, files in os.walk(dir): for filename in files: try: basename = ntpath.basename(filename) file_path = os.path.join(root, filename) if (basename == "home.md"): basename = os.environ['CFPARENT'] + ".md" if (basename.endswith(".md")):