import jinja2


def block(jinja2_context: jinja2.runtime.Context, value: str) -> str:
  """Returns value, in a block comment.

  If this can't determine how to create a comment for the filetype, returns the
  text unfiltered.

  Args:
    jinja2_context: Context from jinja.
    value: Partially-rendered template text to filter.
  """
  context = jinja2_context.parent['context']

  if not value:
    return ''

  contained_info = context.contained_comment()
  if contained_info is not None:
    start, mid, end = contained_info
    ret = [start + '\n']
    for line in value.splitlines():
      ret.append('{}{}{}\n'.format(mid, ' ' if mid and line else '', line))
    ret.append(end + '\n')
    return ''.join(ret)

  prefix = context.prefixed_comment()
  if prefix is not None:
    return ''.join([
        '{}{}{}\n'.format(prefix, ' ' if prefix and line else '', line)
        for line in value.splitlines()
    ])

  return value