docs: def parse_config_for_selected_keys(content, keys):
    """ Parse a config from a magic cell body for selected config keys.
  
    For example, if 'content' is:
      config_item1: value1
      config_item2: value2
      config_item3: value3
    and 'keys' are: [config_item1, config_item3]
  
    The results will be a tuple of
    1. The parsed config items (dict): {config_item1: value1, config_item3: value3}
    2. The remaining content (string): config_item2: value2
  
    Args:
      content: the input content. A string. It has to be a yaml or JSON string.
      keys: a list of keys to retrieve from content. Note that it only checks top level keys
          in the dict.
  
    Returns:
      A tuple. First is the parsed config including only selected keys. Second is
        the remaining content.
  
    Raises:
      Exception if the content is not a valid yaml or JSON string.
    """
  
    config_items = {key: None for key in keys}
    if not content:
      return config_items, content
  
    stripped = content.strip()
    if len(stripped) == 0:
      return {}, None
    elif stripped[0] == '{':
      config = json.loads(content)
    else:
      config = yaml.load(content)
  
    if not isinstance(config, dict):
      raise ValueError('Invalid config.')
  
    for key in keys:
      config_items[key] = config.pop(key, None)
  
    if not config:
      return config_items, None
  
    if stripped[0] == '{':
      content_out = json.dumps(config, indent=4)
    else:
      content_out = yaml.dump(config, default_flow_style=False)
  
    return config_items, content_out