docs: def _replace_keyword(self, keyword, replacement, count=0):
      """
      replace_keyword(keyword, replacement[, count])
  
      Walk through the element and its children
      and look for Str() objects that contains
      exactly the keyword. Then, replace it.
  
      Usually applied to an entire document (a :class:`.Doc` element)
  
      Note: If the replacement is a block, it cannot be put in place of
      a Str element. As a solution, the closest ancestor (e.g. the parent)
      will be replaced instead, but only if possible
      (if the parent only has one child).
  
      Example:
  
      >>> from panflute import *
      >>> p1 = Para(Str('Spam'), Space, Emph(Str('and'), Space, Str('eggs')))
      >>> p2 = Para(Str('eggs'))
      >>> p3 = Plain(Emph(Str('eggs')))
      >>> doc = Doc(p1, p2, p3)
      >>> doc.content
      ListContainer(Para(Str(Spam) Space Emph(Str(and) Space Str(eggs))) Para(Str(eggs)) Plain(Emph(Str(eggs))))
      >>> doc.replace_keyword('eggs', Str('ham'))
      >>> doc.content
      ListContainer(Para(Str(Spam) Space Emph(Str(and) Space Str(ham))) Para(Str(ham)) Plain(Emph(Str(ham))))
      >>> doc.replace_keyword(keyword='ham', replacement=Para(Str('spam')))
      >>> doc.content
      ListContainer(Para(Str(Spam) Space Emph(Str(and) Space Str(ham))) Para(Str(spam)) Para(Str(spam)))
  
      :param keyword: string that will be searched (cannot have spaces!)
      :type keyword: :class:`str`
      :param replacement: element that will be placed in turn of the ``Str``
       element that contains the keyword.
      :type replacement: :class:`.Element`
      :param count: number of occurrences that will be replaced.
       If count is not given or is set to zero, all occurrences
       will be replaced.
      :type count: :class:`int`
      """
  
      def replace_with_inline(e, doc):
          if type(e) == Str and e.text == keyword:
              doc.num_matches += 1
              if not count or doc.num_matches <= count:
                  return replacement
  
      def replace_with_block(e, doc):
          if hasattr(e, 'content') and len(e.content) == 1:
              ee = e.content[0]
              if type(ee) == Str and ee.text == keyword:
                  if isinstance(e, Block):
                      doc.num_matches += 1
                      if not count or doc.num_matches <= count:
                          return replacement
                  elif isinstance(e, Inline):
                      return Str(keyword)
  
      doc = self.doc
      if doc is None:
          raise Exception('No root document')
      doc.num_matches = 0
      if isinstance(replacement, Inline):
          return self.walk(replace_with_inline, doc)
      elif isinstance(replacement, Block):
          return self.walk(replace_with_block, doc)
      else:
          raise NotImplementedError(type(replacement))