title: Extracting MS Word document formatting elements along with raw text information
body: <p>In <a href="https://stackoverflow.com/questions/125222/extracting-text-from-ms-word-files-in-python">this post</a> @mikemaccana describes how to use <a href="https://python-docx.readthedocs.io/en/latest/" rel="nofollow noreferrer">python-docx</a> to extract raw text data from an MS Word document from within python. I'd like to go one step further. Instead of simple extracting the raw text information, can I also use this module to harvest information about font face (e.g. bold versus italic) or font size (e.g. 12 versus 18pt). The closest I was able to come was <a href="https://stackoverflow.com/questions/9562671/extracting-highlighted-words-from-word-document-docx-in-python">this post</a> asking about using this module to extract highlighted text entries. </p>
  
  <p>Seemed a little abstract, and I'm not totally sure what's going on here. Is there a more straightforward way to extract formatting information from a Word doc in python? By way of a quick document template: </p>
  
  <blockquote>
    <h1>Here the first line is a large header with one sentence.</h1>
    
    <h2>The second line is slightly smaller. It also has two sentences.</h2>
    
    <h3>Even smaller. But that's not all. This line has three sentences.</h3>
    
    <p>And finally here's a regular line of unbolded text. </p>
  </blockquote>
  
  <p>If we call these four lines my word document, I'd like to writing a parsing function, call it <code>doc_parser</code>, that returns something <em>like</em> the following: </p>
  
  <pre><code>&gt;&gt;&gt;&gt; doc_data = doc_parser(path_to_example_doc)
  &gt;&gt;&gt;&gt; print(doc_data)
  [1] [{'font': 18, 'face': 'bold', 'n_sentence': 1}, 
  {'font': 16, 'face': 'bold', 'n_sentence': 2}, 
  {'font': 14, 'face': 'bold', 'n_sentence': 3}, 
  {'font': 12, 'face': 'plain', 'n_sentence': 1}]
  </code></pre>