@Test public void process() { assertContent("<h2 id=\"heading-text\">Heading Text</h2>", "Heading Text\n-------"); assertContent("<h1 id=\"heading-text\">Heading Text</h1>", "Heading Text\n="); assertContent("<h1 id=\"heading-text\">Heading Text</h1>", "Heading Text\n===="); assertContent("<h1 id=\"heading-text\">Heading <em>Text</em></h1>", "Heading *Text*\n===="); }
@Override public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) { Line currentLine = lineSequence.getCurrentLine(); Line nextLine = lineSequence.getNextLine(); Matcher matcher = setextUnderlinePattern.matcher(nextLine.getText()); checkState(matcher.matches()); lineSequence.advance(); builder.setLocator(currentLine.toLocator()); int headingLevel = headingLevel(matcher); TextSegment textSegment = new TextSegment(Collections.singletonList(currentLine)); HeadingAttributes attributes = new HeadingAttributes(); InlineParser inlineParser = context.getInlineParser(); String headingText = inlineParser.toStringContent(context, textSegment); attributes.setId(context.generateHeadingId(headingLevel, headingText)); builder.beginHeading(headingLevel, attributes); inlineParser.emit(context, builder, textSegment); builder.endHeading(); lineSequence.advance(); }
SetextHeaderBlock extends SourceBlock { @Override public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) { Line currentLine = lineSequence.getCurrentLine(); Line nextLine = lineSequence.getNextLine(); Matcher matcher = setextUnderlinePattern.matcher(nextLine.getText()); checkState(matcher.matches()); lineSequence.advance(); builder.setLocator(currentLine.toLocator()); int headingLevel = headingLevel(matcher); TextSegment textSegment = new TextSegment(Collections.singletonList(currentLine)); HeadingAttributes attributes = new HeadingAttributes(); InlineParser inlineParser = context.getInlineParser(); String headingText = inlineParser.toStringContent(context, textSegment); attributes.setId(context.generateHeadingId(headingLevel, headingText)); builder.beginHeading(headingLevel, attributes); inlineParser.emit(context, builder, textSegment); builder.endHeading(); lineSequence.advance(); } }
SetextHeaderBlock extends SourceBlock { @Override public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) { Line currentLine = lineSequence.getCurrentLine(); Line nextLine = lineSequence.getNextLine(); Matcher matcher = setextUnderlinePattern.matcher(nextLine.getText()); checkState(matcher.matches()); lineSequence.advance(); builder.setLocator(currentLine.toLocator()); int headingLevel = headingLevel(matcher); TextSegment textSegment = new TextSegment(Collections.singletonList(currentLine)); HeadingAttributes attributes = new HeadingAttributes(); InlineParser inlineParser = context.getInlineParser(); String headingText = inlineParser.toStringContent(context, textSegment); attributes.setId(context.generateHeadingId(headingLevel, headingText)); builder.beginHeading(headingLevel, attributes); inlineParser.emit(context, builder, textSegment); builder.endHeading(); lineSequence.advance(); }  }
SetextHeaderBlock extends SourceBlock { @Override public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) { Line currentLine = lineSequence.getCurrentLine(); Line nextLine = lineSequence.getNextLine(); Matcher matcher = setextUnderlinePattern.matcher(nextLine.getText()); checkState(matcher.matches()); lineSequence.advance(); builder.setLocator(currentLine.toLocator()); int headingLevel = headingLevel(matcher); TextSegment textSegment = new TextSegment(Collections.singletonList(currentLine)); HeadingAttributes attributes = new HeadingAttributes(); InlineParser inlineParser = context.getInlineParser(); String headingText = inlineParser.toStringContent(context, textSegment); attributes.setId(context.generateHeadingId(headingLevel, headingText)); builder.beginHeading(headingLevel, attributes); inlineParser.emit(context, builder, textSegment); builder.endHeading(); lineSequence.advance(); }  @Override void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence); @Override boolean canStart(LineSequence lineSequence); }
SetextHeaderBlock extends SourceBlock { @Override public void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence) { Line currentLine = lineSequence.getCurrentLine(); Line nextLine = lineSequence.getNextLine(); Matcher matcher = setextUnderlinePattern.matcher(nextLine.getText()); checkState(matcher.matches()); lineSequence.advance(); builder.setLocator(currentLine.toLocator()); int headingLevel = headingLevel(matcher); TextSegment textSegment = new TextSegment(Collections.singletonList(currentLine)); HeadingAttributes attributes = new HeadingAttributes(); InlineParser inlineParser = context.getInlineParser(); String headingText = inlineParser.toStringContent(context, textSegment); attributes.setId(context.generateHeadingId(headingLevel, headingText)); builder.beginHeading(headingLevel, attributes); inlineParser.emit(context, builder, textSegment); builder.endHeading(); lineSequence.advance(); }  @Override void process(ProcessingContext context, DocumentBuilder builder, LineSequence lineSequence); @Override boolean canStart(LineSequence lineSequence);  }