prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  node != nodejs within Debian packages
  As part of resolving https://github.com/ipython/nbviewer/issues/196, (and https://github.com/ipython/nbviewer/pull/194), @ahmadia and I ended up finding out that Debian based Linux Distributions build the `node` binary as `nodejs`.
  
  IPython nbconvert defaults to using `node`, which is actually `ax25-node` on Debian based systems. [See relevant posting on the Debian mailing list for more](https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html).
  
  This won't affect users of nvm (who provide `node`) or those who build from source. This will affect certain strains of Ubuntu (Saucy Salamander was what I used to test).
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `IPython/nbconvert/filters/markdown.py`
  Content:
  ```
  1 """Markdown filters
  2 This file contains a collection of utility filters for dealing with 
  3 markdown within Jinja templates.
  4 """
  5 #-----------------------------------------------------------------------------
  6 # Copyright (c) 2013, the IPython Development Team.
  7 #
  8 # Distributed under the terms of the Modified BSD License.
  9 #
  10 # The full license is in the file COPYING.txt, distributed with this software.
  11 #-----------------------------------------------------------------------------
  12 
  13 #-----------------------------------------------------------------------------
  14 # Imports
  15 #-----------------------------------------------------------------------------
  16 from __future__ import print_function
  17 
  18 # Stdlib imports
  19 import os
  20 import subprocess
  21 from io import TextIOWrapper, BytesIO
  22 
  23 # IPython imports
  24 from IPython.nbconvert.utils.pandoc import pandoc
  25 from IPython.nbconvert.utils.exceptions import ConversionException
  26 from IPython.utils.process import find_cmd, FindCmdError
  27 from IPython.utils.py3compat import cast_bytes
  28 
  29 #-----------------------------------------------------------------------------
  30 # Functions
  31 #-----------------------------------------------------------------------------
  32 marked = os.path.join(os.path.dirname(__file__), "marked.js")
  33 
  34 __all__ = [
  35     'markdown2html',
  36     'markdown2html_pandoc',
  37     'markdown2html_marked',
  38     'markdown2latex',
  39     'markdown2rst',
  40 ]
  41 
  42 class NodeJSMissing(ConversionException):
  43     """Exception raised when node.js is missing."""
  44     pass
  45 
  46 def markdown2latex(source):
  47     """Convert a markdown string to LaTeX via pandoc.
  48 
  49     This function will raise an error if pandoc is not installed.
  50     Any error messages generated by pandoc are printed to stderr.
  51 
  52     Parameters
  53     ----------
  54     source : string
  55       Input string, assumed to be valid markdown.
  56 
  57     Returns
  58     -------
  59     out : string
  60       Output as returned by pandoc.
  61     """
  62     return pandoc(source, 'markdown', 'latex')
  63 
  64 def markdown2html_pandoc(source):
  65     """Convert a markdown string to HTML via pandoc"""
  66     return pandoc(source, 'markdown', 'html', extra_args=['--mathjax'])
  67 
  68 def markdown2html_marked(source, encoding='utf-8'):
  69     """Convert a markdown string to HTML via marked"""
  70     command = ['node', marked]
  71     try:
  72         p = subprocess.Popen(command,
  73                              stdin=subprocess.PIPE, stdout=subprocess.PIPE
  74         )
  75     except OSError as e:
  76         raise NodeJSMissing(
  77             "The command '%s' returned an error: %s.\n" % (" ".join(command), e) +
  78             "Please check that Node.js is installed."
  79         )
  80     out, _ = p.communicate(cast_bytes(source, encoding))
  81     out = TextIOWrapper(BytesIO(out), encoding, 'replace').read()
  82     return out.rstrip('\n')
  83 
  84 def markdown2rst(source):
  85     """Convert a markdown string to LaTeX via pandoc.
  86 
  87     This function will raise an error if pandoc is not installed.
  88     Any error messages generated by pandoc are printed to stderr.
  89 
  90     Parameters
  91     ----------
  92     source : string
  93       Input string, assumed to be valid markdown.
  94 
  95     Returns
  96     -------
  97     out : string
  98       Output as returned by pandoc.
  99     """
  100     return pandoc(source, 'markdown', 'rst')
  101 
  102 try:
  103     find_cmd('node')
  104 except FindCmdError:
  105     markdown2html = markdown2html_pandoc
  106 else:
  107     markdown2html = markdown2html_marked
  108
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/IPython/nbconvert/filters/markdown.py b/IPython/nbconvert/filters/markdown.py
  --- a/IPython/nbconvert/filters/markdown.py
  +++ b/IPython/nbconvert/filters/markdown.py
  @@ -67,7 +67,7 @@
   
   def markdown2html_marked(source, encoding='utf-8'):
       """Convert a markdown string to HTML via marked"""
  -    command = ['node', marked]
  +    command = [node_cmd, marked]
       try:
           p = subprocess.Popen(command,
                                stdin=subprocess.PIPE, stdout=subprocess.PIPE
  @@ -99,9 +99,18 @@
       """
       return pandoc(source, 'markdown', 'rst')
   
  +# prefer md2html via marked if node.js is available
  +# node is called nodejs on debian, so try that first
  +node_cmd = 'nodejs'
   try:
  -    find_cmd('node')
  +    find_cmd(node_cmd)
   except FindCmdError:
  -    markdown2html = markdown2html_pandoc
  +    node_cmd = 'node'
  +    try:
  +        find_cmd(node_cmd)
  +    except FindCmdError:
  +        markdown2html = markdown2html_pandoc
  +    else:
  +        markdown2html = markdown2html_marked
   else:
       markdown2html = markdown2html_marked
  
verification_info: {"golden_diff": "diff --git a/IPython/nbconvert/filters/markdown.py b/IPython/nbconvert/filters/markdown.py\n--- a/IPython/nbconvert/filters/markdown.py\n+++ b/IPython/nbconvert/filters/markdown.py\n@@ -67,7 +67,7 @@\n \n def markdown2html_marked(source, encoding='utf-8'):\n     \"\"\"Convert a markdown string to HTML via marked\"\"\"\n-    command = ['node', marked]\n+    command = [node_cmd, marked]\n     try:\n         p = subprocess.Popen(command,\n                              stdin=subprocess.PIPE, stdout=subprocess.PIPE\n@@ -99,9 +99,18 @@\n     \"\"\"\n     return pandoc(source, 'markdown', 'rst')\n \n+# prefer md2html via marked if node.js is available\n+# node is called nodejs on debian, so try that first\n+node_cmd = 'nodejs'\n try:\n-    find_cmd('node')\n+    find_cmd(node_cmd)\n except FindCmdError:\n-    markdown2html = markdown2html_pandoc\n+    node_cmd = 'node'\n+    try:\n+        find_cmd(node_cmd)\n+    except FindCmdError:\n+        markdown2html = markdown2html_pandoc\n+    else:\n+        markdown2html = markdown2html_marked\n else:\n     markdown2html = markdown2html_marked\n", "issue": "node != nodejs within Debian packages\nAs part of resolving https://github.com/ipython/nbviewer/issues/196, (and https://github.com/ipython/nbviewer/pull/194), @ahmadia and I ended up finding out that Debian based Linux Distributions build the `node` binary as `nodejs`.\n\nIPython nbconvert defaults to using `node`, which is actually `ax25-node` on Debian based systems. [See relevant posting on the Debian mailing list for more](https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html).\n\nThis won't affect users of nvm (who provide `node`) or those who build from source. This will affect certain strains of Ubuntu (Saucy Salamander was what I used to test).\n\n", "before_files": [{"content": "\"\"\"Markdown filters\nThis file contains a collection of utility filters for dealing with \nmarkdown within Jinja templates.\n\"\"\"\n#-----------------------------------------------------------------------------\n# Copyright (c) 2013, the IPython Development Team.\n#\n# Distributed under the terms of the Modified BSD License.\n#\n# The full license is in the file COPYING.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Imports\n#-----------------------------------------------------------------------------\nfrom __future__ import print_function\n\n# Stdlib imports\nimport os\nimport subprocess\nfrom io import TextIOWrapper, BytesIO\n\n# IPython imports\nfrom IPython.nbconvert.utils.pandoc import pandoc\nfrom IPython.nbconvert.utils.exceptions import ConversionException\nfrom IPython.utils.process import find_cmd, FindCmdError\nfrom IPython.utils.py3compat import cast_bytes\n\n#-----------------------------------------------------------------------------\n# Functions\n#-----------------------------------------------------------------------------\nmarked = os.path.join(os.path.dirname(__file__), \"marked.js\")\n\n__all__ = [\n    'markdown2html',\n    'markdown2html_pandoc',\n    'markdown2html_marked',\n    'markdown2latex',\n    'markdown2rst',\n]\n\nclass NodeJSMissing(ConversionException):\n    \"\"\"Exception raised when node.js is missing.\"\"\"\n    pass\n\ndef markdown2latex(source):\n    \"\"\"Convert a markdown string to LaTeX via pandoc.\n\n    This function will raise an error if pandoc is not installed.\n    Any error messages generated by pandoc are printed to stderr.\n\n    Parameters\n    ----------\n    source : string\n      Input string, assumed to be valid markdown.\n\n    Returns\n    -------\n    out : string\n      Output as returned by pandoc.\n    \"\"\"\n    return pandoc(source, 'markdown', 'latex')\n\ndef markdown2html_pandoc(source):\n    \"\"\"Convert a markdown string to HTML via pandoc\"\"\"\n    return pandoc(source, 'markdown', 'html', extra_args=['--mathjax'])\n\ndef markdown2html_marked(source, encoding='utf-8'):\n    \"\"\"Convert a markdown string to HTML via marked\"\"\"\n    command = ['node', marked]\n    try:\n        p = subprocess.Popen(command,\n                             stdin=subprocess.PIPE, stdout=subprocess.PIPE\n        )\n    except OSError as e:\n        raise NodeJSMissing(\n            \"The command '%s' returned an error: %s.\\n\" % (\" \".join(command), e) +\n            \"Please check that Node.js is installed.\"\n        )\n    out, _ = p.communicate(cast_bytes(source, encoding))\n    out = TextIOWrapper(BytesIO(out), encoding, 'replace').read()\n    return out.rstrip('\\n')\n\ndef markdown2rst(source):\n    \"\"\"Convert a markdown string to LaTeX via pandoc.\n\n    This function will raise an error if pandoc is not installed.\n    Any error messages generated by pandoc are printed to stderr.\n\n    Parameters\n    ----------\n    source : string\n      Input string, assumed to be valid markdown.\n\n    Returns\n    -------\n    out : string\n      Output as returned by pandoc.\n    \"\"\"\n    return pandoc(source, 'markdown', 'rst')\n\ntry:\n    find_cmd('node')\nexcept FindCmdError:\n    markdown2html = markdown2html_pandoc\nelse:\n    markdown2html = markdown2html_marked\n", "path": "IPython/nbconvert/filters/markdown.py"}], "after_files": [{"content": "\"\"\"Markdown filters\nThis file contains a collection of utility filters for dealing with \nmarkdown within Jinja templates.\n\"\"\"\n#-----------------------------------------------------------------------------\n# Copyright (c) 2013, the IPython Development Team.\n#\n# Distributed under the terms of the Modified BSD License.\n#\n# The full license is in the file COPYING.txt, distributed with this software.\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Imports\n#-----------------------------------------------------------------------------\nfrom __future__ import print_function\n\n# Stdlib imports\nimport os\nimport subprocess\nfrom io import TextIOWrapper, BytesIO\n\n# IPython imports\nfrom IPython.nbconvert.utils.pandoc import pandoc\nfrom IPython.nbconvert.utils.exceptions import ConversionException\nfrom IPython.utils.process import find_cmd, FindCmdError\nfrom IPython.utils.py3compat import cast_bytes\n\n#-----------------------------------------------------------------------------\n# Functions\n#-----------------------------------------------------------------------------\nmarked = os.path.join(os.path.dirname(__file__), \"marked.js\")\n\n__all__ = [\n    'markdown2html',\n    'markdown2html_pandoc',\n    'markdown2html_marked',\n    'markdown2latex',\n    'markdown2rst',\n]\n\nclass NodeJSMissing(ConversionException):\n    \"\"\"Exception raised when node.js is missing.\"\"\"\n    pass\n\ndef markdown2latex(source):\n    \"\"\"Convert a markdown string to LaTeX via pandoc.\n\n    This function will raise an error if pandoc is not installed.\n    Any error messages generated by pandoc are printed to stderr.\n\n    Parameters\n    ----------\n    source : string\n      Input string, assumed to be valid markdown.\n\n    Returns\n    -------\n    out : string\n      Output as returned by pandoc.\n    \"\"\"\n    return pandoc(source, 'markdown', 'latex')\n\ndef markdown2html_pandoc(source):\n    \"\"\"Convert a markdown string to HTML via pandoc\"\"\"\n    return pandoc(source, 'markdown', 'html', extra_args=['--mathjax'])\n\ndef markdown2html_marked(source, encoding='utf-8'):\n    \"\"\"Convert a markdown string to HTML via marked\"\"\"\n    command = [node_cmd, marked]\n    try:\n        p = subprocess.Popen(command,\n                             stdin=subprocess.PIPE, stdout=subprocess.PIPE\n        )\n    except OSError as e:\n        raise NodeJSMissing(\n            \"The command '%s' returned an error: %s.\\n\" % (\" \".join(command), e) +\n            \"Please check that Node.js is installed.\"\n        )\n    out, _ = p.communicate(cast_bytes(source, encoding))\n    out = TextIOWrapper(BytesIO(out), encoding, 'replace').read()\n    return out.rstrip('\\n')\n\ndef markdown2rst(source):\n    \"\"\"Convert a markdown string to LaTeX via pandoc.\n\n    This function will raise an error if pandoc is not installed.\n    Any error messages generated by pandoc are printed to stderr.\n\n    Parameters\n    ----------\n    source : string\n      Input string, assumed to be valid markdown.\n\n    Returns\n    -------\n    out : string\n      Output as returned by pandoc.\n    \"\"\"\n    return pandoc(source, 'markdown', 'rst')\n\n# prefer md2html via marked if node.js is available\n# node is called nodejs on debian, so try that first\nnode_cmd = 'nodejs'\ntry:\n    find_cmd(node_cmd)\nexcept FindCmdError:\n    node_cmd = 'node'\n    try:\n        find_cmd(node_cmd)\n    except FindCmdError:\n        markdown2html = markdown2html_pandoc\n    else:\n        markdown2html = markdown2html_marked\nelse:\n    markdown2html = markdown2html_marked\n", "path": "IPython/nbconvert/filters/markdown.py"}]}