import docx

from .utils import BaseParser


class Parser(BaseParser):
    """Extract text from docx file using python-docx.
    """

    def extract(self, filename, **kwargs):
        text = ""
        document = docx.Document(filename)

        # Extract text from root paragraphs
        text += '\n\n'.join([
            paragraph.text for paragraph in document.paragraphs
        ])

        # Recursively extract text from root tables
        for table in document.tables:
            text += self._parse_table(table, text)

        return text

    def _parse_table(self, table, text):
        for row in table.rows:
            for cell in row.cells:
                # For every cell in every row of the table, extract text from child paragraphs
                text += '\n\n'.join([
                    paragraph.text for paragraph in cell
                ])

                # Then recursively extract text from child tables
                for table in cell.tables:
                    text += _parse_table(table, text)

        return text

@@ -267,33 +267,34 @@
  root paragraphs
+.
 %0A
-
         text += 
@@ -430,24 +430,25 @@
  root tables
+.
 %0A        for
@@ -728,24 +728,43 @@
 t text from 
+%0A                # 
 child paragr
@@ -759,32 +759,33 @@
 child paragraphs
+.
 %0A               
@@ -876,32 +876,32 @@
             %5D)%0A%0A
-
                 
@@ -949,16 +949,17 @@
 d tables
+.
 %0A       

Update docx_parser.py