Some time ago I had a problem where I had to exclude parts of one of my documents based on a build-time condition. I wanted to maintain one document but produce two versions: one that contained internal details of a product and one that didn't.
Nowadays I use reStructuredText (reST) and Docutils for writing my documents so naturally, I started Googling how to do it with the help of those tools. After some research, I found an out-of-the-box solution (unsurprisingly because we all have similar problems 😉). It may surprise you if you haven't looked into this problem before.