Refactoring heading processing code, to eliminate duplicate code and make reuse for PDF bookmark attr possible.