The continuous spectrum of the visible photosphere of the Sun is attributable to the radiative equilibrium of the $\mathrm{H}^{-}$ ion. This has been recognised for at least 80 years (Wildt 1939).
This ion forms by the attachment of a free electron (with a continuous spectrum of energies) to a hydrogen atom, emitting a continuous spectrum of photons in the process. The reverse process, photo-detachment, occurs at the same rate and is the principal source of continuum opacity in the solar photosphere.
Absorption and emission by H$^{-}$ ions demands that the temperature is low enough not to dissociate the extra electron ($<10^{4}$K), but high enough that there is a supply of free electrons donated by the ionisation of alkali metals ($\gtrsim 2500$K) such as sodium and potassium.
Superimposed on this continuum are dark, discrete absorption features caused by transitions within atomic species (mainly metals, but also hydrogen). These are dark because the photons at these frequencies arrive here from higher up in the atmosphere at cooler temperatures.
The original question asks only about "sunlight", and the H$^{-}$ opacity mechanism is only effective between about 2,500-10,000K. Stars with photospheres with temperatures above 10,000K or below about 3,000K are dominated by different opacity and hence emission mechanisms.
In hotter stars the primary sources of continuous opacity at visible wavelengths, at temperatures exceeding 10,000K, are scattering by free electrons and the Paschen continuum arising from transitions between the $n=3$ state in hydrogen atoms and ionised hydrogen. There are also smaller contributions from free-free transitions of electrons in the electric fields of ions (bremsstrahlung).
There can of course be a cooler, overlying layer in hot stars where H$^{-}$ can form, but it has a lower density and a small optical depth (i.e. photons travel through it) and it therefore does not contribute significantly to the photospheric continuum.
In very cool photospheres, there are few free electrons and the atoms begin to form molecules, like carbon monoxide, water, molecular hydrogen, titanium oxide, vanadium oxide etc. There is actually very little true continuum absorption/emission in the visible part of the spectrum of these stars. Instead there is an overlapping mess of rotational and vibrational molecular transitions that form a pseudo-continuum when observed by instruments with finite spectral resolution. The dominant opacity in the visible spectrum at just below 3000K is due to TiO molecules.
At even lower temperatures (below 2500K, and approaching the substellar regime), absorption and emission by dust becomes important, although there is negligible flux at visible wavelengths.