flexmark-java icon indicating copy to clipboard operation
flexmark-java copied to clipboard

flexmark-ext-toc SimTocExtension ignores TITLE_LEVEL > 1 (patch included)

Open maassg opened this issue 4 years ago • 0 comments

Version flexmark-all-0.62.2

SimTocExtension ignores TITLE_LEVEL > 1 like this: [TOC levels=3-5]: ### "A Title"

Title level > 1 can only be set via Parser option, e.g.: options.set( SimTocExtension.TITLE_LEVEL, 3 );

In my opinion the following 2 classes are responsible for this bug:

  • com.vladsch.flexmark.ext.toc.internal.SimTocBlockParser
  • com.vladsch.flexmark.ext.toc.SimTocBlock

The corrected versions can be found in the appendix.

The changes are as follows:

  • com.vladsch.flexmark.ext.toc.internal.SimTocBlockParser
    class TocParsing: changed Pattern from  ...#(... to  ...#+(...
    changed constructor to:
    SimTocBlockParser( MutableDataHolder options, ... ) {
       block = new SimTocBlock(tocChars, styleChars, titleChars);
       options.set( SimTocExtension.TITLE_LEVEL, block.getTitleLevel() );
       this.options = new TocOptions( options, true );
    } 
    
  • com.vladsch.flexmark.ext.toc.SimTocBlock
    changed constructor to:
    public SimTocBlock(BasedSequence chars, BasedSequence styleChars, BasedSequence titleChars) {
       ...
       // anchorMarker = chars.subSequence(anchorPos, anchorPos + 1);
       int anchorEndPos = anchorPos+1;
       for( ; chars.charAt(anchorEndPos) == '#'; anchorEndPos++ );
       if( anchorEndPos - anchorPos > 6 ) {
          throw new IllegalStateException( "Invalid TOC block sequence: " + chars.subSequence( anchorPos) );
       }
       anchorMarker = chars.subSequence( anchorPos, anchorEndPos );
       ...
    }
    added method:
    public int getTitleLevel() {
        return anchorMarker.length();
    }
    

flexmark-ext-toc-0.62.3.zip

maassg avatar Sep 02 '21 11:09 maassg