Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_language_metadata_no_space(text='python{"a":1}', value=('python', {'a': 1})):
compare(text_to_metadata(text), value)
assert metadata_to_text(*value) == 'python a=1'
def test_language_and_attribute(text="python .class", value=('python', {'.class': None})):
compare(text_to_metadata(text), value)
assert metadata_to_text(*value) == text
def test_attribute(allow_title):
text = ".class"
value = ('', {'.class': None})
compare(text_to_metadata(text, allow_title), value)
assert metadata_to_text(*value) == text
def test_simple_metadata_with_spaces(text='python string = "value" number = 1.0 array = ["a", "b"]',
value=('python', {'string': 'value', 'number': 1.0, 'array': ['a', 'b']})):
compare(text_to_metadata(text), value)
assert metadata_to_text(*value) == 'python string="value" number=1.0 array=["a", "b"]'
def test_no_language(text='.class', value=('', {'.class': None})):
compare(text_to_metadata(text), value)
assert metadata_to_text(*value) == text
def test_only_metadata(text='key="value"', value=('', {'key': 'value'})):
compare(text_to_metadata(text), value)
assert metadata_to_text(*value) == text
def html_comment(self, metadata, code='region'):
"""Protect a Markdown or Raw cell with HTML comments"""
if metadata:
region_start = ['']
region_start = ' '.join(region_start)
else:
region_start = ''.format(code)
return [region_start] + self.source + [''.format(code)]
def code_to_text(self):
"""Return the text representation of a code cell"""
source = copy(self.source)
comment_magic(source, self.language, self.comment_magics)
if self.metadata.get('active') == '':
self.metadata.pop('active')
self.language = self.metadata.pop('language', self.language)
if self.cell_type == 'raw' and not is_active(self.ext, self.metadata, False):
return self.html_comment(self.metadata, 'raw')
options = metadata_to_text(self.language, self.metadata)
return ['```' + options] + source + ['```']