docs: def rebuild_reference_lines(ref_sectn, ref_line_marker_ptn):
      """Given a reference section, rebuild the reference lines. After translation
         from PDF to text, reference lines are often broken. This is because
         pdftotext doesn't know what is a wrapped-line and what is a genuine new
         line. As a result, the following 2 reference lines:
          [1] See http://invenio-software.org/ for more details.
          [2] Example, AN: private communication (1996).
         ...could be broken into the following 4 lines during translation from PDF
         to plaintext:
          [1] See http://invenio-software.org/ fo
          r more details.
          [2] Example, AN: private communica
          tion (1996).
         Such a situation could lead to a citation being separated across 'lines',
         meaning that it wouldn't be correctly recognised.
         This function tries to rebuild the reference lines. It uses the pattern
         used to recognise a reference line's numeration marker to indicate the
         start of a line. If no reference line numeration was recognised, it will
         simply join all lines together into one large reference line.
         @param ref_sectn: (list) of strings. The (potentially broken) reference
          lines.
         @param ref_line_marker_ptn: (string) - the pattern used to recognise a
          reference line's numeration marker.
         @return: (list) of strings - the rebuilt reference section. Each string
          in the list represents a complete reference line.
      """
      indentation_splitting = False
  
      # This should be moved the function detecting the pattern!
      if not ref_line_marker_ptn:
          if test_for_blank_lines_separating_reference_lines(ref_sectn):
              # Use blank lines to separate ref lines
              ref_line_marker_ptn = ur'^\s*$'
          else:
              # No ref line dividers
              # We are guessing this the format:
              # Reference1
              #      etc
              # Reference2
              #      etc
              # We split when there's no identation
              indentation_splitting = True
              ref_line_marker_ptn = ur'^[^\s]'
  
      LOGGER.debug(u"references separator %s", ref_line_marker_ptn)
      p_ref_line_marker = re.compile(ref_line_marker_ptn, re.I | re.UNICODE)
  
      # Start from ref 1
      # Append each fixed reference line to rebuilt_references
      # and rebuild references as we go
      current_ref = 0
      rebuilt_references = []
      working_ref = []
  
      def prepare_ref(working_ref):
          working_ref = working_ref[:CFG_REFEXTRACT_MAX_LINES]
          working_line = ""
          for l in working_ref:
              working_line = join_lines(working_line, l.strip())
          return working_line.rstrip()
  
      lower_case_start = re.compile(ur'[a-z]')
      continuing_line_markers = re.compile(ur'[,&-]$')
  
      for line in ref_sectn:
          # Can't find a good way to distinguish between
          # pagination and the page number of a journal numeration that
          # happens to be alone in a new line
          # m = match_pagination(line)
          # if m and current_ref and current_ref != m + 1:
          #     continue
  
          # Try to find the marker for the reference line
          m_ref_line_marker = p_ref_line_marker.search(line)
  
          if m_ref_line_marker:
              try:
                  marknum = int(m_ref_line_marker.group('marknum'))
              except IndexError:
                  marknum = None
              except ValueError:
                  # If the mark is a unicode character category [Nd],
                  # it is not always convertible to int by int()
                  # We can't use its numerical value, but we still accept it
                  # as numeration
                  pass
  
              new_line_detected = False
              if marknum is None or current_ref + 1 == marknum:
                  new_line_detected = True
              if indentation_splitting:
                  if lower_case_start.match(line.strip()):
                      new_line_detected = False
                  if working_ref and \
                          continuing_line_markers.search(working_ref[-1].strip()):
                      new_line_detected = False
  
              if new_line_detected:
                  # Reference line marker found! : Append this reference to the
                  # list of fixed references and reset the working_line to
                  # 'blank'
                  start = m_ref_line_marker.start()
                  if line[:start]:
                      # If it's not a blank line to separate refs
                      # Only append from the start of the marker
                      # For this case:
                      # [1] hello
                      # hello2 [2] foo
                      working_ref.append(line[:start])
  
                  # Append current working line to the refs list
                  if working_ref:
                      rebuilt_references.append(prepare_ref(working_ref))
  
                  current_ref = marknum
                  working_ref = []
                  if line[start:]:
                      working_ref.append(line[start:])
  
              else:
                  # Our marker does not match the counting
                  # Either we missed one, the author missed one or
                  # it is not a line marker
                  # For now we assume it is not line marker
                  working_ref.append(line)
  
          elif line:
              # Continuation of line
              working_ref.append(line)
  
      if working_ref:
          # Append last line
          rebuilt_references.append(prepare_ref(working_ref))
  
      return rebuilt_references