A \label on the line after \section without a blank line was discarded with the
rest of the text after the heading's closing brace, so \ref printed "??".
heading_command now keeps any immediately following \label groups (allowing
whitespace/newlines) in the heading text, which lets the numbering pass attach
them to that heading; other trailing text is still ignored as before.
A preview test puts \label{sec:intro} directly under \section{Introduction},
refers to it, and checks "See 1." with no warnings and no "??".