Text this: Data-driven extraction of the substructure of quark and gluon jets in proton-proton and heavy-ion collisions