def test_wrap_text(self): md_file = MdUtils(file_name="Test_file", title="") created_value = md_file.new_line( "This is a new line created using new_line method with wrapping.", wrap_width=25) expected_value = ' \nThis is a new line \ncreated using new_line \nmethod with wrapping.' self.assertEqual(created_value, expected_value)
def main(): md_file = MdUtils(file_name='hacker_news', title='temp') md_file.new_header(level=1, title='Daily Hacker News') stories = get_top_stories() for i, v in enumerate(stories): item = get_topic_item(v) id = item['id'] title = item['title'] url = item.get('url', None) if url: domain = url_parser(url) md_file.new_line( '{}. {} `{}` [`comments`](https://news.ycombinator.com/item?id={})' .format( str(i + 1), md_file.new_inline_link(link=url, text=title, bold_italics_code='b'), domain, str(id))) else: link = 'https://news.ycombinator.com/item?id={}'.format(str(id)) md_file.new_line('{}. {} [`comments`]({})'.format( str(i + 1), md_file.new_inline_link(link=link, text=title, bold_italics_code='b'), link)) issue_body = md_file.file_data_text date = get_date() issue_url = create_issue('Daily Hacker News {}'.format(date), issue_body)
def report(self, reports): xml_dict = parsexmlfile(self.files[0]) result = json.dumps(xml_dict) nmap_results = json.loads(result) ports = nmap_results["nmaprun"]["host"]["ports"] #cpe, portid, product, name, version, hosts/up if 'port' in ports: open_ports = ports["port"] else: open_ports = [] # temp self.logger.info("Creating report for " + self.name) outfile = f"{self.reportdir}/{self.name}.md" title = f"PENSEC - {self.name.capitalize()} Report" reportfile = MdUtils(file_name=outfile, title=title) reportfile.new_header(level=1, title="Common Statistics") reportfile.new_paragraph(f"{len(open_ports)} open ports\n") if len(open_ports) > 0: reportfile.new_header(level=2, title="Open Ports") # list with open ports, cpe, etc reportfile.create_md_file() self.logger.info("Report saved in " + outfile) return {"open_ports": open_ports}
def test_new_inline_link_text_empty(self): link = "https://github.com/didix21/mdutils" md_file = MdUtils(file_name="Test_file", title="") created_value = md_file.new_inline_link(link=link, text=link) expected_value = '[https://github.com/didix21/mdutils](https://github.com/didix21/mdutils)' self.assertEqual(expected_value, created_value)
def test_new_inline_image(self): md_file = MdUtils(file_name="Test_file", title="") expected_image = '![image](../image.png)' created_image = md_file.new_inline_image(text='image', path='../image.png') self.assertEqual(expected_image, created_image)
def test_new_reference_image(self): md_file = MdUtils(file_name="Test_file", title="") expected_image = '![image][reference]' created_image = md_file.new_reference_image(text='image', path='../image.png', reference_tag="reference") self.assertEqual(expected_image, created_image)
def test_new_inline_link_empty(self): md_file = MdUtils(file_name="Test_file", title="") try: md_file.new_inline_link() except TypeError: return self.fail()
def test_new_inline_link_align_format(self): link = "https://github.com/didix21/mdutils" text = "mdutils" md_file = MdUtils(file_name="Test_file", title="") expected_value = '[<center>' + text + '</center>](' + link + ')' created_value = md_file.new_inline_link(link, text, align='center') self.assertEqual(expected_value, created_value)
def __init__(self, name, addrWidth, dataWidth): self.name = name self.addrWidth = addrWidth self.dataWidth = dataWidth self.registerList = [] self.suffix = ".md" self.mdFile = MdUtils(file_name="none", title="")
def test_new_inline_link_bold_italic_code_format(self): link = "https://github.com/didix21/mdutils" text = "mdutils" md_file = MdUtils(file_name="Test_file", title="") expected_value = '[***``' + text + '``***](' + link + ')' created_value = md_file.new_inline_link(link, text, bold_italics_code="bic") self.assertEqual(expected_value, created_value)
def __init__(self, data_path): self._images_path = os.path.join(data_path, 'images') self._parser = Parser(data_path) self._results = MdUtils(file_name='results', title='Overview') self._num_images = None self._counts = None self._image_shape = None self._image_shape_mean = None
def test_create_md_file(self): md_file = MdUtils("Test_file") md_file.create_md_file() md_file_expect = Path('Test_file.md') if md_file_expect.is_file(): os.remove('Test_file.md') pass else: self.fail()
def main(self): mdFile = MdUtils(file_name='sitelist', title='Scraper Site List') mdFile.new_header(level=1, title='Sites') data = self.loop_spiders() mdFile.new_line() mdFile.new_table(columns=4, rows=int(len(data) / 4), text=data, text_align='center') mdFile.create_md_file()
def test_references_placed_in_markdown_file(self): md_file = MdUtils(file_name="Test_file", title="") text = "mdutils library" reference_tag = "mdutils library" link = "https://github.com/didix21/mdutils" expected_value = "\n\n\n[mdutils library0][mdutils library0]\n" \ "[mdutils library1][mdutils library1]\n" \ "[mdutils library2][mdutils library2]\n" \ "[mdutils library3][mdutils library3]\n" \ "\n\n\n" \ "[mdutils library0]: https://github.com/didix21/mdutils0\n" \ "[mdutils library1]: https://github.com/didix21/mdutils1\n" \ "[mdutils library2]: https://github.com/didix21/mdutils2\n" \ "[mdutils library3]: https://github.com/didix21/mdutils3\n" for i in range(4): md_file.write(md_file.new_reference_link( link=link + str(i), text=text + str(i), reference_tag=reference_tag + str(i))) md_file.write('\n') md_file.create_md_file() created_data = MarkDownFile.read_file('Test_file.md') self.assertEqual(expected_value, created_data)
def _write_tool_page(self): os.makedirs(self.tool_prefix, exist_ok=True) md = MdUtils(file_name=f'{self.tool_prefix}/README', title=self.tool_command) writer = Writer(md) writer.write_description(self.tool.__doc__) writer.write_command_usage(self) self._write_tool_command_arguments_and_options(writer) writer.write_actions_table(self.tool_serialized_actions) writer.write_action_groups_table(self.tool_serialized_action_groups) md.create_md_file()
def test_new_code_reference_link(self): md_file = MdUtils(file_name="Test_file", title="") text = "mdutils library" reference_tag = "mdutils library" expected_value = '[``' + text + '``][' + reference_tag + ']' created_value = md_file.new_reference_link( link="https://github.com/didix21/mdutils", text=text, reference_tag=reference_tag, bold_italics_code='c') self.assertEqual(expected_value, created_value)
def test_new_reference_link_when_reference_tag_not_defined_and_align_is_defined(self): md_file = MdUtils(file_name="Test_file", title="") text = "mdutils library" try: md_file.new_reference_link( link="https://github.com/didix21/mdutils", text=text, align='center') except TypeError: return self.fail()
def create_md_issue_report(org, repos, issue_state='all', start_time=None, token=None): gh = GithubConnection.getConnection(token=token) _md_file = MdUtils(file_name='pdsen_issues', title='PDS EN Issues') for _repo in gh.repositories_by(org): if repos and _repo.name not in repos: continue issues_map = get_issues_groupby_type(_repo, state=issue_state, start_time=start_time) convert_issues_to_planning_report(_md_file, _repo.name, issues_map) _md_file.create_md_file()
def test_insert_code(self): md_file = MdUtils(file_name='Test_file') code = ("mdFile.new_header(level=1, title='Atx Header 1')\n" "mdFile.new_header(level=2, title='Atx Header 2')\n" "mdFile.new_header(level=3, title='Atx Header 3')\n" "mdFile.new_header(level=4, title='Atx Header 4')\n" "mdFile.new_header(level=5, title='Atx Header 5')\n" "mdFile.new_header(level=6, title='Atx Header 6')\n") expects = '\n\n```\n' + code + '\n```' self.assertEqual(md_file.insert_code(code), expects) language = 'python' expects = '\n\n```' + language + '\n' + code + '\n```' self.assertEqual(md_file.insert_code(code, language), expects)
def _write_action_group_page(self, action_group: ActionGroup): group_path = f'{self.tool_prefix}/{action_group.name}' md = MdUtils(file_name=group_path, title=action_group.name) writer = Writer(md) writer.write_description(action_group.description) writer.write_command_usage(self, action_group=action_group) self._write_tool_command_arguments_and_options(writer) writer.write_actions_table(action_group.actions, action_group=action_group) md.create_md_file() os.makedirs(group_path, exist_ok=True) for action in action_group.actions: self._write_action_page(action, action_group=action_group)
def generate(self): class_args_serializer = ArgumentsSerializer( self.tool.CLASS_ARGUMENTS).serialize() self.tool_optional_args = class_args_serializer.optional_args self.tool_serialized_actions = self._serialize_actions() self.tool_options = self._serialize_default_options() # docs/<tool-name>/README.md os.makedirs(self.tool_prefix, exist_ok=True) md = MdUtils(file_name=f'{self.tool_prefix}/README', title=self.tool_command) writer = Writer(md) writer.write_description(self.tool.__doc__) writer.write_tool_command_usage(self) writer.write_arguments(f'command `{self.tool_command}`', self.tool_optional_args, []) writer.write_options(self.tool_options) writer.write_actions_table(self.tool_serialized_actions) md.create_md_file() for action in self.tool_serialized_actions: # docs/<tool-name>/<action-name>.md md = MdUtils(file_name=f'{self.tool_prefix}/{action.action_name}', title=action.action_name) writer = Writer(md) writer.write_description(action.description) writer.write_action_command_usage(self, action) writer.write_arguments(f'action `{action.action_name}`', action.optional_args, action.required_args) writer.write_arguments(f'command `{self.tool_command}`', self.tool_optional_args, []) writer.write_options(self.tool_options) md.create_md_file()
def generate(self): def _write_tool_command_arguments_and_options(): writer.write_arguments(f'command `{self.tool_command}`', self.tool_optional_args, self.tool_required_args) writer.write_options(self.tool_options) # docs/<tool-name>/README.md os.makedirs(self.tool_prefix, exist_ok=True) md = MdUtils(file_name=f'{self.tool_prefix}/README', title=self.tool_command) writer = Writer(md) writer.write_description(self.tool.__doc__) writer.write_tool_command_usage(self) _write_tool_command_arguments_and_options() writer.write_actions_table(self.tool_serialized_actions) md.create_md_file() for action in self.tool_serialized_actions: # docs/<tool-name>/<action-name>.md md = MdUtils(file_name=f'{self.tool_prefix}/{action.action_name}', title=action.action_name) writer = Writer(md) writer.write_description(action.description) writer.write_action_command_usage(self, action) writer.write_arguments(f'action `{action.action_name}`', action.optional_args, action.required_args) _write_tool_command_arguments_and_options() md.create_md_file()
def create_file(files): data = get_data(files) md_file = MdUtils(file_name='repositories') md_file.new_header(level=1, title='Repositories') grouped_by_type = groupby(data, key=itemgetter('type')) for key, value in grouped_by_type: value_sorted = sorted(value, key=lambda x: x['name']) md_file.new_header(level=2, title=key) if key == 'Reading': write_reading_entries(value_sorted, md_file) else: for item in value_sorted: write_item(item, md_file) md_file.new_line() md_file.create_md_file()
def run(username, name, job, company, accounts): mdFile = MdUtils(file_name='README', title=title) add_introduction(mdFile, username, name, job, company) add_analytics(mdFile, username) if accounts is not None: add_accounts_url(mdFile, accounts) mdFile.create_md_file() print('✅ Github profile README.md file created successfully for {}'.format( username))
def _write_action_page(self, action: Action, action_group: Optional[ActionGroup] = None): group_str = f'{action_group.name}/' if action_group else '' md = MdUtils( file_name=f'{self.tool_prefix}/{group_str}{action.action_name}', title=action.action_name) writer = Writer(md) writer.write_description(action.description) writer.write_command_usage(self, action_group=action_group, action=action) writer.write_arguments(f'action `{action.action_name}`', action.optional_args, action.required_args) self._write_tool_command_arguments_and_options(writer) md.create_md_file()
def run(username, name, job, company, hardskills, accounts): mdFile = MdUtils(file_name='README', title=title) add_introduction(mdFile, username, name, job, company) if hardskills is not None: add_hardskills(mdFile, hardskills) add_analytics(mdFile, username) if accounts is not None: add_accounts_url(mdFile, accounts) mdFile.create_md_file() print('\nтЬЕ \033[1mGithub profile README.md file created successfully for {} user!\033[0m'.format(username))
def model_to_md(model, level=1): # ... if isinstance(model, Accreditation): title = '{name}. {title}'.format(name=model.name, title=model.title) elif isinstance(model, Syllabus): title = '{name}. {title}'.format(name=model.name, title=model.title) else: raise NotImplementedError('{} not available'.format(type(model))) # ... md = MdUtils(title=title) # ... if isinstance(model, Accreditation): _accreditation_to_md(model, md, level) elif isinstance(model, Syllabus): _syllabus_to_md(model, md, level) else: raise NotImplementedError('{} not available'.format(type(model))) # ... # TODO Create a table of contents # mdFile.new_table_of_contents(table_title='Contents', level=2) return {'data': md.data, 'toc': md.toc}
def test_create_table(self): md_file = MdUtils("file_name") table = Table() result_table = '\n|**Test**|**Descripción**|**Estado**|\n| :---: | :---: | :---: ' \ '|\n|Test 1|Carga de configuración correcta|<font color="green">OK</font>|\n' \ '|Test 2|Lectura de Configuración|<font color="red">NOK</font>|\n' \ '|Test 3|Lectura de Soporte|<font color="green">OK</font>|\n' \ '|Test 4|Modificación de entradas y lectura de salidas de cantón|<font color="green">' \ 'OK</font>|'\ '\n|Test 5|Lectura de estados de Pedal de Rearme y Aviso|<font color="green">OK</font>|\n' \ '|Test 6|Actualización de datos de unidades de vía|<font color="green">OK</font>|\n' \ '|Test 7|Fallos en carga de configuración - Campo IdApp Erróneo|<font color="green">' \ 'OK</font>|' \ '\n' \ '|Test 8|Fallos en carga de configuración - Campo VersTAbla Erróneo' \ '|<font color="red">NOK</font>|'\ '\n|Test 9|Fallos en carga de configuración - Campo IdUc Erróneo|<font color="red">' \ 'NOK</font>|' \ '\n|Test 10|Fallos en carga de configuración - Campo Addresses Erróneo' \ '|<font color="red">NOK</font>|\n' \ '|Test 11|Fallos en carga de configuración - Campo NumTc Erróneo' \ '|<font color="red">NOK</font>|\n' \ '|Test 12|Fallos en carga de configuración - Campo NumUv Erróneo' \ '|<font color="red">NOK</font>|\n' \ '|Test 13|Fallos en carga de configuración - Campo CRC Erróneo|<font color="red">NOK</font>|\n' text_array = [ '**Test**', '**Descripción**', '**Estado**', 'Test 1', 'Carga de configuración correcta', md_file.textUtils.text_color( "OK", 'green'), 'Test 2', 'Lectura de Configuración', md_file.textUtils.text_color( "NOK", 'red'), 'Test 3', 'Lectura de Soporte', md_file.textUtils.text_color("OK", 'green'), 'Test 4', 'Modificación de entradas y lectura de salidas de cantón', md_file.textUtils.text_color("OK", 'green'), 'Test 5', 'Lectura de estados de Pedal de Rearme y Aviso', md_file.textUtils.text_color("OK", 'green'), 'Test 6', 'Actualización de datos de unidades de vía', md_file.textUtils.text_color("OK", 'green'), 'Test 7', 'Fallos en carga de configuración - Campo IdApp Erróneo', md_file.textUtils.text_color("OK", 'green'), 'Test 8', 'Fallos en carga de configuración - Campo VersTAbla Erróneo', md_file.textUtils.text_color("NOK", 'red'), 'Test 9', 'Fallos en carga de configuración - Campo IdUc Erróneo', md_file.textUtils.text_color("NOK", 'red'), 'Test 10', 'Fallos en carga de configuración - Campo Addresses Erróneo', md_file.textUtils.text_color("NOK", 'red'), 'Test 11', 'Fallos en carga de configuración - Campo NumTc Erróneo', md_file.textUtils.text_color("NOK", 'red'), 'Test 12', 'Fallos en carga de configuración - Campo NumUv Erróneo', md_file.textUtils.text_color("NOK", 'red'), 'Test 13', 'Fallos en carga de configuración - Campo CRC Erróneo', md_file.textUtils.text_color("NOK", 'red') ] self.assertEqual( table.create_table(columns=3, rows=14, text=text_array), result_table)
def test_invalid_text_align(self): md_file = MdUtils("file_name") table = Table() text_array = ['**Test**', '**Descripción**', '**Estado**', 'Test 1', 'Carga de configuración correcta', md_file.textUtils.text_color("OK", 'green'), 'Test 2', 'Lectura de Configuración', md_file.textUtils.text_color("NOK", 'red'), 'Test 3', 'Lectura de Soporte', md_file.textUtils.text_color("OK", 'green')] self.assertRaises(ValueError, table.create_table, 3, 14, text_array, 'invalid_align')
def img_to_markdown(path: str) -> str: """ Creates a Markdown Image. Parameters ---------- path: str The image path. """ return MdUtils.new_inline_image(text=path, path=path)