title: highlighting words in an docx file using python-docx gives incorrect results
body: <p>I would like to highlight specific words in an MS word document (here given as negativeList) and leave the rest of the document as it was before. I have tried to adopt from this <a href="https://stackoverflow.com/questions/46116389/highlight-text-using-python-docx">one</a> but I can not get it running as it should:</p>
  
  <pre><code>from docx.enum.text import WD_COLOR_INDEX
  from docx import Document
  import pandas as pd
  import copy
  import re
  
  doc = Document(docxFileName)
  
  negativList = ["king", "children", "lived", "fire"]  # some examples
  
  for paragraph in doc.paragraphs:
      for target in negativList:
          if target in paragraph.text:  # it is worth checking in detail ...
  
              currRuns = copy.copy(paragraph.runs)   # deep copy as we delete/clear the object
              paragraph.runs.clear()
  
              for run in currRuns:
                  if target in run.text:
                      words = re.split('(\W)', run.text)  # split into words in order to be able to color only one
                      for word in words:
                          if word == target:
                              newRun = paragraph.add_run(word)
                              newRun.font.highlight_color = WD_COLOR_INDEX.PINK
                          else:
                              newRun = paragraph.add_run(word)
                              newRun.font.highlight_color = None
                  else: # our target is not in it so we add it unchanged
                      paragraph.runs.append(run)
  
  doc.save('output.docx')
  </code></pre>
  
  <p>As example I am using this text (in a word docx file):</p>
  
  <blockquote>
    <p>CHAPTER 1</p>
    
    <p>Centuries ago there lived --</p>
    
    <p>"A king!" my little readers will say immediately.</p>
    
    <p>No, children, you are mistaken. Once upon a time there was a piece of
    wood. It was not an expensive piece of wood. Far from it. Just a
    common block of firewood, one of those thick, solid logs that are put
    on the fire in winter to make cold rooms cozy and warm.</p>
  </blockquote>
  
  <p>There are multiple problems with my code:</p>
  
  <p>1) The first sentence works but the second sentence is in twice. Why?</p>
  
  <p>2) The format gets somehow lost in the part where I highlight. I would possibly need to copy the properties of the original run into the newly created ones but how do I do this?</p>
  
  <p>3) I loose the terminal "--"</p>
  
  <p>4) In the highlighted last paragraph the "cozy and warm" is missing ...</p>
  
  <p>What I would need is a eighter a fix for these problems or maybe I am overthinking it and there is a much easier way to do the highlighting? (something like doc.highlight({"king": "pink"} but I haven't found anything in the documentation)?</p>