I read that stars show both absorption and emission lines. While how we see absorption lines is clear to me, I don't understand how (and when) we see the emission lines. Based on what I read in several of your threads such as Why don't absorption and emission lines cancel out in our Sun? we should not be seeing emission lines at all, since all the emissions would come from the hotter interior but those can't reach the outside (unless I misunderstood this point), and the only emission we see is blackbody radiation. But then how do we see the few emission lines such as in the spectrum shown here?
Light emitted in the interior of a star is largely thermalized by the time it works its way out, and will have a black body spectrum.
The interesting parts of the spectrum is due to molecules and atoms in the corona: the "atmosphere" of the star.
Any gas that is ionized or at least excited to something above the ground state will produce an emission spectrum. Practically all the gas in the first several tens of thousand miles above the star's "surface" will be ionized and emitting light at a high rate, producing emission lines. Consistent with the link you provided, a molecule (or atom) will absorb light only if the light frequency matches an available energy transition in the molecule. If the molecule is already excited above the bottom level of that transition, the transition is not available. However, as long as there is cooler gas at high levels in the stellar atmosphere, there will be absorption lines.
In general, emission lines occur in gases that are optically thin, or in atmospheres that have a temperature inversion (i.e. are hotter closer to the observer).
In an optically thin gas, if excited atoms or ions are radiatively deexcited, then the photons produced can escape to an observer. If continuum absorption/emission is unlikely then this leads to an observed emission line. Examples include most nebulae.
The second case arises because if you have a hot layer on top of a cool layer, then the light we receive from the "photosphere" will come from a hotter layer at the wavelength of a strong radiative transition (closer to the observer) compared with the continuum. As the hotter layer is brighter, we see an emission line. The exact opposite case to the formation of an absorption line, which arises when light at the central wavelength of a transition arises from a higher, cooler layer.
A temperature inversion requires a way of non-radiatively depositing heat in the hotter layer, otherwise radiative diffusion would eliminate it. An example is a stellar chromosphere, which is above and hotter than the photosphere, and heated by magnetic fields. This can produce high temperature emission lines. However, the chromosphere is (a) patchy and (b) thin enough to allow light of most wavelengths through it, so we still view the solar photosphere with its absorption lines, but with the addition of emission lines from the hotter chromosphere.