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 generate_singular_templates(bib_data): """ Parses a .bibtex file and creates a singular markdown write-up template for each entry. Args: bib_data: A pybtex parsed file Returns: Outputs singular markdown write-up templates """ for entry in tqdm(bib_data.entries.values()): title = entry.fields['title'] year = entry.fields['year'] url = entry.fields['url'] authors = str(entry.persons['author'][0]) if 'journal' in entry.fields: journal = entry.fields['journal'] file_name = authors.lower() + '-' + str(year) if 'journal' in locals(): title = authors + ', ' + title + ', ' + year + ', ' + journal else: title = authors + ', ' + title + ', ' + year mdfile = MdUtils(file_name=file_name, title=title) # Add the correct header information mdfile.new_header(level=1, title='TLDR') mdfile.new_header(level=1, title='Links') mdfile.new_line('Paper - ' + mdfile.new_inline_link(text='Link to Paper', link=url)) mdfile.new_header(level=1, title='Summary') mdfile.new_header(level=1, title='Comments') mdfile.new_header(level=1, title='Reference') mdfile.insert_code(entry.to_string(bib_format='bibtex')) mdfile.create_md_file()
mdFile.new_paragraph( "**IMPORTANT:** This game will not teach you <ins>strategery</ins> or make you a pro. All bets are off..... (I'm not liable for any real $$ lost at the table)", bold_italics_code='bi', color='purple') # How to play mdFile.new_header(level=1, title="Rules of the Game") mdFile.new_header(level=2, title="Come Out Roll") mdFile.new_paragraph( "This is where the `point` is established. The dice you're about to roll will either make you a hero or zero real quick. Good Luck!" ) mdFile.insert_code( "First Roll: \n" "\n" "7, 11 = Immediate winner! If you bet on the ``Pass Line``, you win and get to roll again!.\n" "2, 3, 12 = Craps. If you roll any of these numbers on the first roll, you lose your $$. The funny thing is that you also get to roll again if you choose to do so. \n" "Note: On a craps roll, you would have won if you bet on the ``Don\'t Pass`` line, but that's risky. \n" "4, 5, 6, 8, 9, 10 = Establish the point on the first roll and the game continues. \n" "\n" "Note... note...: Some people are very superstitious when it comes to Craps so beware if you start to bet `against` the table, although I've seen some rollers do very well. \n" "At the end of the day, it's your $$, so you choose your own destiny. \n" "Note... note... note...: Always Tip your dealers. They help you understand the game better and are extremely patient as you learn the game!", language='php') imagelink = "https://media.tenor.com/images/9081df2ca9610e3fdb4e0dfca1b27df1/tenor.gif" imagetext = "Rick Roll Eyes" mdFile.new_header(level=2, title="Second Roll and Forward") mdFile.new_paragraph( "If you didn't win on your first roll and you've established the point, the goal is to roll the number again. \n" ) mdFile.new_paragraph(Html.image(path=imagelink, size='300x200', align='left'))
def createMarkDownFile(file_array): mdFile = MdUtils(file_name='_genBuiltinDocs_Out', title='Markdown Files for scripts') mdFile.new_header( level=1, title='Overview') # style is set 'atx' format by default. for entry in file_array: inputParameters = entry.param outputParameters = entry.output inputParameterCount = entry.param_count outputParameterCount = entry.output_param_count description = entry.description additionalInfos = entry.additional fileName = entry.fileName #First I strip all the newline characters from the end of each string and replace the newlines within strings wit spaces inputParameters = replaceNewlineCharacter(inputParameters) outputParameters = replaceNewlineCharacter(outputParameters) description = replaceNewlineCharacter(description) titleString = fileName + "-Function" mdFile.new_header( level=2, title=titleString) # style is set 'atx' format by default. for line in description: mdFile.new_paragraph(line) mdFile.new_header(level=3, title="Usage") usage = fileName + "(" for argument in inputParameters[4::4]: usage += (argument + ", ") if len(inputParameters) > 0: usage = usage[:-2] + ')' else: usage = usage + ')' mdFile.insert_code(usage, language='python') mdFile.new_header(level=3, title="Arguments") if inputParameterCount > 0: rows = int(len(inputParameters) / inputParameterCount) mdFile.new_table(columns=inputParameterCount, rows=rows, text=inputParameters, text_align='center') mdFile.new_header(level=3, title="Returns") if outputParameterCount > 0: rows = int(len(outputParameters) / outputParameterCount) mdFile.new_table(columns=outputParameterCount, rows=rows, text=outputParameters, text_align='center') else: for line in additionalInfos: mdFile.new_paragraph(line) mdFile.create_md_file()
def dumpMarkdown(report, output_dir): def trim(s, n): if not s: return s ret = s if len(ret) > n: ret = ret[0:800] + '\n...' return ret if exists(output_dir): remove(output_dir) mdFile = MdUtils(file_name=output_dir) mdFile.new_header(1, 'CS577 Report for Type II Binaries') mdFile.new_paragraph( "This is a sanbox analysis report auto generated by Layrex") mdFile.new_header(2, 'Overview') overviewTable = [ 'binary', 'cracked', 'filesystem activity', 'network activity', 'process forks'] rowCounter = 1 for name, metrics in report.items(): cracked = '' fsActivity = 'Yes' if metrics['filesystem'] else 'No' netActivity = 'Yes' if 'sock' in metrics['strace']['summary'] else 'No' procForks = '' overviewTable.extend( [name, cracked, fsActivity, netActivity, procForks]) rowCounter = rowCounter + 1 mdFile.new_table(5, rowCounter, text=overviewTable) for name, metrics in report.items(): mdFile.new_header(2, f'Analysis of {name}') mdFile.new_header(3, 'Process:') processInfo = metrics['process'] normal = True if processInfo['exit'] != 0: mdFile.new_header(4, 'exit code: ' + str(processInfo['exit'])) normal = False if processInfo['stdout']: mdFile.new_header(4, 'stdout:') mdFile.insert_code(trim(processInfo['stdout'], 300)) normal = False if processInfo['stderr']: mdFile.new_header(4, 'stderr:') mdFile.insert_code(trim(processInfo['stderr'], 300)) normal = False if normal: mdFile.new_paragraph( 'The process exited with code 0, ' 'and no `stdout` or `stderr` was produced') mdFile.new_header(3, 'Filesystem:') if metrics['filesystem']: mdFile.new_header(4, 'Changes Observed:') # for entry in metrics['filesystem']['docker-diff']: mdFile.new_list(metrics['filesystem']['docker-diff']) mdFile.new_header(4, 'Changes Detail:') for name, content in metrics['filesystem']['diff-content'].items(): text = [f'Added file `{name}` with the following content:'] body = content if len(body) > 800: body = body[0:800] + '\n...' mdFile.new_list(text) mdFile.insert_code(body, language='diff') else: mdFile.new_paragraph('No filesystem changes observed.') mdFile.new_header(3, 'Syscalls:') straceInfo = metrics['strace'] mdFile.new_header(4, 'Summary:') mdFile.insert_code(straceInfo['summary']) mdFile.new_header(4, 'Critical Calls:') mdFile.insert_code(straceInfo['critical']) mdFile.new_header(3, 'Network:') networkInfo = metrics['tcpdump'] if 'sock' in straceInfo['summary']: mdFile.insert_code(networkInfo['stdout']) else: mdFile.new_paragraph('No network traffic produced by the process.') # mdFile.insert_code(json.dumps(metrics)) mdFile.create_md_file()
"CSS. Some of them are: coloring text, centering text...") mdFile.new_paragraph() # Available Features mdFile.new_header(level=1, title="This is what you can do") # ******************************************************************************************************************** # ***************************************************** Markdown ***************************************************** # ******************************************************************************************************************** mdFile.new_header(level=2, title="Create Markdown files") mdFile.new_paragraph( "``create_md_file()`` is the last command that has to be called.") mdFile.insert_code( "import Mdutils\n" "\n" "\n" "mdFile = MdUtils(file_name=\'Example_Markdown\',title=\'Markdown File Example\')\n" "mdFile.create_md_file()", language='python') # ******************************************************************************************************************** # ***************************************************** Headers ****************************************************** # ******************************************************************************************************************** mdFile.new_header(level=2, title="Create Headers") mdFile.new_paragraph( "Using ``new_header`` method you can create headers of different levels depending on the style. " "There are two available styles: 'atx' and 'setext'. The first one has til 6 different header " "levels. Atx's levels 1 and 2 are automatically added to the table of contents unless the " "parameter ``add_table_of_contents`` is set to 'n'. The 'setext' style only has two levels" "of headers.")
getImage(op) else: j = 1 op = input("\nEnter output image path: ") while (j > 0): if os.path.isfile(op): j = -1 else: print("\nPlease enter correct path or filename.\n") op = input("\nEnter correct output image path: ") j += 1 mdFile.new_header(level=2, title="**{}. {}**".format(i + 1, ques), add_table_of_contents='n') mdFile.insert_code(code, lang) mdFile.new_line("<br>\n\n") mdFile.new_header(level=3, title="**Output:**\n<br>", add_table_of_contents='n') imgPath = r'{}'.format(op) im = Image.open(imgPath) w, h = im.size if w > 573: w = 573 im.close() mdFile.new_paragraph(Html.image(path=imgPath, size="{}".format(w))) mdFile.new_line("<div class=\"page\"/>\n\n") mdFile.create_md_file() print("\nCreated md file at {}\{}.md".format(pathlib.Path().absolute(), fn))
def md_help(parser: _argparse.ArgumentParser) -> None: """ Args: parser: parser object Returns: """ if parser.prog is None: logging.info("Saving as foo.md") mdFile = MdUtils(file_name="foo") else: mdFile = MdUtils(file_name=os.path.splitext(parser.prog)[0], title=parser.prog) if parser.description: mdFile.new_header(level=1, title="Description") mdFile.new_paragraph(parser.description) if parser.epilog: mdFile.new_header(level=1, title="Epilog") mdFile.new_paragraph(parser.epilog) mdFile.new_header(level=1, title="Usage:") mdFile.insert_code(parser.format_usage(), language="bash") used_actions = {} options = ["short", "long", "default", "help"] i = 0 for k in parser._option_string_actions: action = parser._option_string_actions[k] list_of_str = ["", "", "", action.help] this_id = id(action) if this_id in used_actions: continue used_actions[this_id] = True for opt in action.option_strings: # --, long option if len(opt) > 1 and opt[1] in parser.prefix_chars: list_of_str[1] = inline_code(opt) # short opt elif len(opt) > 0 and opt[0] in parser.prefix_chars: list_of_str[0] = inline_code(opt) if not (isinstance(action.default, bool) or isinstance(action, _argparse._VersionAction) or isinstance(action, _argparse._HelpAction)): default = (action.default if isinstance(action.default, str) else repr(action.default)) list_of_str[2] = inline_code(default) options.extend(list_of_str) i += 1 mdFile.new_header(level=1, title="Arguments") mdFile.new_table( columns=4, rows=len(options) // 4, text=options, text_align="center", ) mdFile.create_md_file()