Skip to content

Commit

Permalink
Markdown and R Markdown format in version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Mar 30, 2019
1 parent d032b87 commit 57c2c08
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 6 additions & 5 deletions jupytext/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ def combine_inputs_with_outputs(nb_source, nb_outputs, fmt=None):
output_other_cells = [cell for cell in nb_outputs.cells if cell.cell_type != 'code']

fmt = long_form_one_format(fmt)
ext = fmt.get('extension')
format_name = fmt.get('format_name')
text_repr = nb_source.metadata.get('jupytext', {}).get('text_representation', {})
ext = fmt.get('extension') or text_repr.get('extension')
format_name = fmt.get('format_name') or text_repr.get('format_name')

nb_outputs_filtered_metadata = copy(nb_outputs.metadata)
filter_metadata(nb_outputs_filtered_metadata,
Expand All @@ -45,6 +46,7 @@ def combine_inputs_with_outputs(nb_source, nb_outputs, fmt=None):
if key not in nb_outputs_filtered_metadata:
nb_source.metadata[key] = nb_outputs.metadata[key]

source_is_md_version_one = ext in ['.md', '.Rmd'] and text_repr.get('format_version') == '1.0'
if nb_source.metadata.get('jupytext', {}).get('formats') or ext in ['.md', '.Rmd']:
nb_source.metadata.get('jupytext', {}).pop('text_representation', None)

Expand All @@ -64,7 +66,7 @@ def combine_inputs_with_outputs(nb_source, nb_outputs, fmt=None):
cell.outputs = ocell.outputs

# Append cell metadata that was filtered
if (ext and ext.endswith('.md')) or format_name in ['bare', 'sphinx']:
if format_name in ['bare', 'sphinx'] or source_is_md_version_one:
ocell_filtered_metadata = {}
else:
ocell_filtered_metadata = copy(ocell.metadata)
Expand All @@ -81,8 +83,7 @@ def combine_inputs_with_outputs(nb_source, nb_outputs, fmt=None):
else:
for i, ocell in enumerate(output_other_cells):
if cell.cell_type == ocell.cell_type and same_content(cell.source, ocell.source):
if (ext and (ext.endswith('.md') or ext.endswith('.Rmd'))) \
or format_name in ['spin', 'bare', 'sphinx', 'sphinx']:
if format_name in ['spin', 'bare', 'sphinx'] or source_is_md_version_one:
ocell_filtered_metadata = {}
else:
ocell_filtered_metadata = copy(ocell.metadata)
Expand Down
8 changes: 6 additions & 2 deletions jupytext/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def __init__(self,
cell_reader_class=MarkdownCellReader,
cell_exporter_class=MarkdownCellExporter,
# Version 1.0 on 2018-08-31 - jupytext v0.6.0 : Initial version
current_version_number='1.0'),
# Version 1.1 on 2019-03-24 - jupytext v1.1.0 : Markdown regions and cell metadata
current_version_number='1.1',
min_readable_version_number='1.0'),

NotebookFormatDescription(
format_name='rmarkdown',
Expand All @@ -61,7 +63,9 @@ def __init__(self,
cell_reader_class=RMarkdownCellReader,
cell_exporter_class=RMarkdownCellExporter,
# Version 1.0 on 2018-08-22 - jupytext v0.5.2 : Initial version
current_version_number='1.0')] + \
# Version 1.1 on 2019-03-24 - jupytext v1.1.0 : Markdown regions and cell metadata
current_version_number='1.1',
min_readable_version_number='1.0')] + \
[
NotebookFormatDescription(
format_name='light',
Expand Down

0 comments on commit 57c2c08

Please sign in to comment.