How to use the jupytext.cell_metadata.text_to_metadata function in jupytext

To help you get started, we’ve selected a few jupytext 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 mwouts / jupytext / tests / test_cell_metadata.py View on Github external
def test_language_and_attribute(text="python .class", value=('python', {'.class': None})):
    compare(text_to_metadata(text), value)
    assert metadata_to_text(*value) == text
github mwouts / jupytext / tests / test_cell_metadata.py View on Github external
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"]'
github mwouts / jupytext / tests / test_cell_metadata.py View on Github external
def test_attribute(allow_title):
    text = ".class"
    value = ('', {'.class': None})
    compare(text_to_metadata(text, allow_title), value)
    assert metadata_to_text(*value) == text
github mwouts / jupytext / tests / test_cell_metadata.py View on Github external
def test_title_and_json_dict(text='cell title {"string": "value", "number": 1.0, "array": ["a", "b"]}',
                             value=('cell title', {'string': 'value', 'number': 1.0, 'array': ['a', 'b']})):
    compare(text_to_metadata(text, allow_title=True), value)
    assert metadata_to_text(*value) == 'cell title string="value" number=1.0 array=["a", "b"]'
github mwouts / jupytext / tests / test_cell_metadata.py View on Github external
def test_values_with_equal_signs_inside(text='python string="value=5"',
                                        value=('python', {'string': 'value=5'})):
    compare(text_to_metadata(text), value)
    assert metadata_to_text(*value) == text
github mwouts / jupytext / tests / test_cell_metadata.py View on Github external
def test_only_metadata_2(text='key="value"', value=('', {'key': 'value'})):
    compare(text_to_metadata(text, allow_title=True), value)
    assert metadata_to_text(*value) == text
github mwouts / jupytext / tests / test_cell_metadata.py View on Github external
def test_title_and_relax_json(text="cell title string='value' number=1.0 array=['a', \"b\"]",
                              value=('cell title', {'string': 'value', 'number': 1.0, 'array': ['a', 'b']})):
    compare(text_to_metadata(text, allow_title=True), value)
    assert metadata_to_text(*value) == 'cell title string="value" number=1.0 array=["a", "b"]'
github mwouts / jupytext / jupytext / cell_reader.py View on Github external
def options_to_metadata(self, options):
        self.cell_metadata_json = self.cell_metadata_json or is_json_metadata(options)
        title, metadata = text_to_metadata(options, allow_title=True)

        # Cell type
        for cell_type in ['markdown', 'raw', 'md']:
            code = '[{}]'.format(cell_type)
            if code in title:
                title = title.replace(code, '').strip()
                metadata['cell_type'] = cell_type
                if cell_type == 'md':
                    metadata['region_name'] = cell_type
                    metadata['cell_type'] = 'markdown'
                break

        # Spyder has sub cells
        cell_depth = 0
        while title.startswith('%'):
            cell_depth += 1
github mwouts / jupytext / jupytext / cell_reader.py View on Github external
def options_to_metadata(self, options):
        if isinstance(options, tuple):
            options = ' '.join(options)
        self.cell_metadata_json = self.cell_metadata_json or is_json_metadata(options)
        return text_to_metadata(options)