unified function for detecting heading tokens