We use Morera's Theorem. It suffices to show that if $T$ is any triangle in $\mathbb{C}$ that crosses $[-1,1]$, $\int_T f\,dz=0$.
The idea is as follows. Let $\gamma$ be the closed oriented curve round $T$ and $p$ be the point where $\gamma$ crosses $[-1,1]$. Choose points $q$ and $r$ near $p$ (one before and one after $p$), and let $\alpha$ be the rectangular curve that goes round $[-1,1]$ connecting $r$ and $q$.
An example is given in the image below.

Here, $[-1,1]$ is represented by the black line, the red triangle is $\gamma$ and $\alpha$ is the green segment. Say $r$ is the point below $[-1,1]$ and $q$ is the point above it.
Since $f$ is analytic outside $[-1,1]$, we have that the integral along the following path is $0$: start from $q$ and go along $\gamma$ until you meet $r$, then go along $-\alpha$ (opposite orientation) until you meet $q$ again. If we call the red segment of this path $\gamma'$, we thus have that
$$\int_{\gamma'}f\,dz=\int_\alpha f\,dz$$
On the other hand, $\int_\gamma f\,dz=\int_{\gamma'}f\,dz+\int_r^qf\,dz=\int_\alpha f\,dz+\int_r^qf\,dz$. In other words, integrating round the red triangleis the same as integrating round the red-green rectangle.
The thing is, we can repeat this construction making the rectangle tighter and tighter round the interval $[-1,1]$. In the end, it will be very close to going forward then backwards (orientation matters for canceling!) the black segment (inside the rectangle). Using the continuity of $f$, we can make this as small as we want so that in the limit $\int_\alpha f\,dz+\int_r^qf\,dz$ is $0$ and hence $\int_\gamma f\,dz$ is also $0$.
Of course, the triangle doesn't have to be like the one in the image above, this is just meant to give you an idea of how it goes.