Sunlight can be treated as BB radiation. Why is it a continuous spectrum while the sun contains only a few elements and the radiation from the jumps between atomic levels are discrete? How does the photon gas achieve thermal equilibrium while they do not interact with themselves?
Maybe the simplest way to think about this is that the Sun is in approximate thermal equilibrium and would absorb any photon, of any frequency, that is incident upon it. This is essentially the definition of a BB.
There are many radiative processes that can absorb (and hence emit) radiation at all frequencies, not just those corresponding to atomic transitions. For example there is free-free and bound-free opacity associated with negative H ions in the solar photosphere.
Of course not all frequencies are absorbed equally - that is why the solar spectrum is not a BB at a single temperature. At each frequency you see to a different depth (and hence temperature) meaning that the radiation field at any frequency corresponds roughly to that of a blackbody at a temperature where the optical depth reaches $\sim 1$ (or 2/3 in more exact treatments). In a strong absorption line, the photons that finally escape the Sun come from higher up and at cooler temperatures and hence are not as bright as other frequencies, with lower opacities, that arise in deeper, hotter layers.
Black body radiation is given by Planck's formula
(see link for variables)
Here is the measured irradiance of the sun and the attempt to fit it with the black body formula:
The effective temperature, or black body temperature, of the Sun (5,777 K) is the temperature a black body of the same size must have to yield the same total emissive power.
The visible surface of the Sun, the photosphere, is the layer below which the Sun becomes opaque to visible light. Above the photosphere visible sunlight is free to propagate into space, and its energy escapes the Sun entirely. The change in opacity is due to the decreasing amount of H− ions, which absorb visible light easily.Conversely, the visible light we see is produced as electrons react with hydrogen atoms to produce H− ions. The photosphere is tens to hundreds of kilometers thick, being slightly less opaque than air on Earth. Because the upper part of the photosphere is cooler than the lower part, an image of the Sun appears brighter in the center than on the edge or limb of the solar disk, in a phenomenon known as limb darkening. The spectrum of sunlight has approximately the spectrum of a black-body radiating at about 6,000 K, interspersed with atomic absorption lines from the tenuous layers above the photosphere.
The continuum in the spectrum comes because at that high temperature the ions and electrons interact with the fields of each other and the magnetic field of the sun, accelerating/decelerating charges radiate in the continuum.