3636import datetime
3737import re
3838from textwrap import dedent
39- from typing import Any , Callable , Dict , Type
39+ from typing import Any , Callable , Dict , List , Tuple , Type
4040
4141import yaml
4242from docutils .parsers .rst import Directive
@@ -54,25 +54,27 @@ def parse_directive_text(
5454 first_line : str ,
5555 content : str ,
5656 validate_options : bool = True ,
57- ):
57+ ) -> Tuple [ List [ str ], dict , List [ str ], int ] :
5858 """Parse (and validate) the full directive text.
5959
6060 :param first_line: The text on the same line as the directive name.
6161 May be an argument or body text, dependent on the directive
6262 :param content: All text after the first line. Can include options.
6363 :param validate_options: Whether to validate the values of options
6464
65+ :returns: (arguments, options, body_lines, content_offset)
6566 """
6667 if directive_class .option_spec :
6768 body , options = parse_directive_options (
6869 content , directive_class , validate = validate_options
6970 )
71+ body_lines = body .splitlines ()
72+ content_offset = len (content .splitlines ()) - len (body_lines )
7073 else :
7174 # If there are no possible options, we do not look for a YAML block
7275 options = {}
73- body = content
74-
75- body_lines = body .splitlines ()
76+ body_lines = content .splitlines ()
77+ content_offset = 0
7678
7779 if not (
7880 directive_class .required_arguments
@@ -91,12 +93,13 @@ def parse_directive_text(
9193 # this is to allow space between the options and the content
9294 if body_lines and not body_lines [0 ].strip ():
9395 body_lines = body_lines [1 :]
96+ content_offset += 1
9497
9598 # check for body content
9699 if body_lines and not directive_class .has_content :
97100 raise DirectiveParsingError ("No content permitted" )
98101
99- return arguments , options , body_lines
102+ return arguments , options , body_lines , content_offset
100103
101104
102105def parse_directive_options (
0 commit comments