1818import com .vladsch .flexmark .util .misc .CharPredicate ;
1919import com .vladsch .flexmark .util .sequence .BasedSequence ;
2020import com .vladsch .flexmark .util .sequence .PrefixedSubSequence ;
21+ import io .opentelemetry .instrumentation .annotations .WithSpan ;
2122import org .jetbrains .annotations .NotNull ;
2223
2324import java .io .BufferedReader ;
@@ -271,16 +272,23 @@ public InlineParser getInlineParser() {
271272 */
272273 public Document parse (CharSequence source ) {
273274 BasedSequence input = BasedSequence .of (source );
274- int lineStart = 0 ;
275- int lineBreak ;
276- int lineEOL ;
277- int lineEnd ;
278275 lineNumber = 0 ;
279276
280277 documentBlockParser .initializeDocument (options , input );
281278 inlineParser .initializeDocument (documentBlockParser .getBlock ());
282279
283280 currentPhase = ParserPhase .PARSE_BLOCKS ;
281+ parseBlocks (input );
282+
283+ return finalizeAndProcess ();
284+ }
285+
286+ @ WithSpan ("markdown.parse.blocks" )
287+ private void parseBlocks (BasedSequence input ) {
288+ int lineStart = 0 ;
289+ int lineBreak ;
290+ int lineEOL ;
291+ int lineEnd ;
284292
285293 while ((lineBreak = Parsing .findLineBreak (input , lineStart )) != -1 ) {
286294 BasedSequence line = input .subSequence (lineStart , lineBreak );
@@ -308,8 +316,6 @@ public Document parse(CharSequence source) {
308316 incorporateLine (lineWithEOL );
309317 lineNumber ++;
310318 }
311-
312- return finalizeAndProcess ();
313319 }
314320
315321 public Document parse (Reader input ) throws IOException {
@@ -745,6 +751,7 @@ private void finalize(BlockParser blockParser) {
745751 /**
746752 * Walk through a block & children recursively, parsing string content into inline content where appropriate.
747753 */
754+ @ WithSpan ("markdown.parse.inlines" )
748755 private void processInlines () {
749756 for (BlockParser blockParser : blockTracker .allBlockParsers ()) {
750757 blockParser .parseInlines (inlineParser );
@@ -938,6 +945,7 @@ private void preProcessParagraph(Paragraph block, List<ParagraphPreProcessorFact
938945 }
939946 }
940947
948+ @ WithSpan ("markdown.parse.pre_process_paragraphs" )
941949 private void preProcessParagraphs () {
942950 // here we run preProcessing stages
943951 if (blockTracker .getNodeClassifier ().containsCategory (Paragraph .class )) {
@@ -951,6 +959,7 @@ private void preProcessParagraphs() {
951959 }
952960 }
953961
962+ @ WithSpan ("markdown.parse.pre_process_blocks" )
954963 private void preProcessBlocks () {
955964 // here we run preProcessing stages
956965 HashSet <Class <?>> blockTypes = new HashSet <>();
0 commit comments