/// <summary> /// Process on a new <see cref="HeadingBlock"/> /// </summary> /// <param name="processor">The processor.</param> /// <param name="block">The heading block.</param> private void HeadingBlockParser_Closed(BlockProcessor processor, Block block) { // We may have a ParagraphBlock here as we have a hook on the ParagraphBlockParser var headingBlock = block as HeadingBlock; if (headingBlock == null) { return; } // If the AutoLink options is set, we register a LinkReferenceDefinition at the document level if ((options & AutoIdentifierOptions.AutoLink) != 0) { var headingLine = headingBlock.Lines.Lines[0]; var text = headingLine.ToString(); var linkRef = new HeadingLinkReferenceDefinition() { Heading = headingBlock, CreateLinkInline = CreateLinkInlineForHeading }; processor.Document.SetLinkReferenceDefinition(text, linkRef); } // Then we register after inline have been processed to actually generate the proper #id headingBlock.ProcessInlinesEnd += HeadingBlock_ProcessInlinesEnd; }
/// <summary> /// Process on a new <see cref="HeadingBlock"/> /// </summary> /// <param name="processor">The processor.</param> /// <param name="block">The heading block.</param> private void HeadingBlockParser_Closed(BlockProcessor processor, Block block) { // We may have a ParagraphBlock here as we have a hook on the ParagraphBlockParser if (!(block is HeadingBlock headingBlock)) { return; } // If the AutoLink options is set, we register a LinkReferenceDefinition at the document level if ((options & AutoIdentifierOptions.AutoLink) != 0) { var headingLine = headingBlock.Lines.Lines[0]; var text = headingLine.ToString(); var linkRef = new HeadingLinkReferenceDefinition(headingBlock) { CreateLinkInline = CreateLinkInlineForHeading }; var doc = processor.Document; var dictionary = doc.GetData(this) as Dictionary <string, HeadingLinkReferenceDefinition>; if (dictionary is null) { dictionary = new Dictionary <string, HeadingLinkReferenceDefinition>(); doc.SetData(this, dictionary); doc.ProcessInlinesBegin += DocumentOnProcessInlinesBegin; } dictionary[text] = linkRef; } // Then we register after inline have been processed to actually generate the proper #id headingBlock.ProcessInlinesEnd += HeadingBlock_ProcessInlinesEnd; }