How to use the markdown2.MarkdownError function in markdown2

To help you get started, we’ve selected a few markdown2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github haldean / docstore / markdown2.py View on Github external
ename, earg = e, None
                extras[ename] = earg
    else:
        extras = None

    if opts.link_patterns_file:
        link_patterns = []
        f = open(opts.link_patterns_file)
        try:
            for i, line in enumerate(f.readlines()):
                if not line.strip(): continue
                if line.lstrip().startswith("#"): continue
                try:
                    pat, href = line.rstrip().rsplit(None, 1)
                except ValueError:
                    raise MarkdownError("%s:%d: invalid link pattern line: %r"
                                        % (opts.link_patterns_file, i+1, line))
                link_patterns.append(
                    (_regex_from_encoded_pattern(pat), href))
        finally:
            f.close()
    else:
        link_patterns = None

    from os.path import join, dirname, abspath, exists
    markdown_pl = join(dirname(dirname(abspath(__file__))), "test",
                       "Markdown.pl")
    for path in paths:
        if opts.compare:
            print "==== Markdown.pl ===="
            perl_cmd = 'perl %s "%s"' % (markdown_pl, path)
            o = os.popen(perl_cmd)
github b1ueb1ues / dl / markdown2.py View on Github external
ename, earg = e, None
                extras[ename] = earg
    else:
        extras = None

    if opts.link_patterns_file:
        link_patterns = []
        f = open(opts.link_patterns_file)
        try:
            for i, line in enumerate(f.readlines()):
                if not line.strip(): continue
                if line.lstrip().startswith("#"): continue
                try:
                    pat, href = line.rstrip().rsplit(None, 1)
                except ValueError:
                    raise MarkdownError("%s:%d: invalid link pattern line: %r"
                                        % (opts.link_patterns_file, i+1, line))
                link_patterns.append(
                    (_regex_from_encoded_pattern(pat), href))
        finally:
            f.close()
    else:
        link_patterns = None

    from os.path import join, dirname, abspath, exists
    markdown_pl = join(dirname(dirname(abspath(__file__))), "test",
                       "Markdown.pl")
    if path:
        paths = [path]

    if not paths:
        paths = ['-']
github b1ueb1ues / dl / markdown2.py View on Github external
def _sanitize_html(self, s):
        if self.safe_mode == "replace":
            return self.html_removed_text
        elif self.safe_mode == "escape":
            replacements = [
                ('&', '&'),
                ('<', '<'),
                ('>', '>'),
            ]
            for before, after in replacements:
                s = s.replace(before, after)
            return s
        else:
            raise MarkdownError("invalid value for 'safe_mode': %r (must be "
                                "'escape' or 'replace')" % self.safe_mode)
github haldean / docstore / markdown2.py View on Github external
def _sanitize_html(self, s):
        if self.safe_mode == "replace":
            return self.html_removed_text
        elif self.safe_mode == "escape":
            replacements = [
                ('&', '&'),
                ('<', '<'),
                ('>', '>'),
            ]
            for before, after in replacements:
                s = s.replace(before, after)
            return s
        else:
            raise MarkdownError("invalid value for 'safe_mode': %r (must be "
                                "'escape' or 'replace')" % self.safe_mode)
github frappe / frappe / frappe / utils / data.py View on Github external
def md_to_html(markdown_text):
	extras = {
		'fenced-code-blocks': None,
		'tables': None,
		'header-ids': None,
		'highlightjs-lang': None,
		'html-classes': {
			'table': 'table table-bordered',
			'img': 'screenshot'
		}
	}

	html = None
	try:
		html = markdown(markdown_text or '', extras=extras)
	except MarkdownError:
		pass

	return html