private static void anchorToId ( Element heading , Element anchor ) { if ( "a" . equals ( anchor . tagName ( ) ) && heading . id ( ) . isEmpty ( ) ) { String aName = anchor . attr ( "name" ) ; if ( ! aName . isEmpty ( ) ) { // set the anchor name as heading ID heading . attr ( "id" , aName ) ; // remove the anchor anchor . remove ( ) ; } } }
Moves anchor name to heading id if one does not exist . Removes the anchor .