From 7fcb258ca10f76a8f0cd1747c2d23c5f70ef995d Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sun, 15 Sep 2019 20:17:21 +0200 Subject: [PATCH] .md and .markdown everywhere Closes #325 --- jupytext/cell_reader.py | 2 +- jupytext/combine.py | 4 ++-- jupytext/contentsmanager.py | 4 ++-- jupytext/formats.py | 11 ++++++----- jupytext/jupytext.py | 2 +- jupytext/magics.py | 3 ++- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/jupytext/cell_reader.py b/jupytext/cell_reader.py index b7e085961..b4e9e305b 100644 --- a/jupytext/cell_reader.py +++ b/jupytext/cell_reader.py @@ -191,7 +191,7 @@ def find_cell_content(self, lines): # Is this a raw cell? if ('active' in self.metadata and not is_active('ipynb', self.metadata)) or \ - (self.ext == '.md' and self.cell_type == 'code' and self.language is None): + (self.ext in ['.md', '.markdown'] and self.cell_type == 'code' and self.language is None): if self.metadata.get('active') == '': del self.metadata['active'] self.cell_type = 'raw' diff --git a/jupytext/combine.py b/jupytext/combine.py index 0c76c845c..0b8e24bd0 100644 --- a/jupytext/combine.py +++ b/jupytext/combine.py @@ -46,8 +46,8 @@ 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']: + source_is_md_version_one = ext in ['.md', '.markdown', '.Rmd'] and text_repr.get('format_version') == '1.0' + if nb_source.metadata.get('jupytext', {}).get('formats') or ext in ['.md', '.markdown', '.Rmd']: nb_source.metadata.get('jupytext', {}).pop('text_representation', None) if not nb_source.metadata.get('jupytext', {}): diff --git a/jupytext/contentsmanager.py b/jupytext/contentsmanager.py index 9fb64b578..563946254 100644 --- a/jupytext/contentsmanager.py +++ b/jupytext/contentsmanager.py @@ -36,7 +36,7 @@ def preferred_format(incomplete_format, preferred_formats): for fmt in long_form_multiple_formats(preferred_formats): if ((incomplete_format['extension'] == fmt['extension'] or ( fmt['extension'] == '.auto' and - incomplete_format['extension'] not in ['.md', '.Rmd', '.ipynb'])) and + incomplete_format['extension'] not in ['.md', '.markdown', '.Rmd', '.ipynb'])) and incomplete_format.get('suffix') == fmt.get('suffix', incomplete_format.get('suffix')) and incomplete_format.get('prefix') == fmt.get('prefix', incomplete_format.get('prefix'))): fmt.update(incomplete_format) @@ -264,7 +264,7 @@ def save(self, model, path=''): alt_path = full_path(base, fmt) self.create_prefix_dir(alt_path, fmt) - if 'format_name' in fmt and fmt['extension'] not in ['.Rmd', '.md']: + if 'format_name' in fmt and fmt['extension'] not in ['.md', '.markdown', '.Rmd']: self.log.info("Saving %s in format %s:%s", os.path.basename(alt_path), fmt['extension'][1:], fmt['format_name']) else: diff --git a/jupytext/formats.py b/jupytext/formats.py index 683c7b6c7..d5e2f0b79 100644 --- a/jupytext/formats.py +++ b/jupytext/formats.py @@ -170,7 +170,7 @@ def get_format_implementation(ext, format_name=None): formats_for_extension.append(fmt.format_name) if formats_for_extension: - if ext == '.md' and format_name == 'pandoc': + if ext in ['.md', '.markdown'] and format_name == 'pandoc': raise JupytextFormatError('Please install pandoc>=2.7.2') raise JupytextFormatError("Format '{}' is not associated to extension '{}'. " @@ -184,7 +184,7 @@ def read_metadata(text, ext): ext = '.' + ext.split('.')[-1] lines = text.splitlines() - if ext in ['.md', '.Rmd']: + if ext in ['.md', '.markdown', '.Rmd']: comment = '' else: comment = _SCRIPT_EXTENSIONS.get(ext, {}).get('comment', '#') @@ -274,7 +274,7 @@ def guess_format(text, ext): if rspin_comment_count >= 1: return 'spin', {} - if ext == '.md': + if ext in ['.md', '.markdown']: for line in lines: if line.startswith(':::'): # Pandoc div return 'pandoc', {} @@ -355,7 +355,7 @@ def format_name_for_ext(metadata, ext, cm_default_formats=None, explicit_default if (not explicit_default) or fmt.get('format_name'): return fmt.get('format_name') - if (not explicit_default) or ext in ['.Rmd', '.md']: + if (not explicit_default) or ext in ['.md', '.markdown', '.Rmd']: return None return get_format_implementation(ext).format_name @@ -509,7 +509,8 @@ def short_form_one_format(jupytext_format): fmt = jupytext_format['prefix'] + '/' + fmt if jupytext_format.get('format_name'): - if jupytext_format['extension'] not in ['.md', '.Rmd'] or jupytext_format['format_name'] == 'pandoc': + if jupytext_format['extension'] not in ['.md', '.markdown', '.Rmd'] or \ + jupytext_format['format_name'] == 'pandoc': fmt = fmt + ':' + jupytext_format['format_name'] return fmt diff --git a/jupytext/jupytext.py b/jupytext/jupytext.py index 1c8135a0b..10bd9a1b7 100644 --- a/jupytext/jupytext.py +++ b/jupytext/jupytext.py @@ -161,7 +161,7 @@ def writes(self, nb, metadata=None, **kwargs): text.extend([''] * lines_to_next_cell) # two blank lines between markdown cells in Rmd when those do not have explicit region markers - if self.ext in ['.Rmd', '.md'] and not cell.is_code(): + if self.ext in ['.md', '.markdown', '.Rmd'] and not cell.is_code(): if (i + 1 < len(cell_exporters) and not cell_exporters[i + 1].is_code() and not texts[i][0].startswith('