def lang_for_block(source,lang):
if lang in ('py', 'python'):
if source.startswith('>>>'):
# interactive session
return 'pycon'
else:
# maybe Python -- try parsing it
if try_parse(source):
return 'python'
else: # Guess
return lang_for_block(source,'guess')
elif lang in ('python3', 'py3') and source.startswith('>>>'):
# for py3, recognize interactive sessions, but do not try parsing...
return 'pycon3'
elif lang == 'guess':
try:
#return 'python'
lexer=guess_lexer(source)
return lexer.aliases[0]
except Exception:
return None
else:
return lang
评论列表
文章目录