@ SuppressWarnings ( "static-method" ) protected ReferenceContext extractReferencableElements ( String text ) { final ReferenceContext context = new ReferenceContext ( ) ; // Visit the links and record the transformations final MutableDataSet options = new MutableDataSet ( ) ; final Parser parser = Parser . builder ( options ) . build ( ) ; final Node document = parser . parse ( text ) ; final Pattern pattern = Pattern . compile ( SECTION_PATTERN_AUTONUMBERING ) ; NodeVisitor visitor = new NodeVisitor ( new VisitHandler <> ( Paragraph . class , it -> { final Matcher matcher = pattern . matcher ( it . getContentChars ( ) ) ; if ( matcher . find ( ) ) { final String number = matcher . group ( 2 ) ; final String title = matcher . group ( 3 ) ; final String key1 = computeHeaderId ( number , title ) ; final String key2 = computeHeaderId ( null , title ) ; context . registerSection ( key1 , key2 , title ) ; } } ) ) ; visitor . visitChildren ( document ) ; visitor = new NodeVisitor ( new VisitHandler <> ( Heading . class , it -> { String key = it . getAnchorRefId ( ) ; final String title = it . getAnchorRefText ( ) ; final String key2 = computeHeaderId ( null , title ) ; if ( Strings . isEmpty ( key ) ) { key = key2 ; } context . registerSection ( key , key2 , title ) ; } ) ) ; visitor . visitChildren ( document ) ; return context ; }
Extract all the referencable objects from the given content .