Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.template_html = json.dumps({
'title': '',
'toc': '',
'main_content': '',
})
self.stdin = StringIO()
self.stdin.read = self.stdin.getvalue
self.stdout = StringIO()
self.backdoc = BackDoc(
markdown_converter=Markdown(extras=['toc']),
template_html=self.template_html,
stdin=self.stdin,
stdout=self.stdout
)
def test_toc_with_persistent_object(self):
"""
Tests that the toc is the same every time it's run on HTML, even if the Markdown object isn't disposed of.
"""
md = markdown2.Markdown(extras=["toc"])
html = """
# Header 1
## Header 1.1
## Header 1.2
### Header 1.3
# Header 2
## Header 2.1
"""
expected_toc_html = """<ul>
<li><a href="#header-1">Header 1</a>
<ul>
<li><a href="#header-11">Header 1.1</a></li>
<li><a href="#header-12">Header 1.2</a>
<ul>
<li><a href="#header-13">Header 1.3</a></li>
</ul></li></ul></li></ul>
def _convert_default (self, content):
import markdown2
tabsize = config.options['tabsize']
content = self._fenced_code_block(content, tabsize)
extras = [ n for n in MD_EXTRAS ]
if config.options['extras']:
for n in config.options['extras'].split(','):
extras.append(n.strip())
md = markdown2.Markdown(extras = extras, tab_width = tabsize)
html = md.convert(content)
if sys.version_info[0] >= 3:
unicode = str
text = unicode(html)
return text
def time_markdown2_py(cases_dir, repeat):
sys.path.insert(0, "../lib")
import markdown2
del sys.path[0]
markdowner = markdown2.Markdown()
times = []
for i in range(repeat):
start = clock()
for path in glob(join(cases_dir, "*.text")):
f = open(path, 'r')
content = f.read()
f.close()
markdowner.convert(content)
end = clock()
times.append(end - start)
print " markdown2.py: best of %d: %.3fs" % (repeat, min(times))
def __init__(self, environment):
super(Markdown2Extension, self).__init__(environment)
environment.extend(
markdowner=markdown2.Markdown()
)
from forum.user import *
from utils.html import sanitize_html
# used in index page
INDEX_PAGE_SIZE = 20
INDEX_AWARD_SIZE = 15
INDEX_TAGS_SIZE = 100
# used in tags list
DEFAULT_PAGE_SIZE = 60
# used in questions
QUESTIONS_PAGE_SIZE = 10
# used in users
USERS_PAGE_SIZE = 35
# used in answers
ANSWERS_PAGE_SIZE = 10
markdowner = Markdown(html4tags=True)
question_type = ContentType.objects.get_for_model(Question)
answer_type = ContentType.objects.get_for_model(Answer)
comment_type = ContentType.objects.get_for_model(Comment)
question_revision_type = ContentType.objects.get_for_model(QuestionRevision)
answer_revision_type = ContentType.objects.get_for_model(AnswerRevision)
repute_type = ContentType.objects.get_for_model(Repute)
question_type_id = question_type.id
answer_type_id = answer_type.id
comment_type_id = comment_type.id
question_revision_type_id = question_revision_type.id
answer_revision_type_id = answer_revision_type.id
repute_type_id = repute_type.id
def _get_tags_cache_json():
tags = Tag.objects.filter(deleted=False).all()
tags_list = []
for tag in tags:
for hash, link in link_from_hash.items():
text = text.replace(hash, link)
return text
def _unescape_special_chars(self, text):
# Swap back in all the special characters we've hidden.
for ch, hash in self._escape_table.items():
text = text.replace(hash, ch)
return text
def _outdent(self, text):
# Remove one level of line-leading tabs or spaces
return self._outdent_re.sub('', text)
class MarkdownWithExtras(Markdown):
"""A markdowner class that enables most extras:
- footnotes
- code-color (only has effect if 'pygments' Python module on path)
These are not included:
- pyshell (specific to Python-related documenting)
- code-friendly (because it *disables* part of the syntax)
- link-patterns (because you need to specify some actual
link-patterns anyway)
"""
extras = ["footnotes", "code-color"]
#---- internal support functions
def time_markdown2_py(cases_dir, repeat):
sys.path.insert(0, "../lib")
import markdown2
del sys.path[0]
markdowner = markdown2.Markdown()
times = []
for i in range(repeat):
start = clock()
for path in glob(join(cases_dir, "*.text")):
f = open(path, 'r')
content = f.read()
f.close()
markdowner.convert(content)
end = clock()
times.append(end - start)
print " markdown2.py: best of %d: %.3fs" % (repeat, min(times))
def _convert_default (self, content):
import markdown2
content = self._fenced_code_block(content)
tabsize = config.options['tabsize']
md = markdown2.Markdown(extras = MD_EXTRAS, tab_width = tabsize)
html = md.convert(content)
if sys.version_info[0] >= 3:
unicode = str
text = unicode(html)
return text