Cosmic-ray positrons are a powerful probe of astrophysical processes and properties of the Galaxy. While the local cosmic-ray positron flux at low energies is dominated by positrons produced as secondaries in interactions in the interstellar medium, the positron fraction unexpectedly rises at energies above about 20 GeV. The most prominent explanation for this is a contribution from nearby pulsars that produce electron-positron pairs as they spin down. In this work, this contribution of pulsars to the positron flux is investigated by creating models of the positron spectra produced by individual pulsars that precisely take into account the energy losses that positrons experience while propagating through the Galaxy. Another contribution to the positron flux could come from dark matter particles that annihilate into electron-positron final states and can produce spiky spectral features at the dark matter mass in the positron flux. Here, the high-precision AMS-02 data is used to derive strong constraints on leptophilic dark matter models.