def run(self, params={}): markdown_bytes = params.get(Input.MARKDOWN) markdown_string = params.get(Input.MARKDOWN_STRING) if not (((markdown_string is None) ^ (markdown_bytes is None)) or ((markdown_string == "") ^ (markdown_bytes == ""))): raise Exception( "You must define one of Markdown or Markdown String") if markdown_bytes is not None: try: markdown = utils.from_bytes(markdown_bytes) except binascii.Error as _: bytes_len = len(markdown_bytes) markdown = utils.from_bytes(markdown_bytes[:bytes_len - (bytes_len % 4)]) else: markdown = markdown_string soup = BeautifulSoup(utils.convert(markdown, 'md', 'html'), features='html.parser') for script in soup(["script", "style"]): script.extract() txt_string = soup.get_text() return { Output.TXT_STRING: txt_string, Output.TXT: utils.to_bytes(txt_string) }
def run(self, params={}): inbytes = params.get('html') instr = params.get('html_string') if not (((instr == None) ^ (inbytes == None)) or ((instr == "") ^ (inbytes == ""))): raise Exception("Only one of HTML or HTML String can be defined" if instr != inbytes else "You must define one of HTML or HTML String.") if instr: markdown_string = utils.convert(instr,'html', 'md') markdown_b64 = utils.to_bytes(markdown_string) else: markdown_string = utils.convert(utils.from_bytes(inbytes),'html', 'md') markdown_b64 = utils.to_bytes(markdown_string) return {'markdown_string': markdown_string, 'markdown': markdown_b64}
def run(self, params={}): inbytes = params.get("markdown") instr = params.get("markdown_string") if not (((instr == None) ^ (inbytes == None)) or ((instr == "") ^ (inbytes == ""))): raise Exception( "Only one of Markdown or Markdown String can be defined" if instr != inbytes else "You must define one of Markdown or Markdown String.") if instr: html_string = utils.convert(instr, "md", "html") html_b64 = utils.to_bytes(html_string) else: html_string = utils.convert(utils.from_bytes(inbytes), "md", "html") html_b64 = utils.to_bytes(html_string) return {"html_string": html_string, "html": html_b64}
def run(self, params={}): inbytes = params.get('markdown') instr = params.get('markdown_string') if not (((instr == None) ^ (inbytes == None)) or ((instr == "") ^ (inbytes == ""))): raise Exception( "Only one of Markdown or Markdown String can be defined" if instr != inbytes else "You must define one of Markdown or Markdown String.") path = tempfile.mkdtemp() + "/" if instr: html_string = utils.convert(instr, 'md', 'html') pdf_string = makePDF(html_string, path) pdf_b64 = utils.to_bytes(pdf_string) else: html_string = utils.convert(utils.from_bytes(inbytes), 'md', 'html') pdf_string = makePDF(html_string, path) pdf_b64 = utils.to_bytes(pdf_string) shutil.rmtree(path) return {'pdf_string': pdf_string, 'pdf': pdf_b64}
def run(self, params={}): inbytes = params.get(Input.MARKDOWN) instr = params.get(Input.MARKDOWN_STRING) if not (((instr is None) ^ (inbytes is None)) or ((instr == "") ^ (inbytes == ""))): raise PluginException( cause="Input error", assistance= "Only one of Markdown or Markdown String can be defined" if instr != inbytes else "You must define one of Markdown or Markdown String.", ) path = tempfile.mkdtemp() + "/" if instr: html_string = utils.convert(instr, "md", "html") else: html_string = utils.convert(utils.from_bytes(inbytes), "md", "html") pdf_string = makePDF(html_string, path) pdf_b64 = utils.to_bytes(pdf_string) shutil.rmtree(path) return {Output.PDF_STRING: pdf_string, Output.PDF: pdf_b64}