Example #1
0
  public static SourceBlocks newSourceBlocks(final ICommonmarkConfig config) {
    if (config == null) {
      return newSourceBlocks();
    }

    final List<Class<? extends SourceBlock>> interruptParagraphExclusions;
    if (config.isHeaderInterruptParagraphDisabled()
        || config.isBlockquoteInterruptParagraphDisabled()) {
      interruptParagraphExclusions = new ArrayList<>();
      interruptParagraphExclusions.addAll(ParagraphBlock.DEFAULT_INTERRUPT_EXCLUSIONS);
      if (config.isHeaderInterruptParagraphDisabled()) {
        interruptParagraphExclusions.add(AtxHeaderBlock.class);
      }
      if (config.isBlockquoteInterruptParagraphDisabled()) {
        interruptParagraphExclusions.add(BlockQuoteBlock.class);
      }
    } else {
      interruptParagraphExclusions = ParagraphBlock.DEFAULT_INTERRUPT_EXCLUSIONS;
    }

    return new SourceBlocks(
        new BlockQuoteBlock(),
        new AtxHeaderBlock(),
        new ThematicBreakBlock(),
        new ListBlock(),
        new FencedCodeBlock(),
        new IndentedCodeBlock(),
        new HtmlBlock(),
        new SetextHeaderOrParagraphBlock(interruptParagraphExclusions),
        new EmptyBlock());
  }
Example #2
0
 public static InlineParser newInlineParserCommonMark(final ICommonmarkConfig config) {
   final ArrayList<SourceSpan> spans = new ArrayList<>();
   spans.add(new LineBreakSpan());
   spans.add(new BackslashEscapeSpan());
   spans.add(new CodeSpan());
   spans.add(new AutoLinkSpan());
   spans.add(new HtmlTagSpan());
   spans.add(new HtmlEntitySpan());
   final PotentialStyleSpan styleSpan =
       (config != null)
           ? new PotentialStyleSpan(
               config.isStrikeoutByDTildeEnabled(),
               config.isSuperscriptBySCircumflexEnabled(),
               config.isSubscriptBySTildeEnabled())
           : new PotentialStyleSpan();
   spans.add(styleSpan);
   spans.add(new PotentialBracketSpan());
   spans.add(new StringCharactersSpan(styleSpan.getControlChars()));
   return new InlineParser(ImCollections.toList(spans));
 }