Skip to content

Commit

Permalink
.md and .markdown everywhere
Browse files Browse the repository at this point in the history
Closes #325
  • Loading branch information
mwouts committed Sep 17, 2019
1 parent 5c3f5c4 commit 818f7e1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion jupytext/cell_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions jupytext/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', {}):
Expand Down
4 changes: 2 additions & 2 deletions jupytext/contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions jupytext/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '{}'. "
Expand All @@ -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', '#')
Expand Down Expand Up @@ -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', {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jupytext/jupytext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<!-- #region') and
not texts[i + 1][0].startswith('<!-- #region') and
Expand Down
3 changes: 2 additions & 1 deletion jupytext/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ def uncomment_magic(source, language='python', global_escape_flag=True):


_ESCAPED_CODE_START = {'.Rmd': re.compile(r"^(# |#)*```{.*}"),
'.md': re.compile(r"^(# |#)*```")}
'.md': re.compile(r"^(# |#)*```"),
'.markdown': re.compile(r"^(# |#)*```")}
_ESCAPED_CODE_START.update({ext: re.compile(
r"^({0} |{0})*({0}|{0} )\+".format(_SCRIPT_EXTENSIONS[ext]['comment'])) for ext in _SCRIPT_EXTENSIONS})

Expand Down

0 comments on commit 818f7e1

Please sign in to comment.