Getting the plain text into InDesign
"For copying"? No need for such drastic measures, just use the regular
Place ... function in InDesign. Make sure to click the
Show import options checkbox, as this will show a dialog after you selected a file.
In this dialog, select "Remove Styles and Formatting from Text and Tables". Press OK to import the file with these settings. You will see the imported text is stripped of all "markups and crazy formatting".
However, be warned that some formatting adds text! For instance, bulleted and numbered lists count as 'formatting', and "clearing" the formatting from these paragraphs makes the bullet and number disappear. A way around this is to open the file with a Word-compatible editor that can convert such items to plain text (Microsoft Word itself can do that; I don't know of any others).
A good alternative to the above is to import the file with formatting, and then clearing all overrides. See the online Help for that. The advantage over importing without any formatting is that you can use InDesign's built-in Convert bullets and numbering to text function before removing the formatting that added them.
Lifting text straight out of the file
.docx file is a compound document format with all of its constituent parts zipped into one file. You can extract the individual files out of it with any PKZip compatible software (you may need to change the file extension to
.zip for some). After that, you get a folder full of data. The file that contains the plain text is usually
word/document.xml. Pay attention to the other files, though; I see one in my test that is more than 2Kb, called
These are XML files, and getting just the plain text out of it is still not an easy operation. I wrote up a quick and dirty XSLT transformation sheet to extract the plain text and found a couple of caveats right away.
A few: paragraphs are surrounded by XML tags, not with returns of any kind. So discarding all XML tags indiscriminately is not an option.
Similar to the returns, tabs are not physically present in the file but also have a tag of their own.
Also, not all plain text should appear in your output. Some tags' data are written out as plain text, and, in reverse, some tags seem to indicate their associated paragraph should not be included 'in' the visible text.
Finally, the same problem as when you discard all formatting: bullets and numbered lists are not physically present in the file but only indicated through tags. Not researched any further; you'd need quite a complex stylesheet to correctly preserve these.
Keeping the above in mind, this is the XSLT stylesheet I wrote up.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1"
<xsl:output method="text" indent="no" />
<!-- do not include paragraphs marked 'vanish' -->
<!-- this tag contains data as plain text, not as an attribute -->
<!-- Tsk tsk. (There could be more like these.) -->