def render_markdown(changelog_txt, version, logging): """ Create an AST from the changelog document (which is in Markdown). Search the AST for the version we're interested in, generate and return markdown as a string for just that version. """ d = Document(changelog_txt) output = ast_renderer.get_ast(d) s = str() logging.debug("Locating the changelog AST for version: \'{}\'".format(version)) version_heading = '' version_changes = '' pos = 0 for item in output['children']: if item['type'] == 'Heading' and item['level'] == 2: if item['children'][0]['children'][0]['content'] == version: version_heading = output['children'][pos] version_changes = output['children'][pos+1] pos = pos + 1 if version_heading and version_changes: heading = '# Release Notes' s = heading + '\n' s = s + '\n' changes = reconstruct_brave_changelog_list(version_changes) for i in changes: s = s + i + '\n' else: logging.error("Cannot Locate the changelog AST for version: \'{}\'".format(version)) exit(1) return s
def test_footnotes(self): self.maxDiff = None d = Document(['[bar][baz]\n', '\n', '[baz]: spam\n']) target = { 'type': 'Document', 'footnotes': { 'baz': 'spam' }, 'children': [{ 'type': 'Paragraph', 'children': [{ 'type': 'FootnoteLink', 'target': { 'type': 'FootnoteAnchor', 'key': 'baz' }, 'children': [{ 'type': 'RawText', 'content': 'bar' }] }] }] } output = ast_renderer.get_ast(d) self.assertEqual(output, target)
def test(self): self.maxDiff = None d = Document(['# heading 1', '\n', 'hello\n', 'world\n']) output = ast_renderer.get_ast(d) target = { 'type': 'Document', 'footnotes': {}, 'children': [{ 'type': 'Heading', 'level': 1, 'children': [{ 'type': 'RawText', 'content': 'heading 1' }] }, { 'type': 'Paragraph', 'children': [{ 'type': 'RawText', 'content': 'hello\nworld' }] }] } self.assertEqual(output, target)
def render_markdown(changelog_txt, version, logging): """ Create an AST from the changelog document (which is in Markdown). Search the AST for the version we're interested in, generate and return markdown as a string for just that version. """ d = Document(changelog_txt) output = ast_renderer.get_ast(d) s = str() logging.debug("Locating the changelog AST for version: \'{}\'".format(version)) version_heading = '' version_changes = '' pos = 0 for item in output['children']: if item['type'] == 'Heading' and item['level'] == 2: if item['children'][0]['children'][0]['content'] == version: version_heading = output['children'][pos] version_changes = output['children'][pos+1] pos = pos + 1 if version_heading and version_changes: heading = reconstruct_heading(version_heading) s = heading + '\n' s = s + '\n' changes = reconstruct_brave_changelog_list(version_changes) for i in changes: s = s + i + '\n' else: logging.error("Cannot Locate the changelog AST for version: \'{}\'".format(version)) exit(1) return s