Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let the comment header as raw text or literal block #45

Open
ndarmage opened this issue Jun 22, 2022 · 1 comment
Open

Let the comment header as raw text or literal block #45

ndarmage opened this issue Jun 22, 2022 · 1 comment

Comments

@ndarmage
Copy link

Hello,

Is it possible to leave the comment header of fortran blocks as raw text without interpreting it as ReST please ?
A possible fix is adding the following lines,

if len(block['desc']) and raw_desc > 0:
    block['desc'] = ["! .. code-block::\n"] + block['desc']

right after,

# Comment
 block['desc'] = self.get_comment(subsrc, aslist=True)

in the function scan_container of file fortran_autodoc.f90. The new variable raw_desc should be True if such option was selected when processing the fortran blocks.

Or perhaps, is there another way of achiving this behavior?

Thanks in advance for your kind attention.

@quocdang1998
Copy link

In the definition of F90toRst.scan_container, you can add these following lines:

        # Comment
        block['desc'] = self.get_comment(subsrc, aslist=True)
        indent = ''
        in_codeblock = False
        i = 0
        while i < len(block['desc']):
            line = block['desc'][i]
            if not in_codeblock:
                if line.startswith(' '):   # get current indent
                    indent = re.split(r'[^\s]', line)[0]
                if line == '*':  # code-block starts with !*
                    in_codeblock = True
                    block['desc'][i] = indent + '.. code-block::'
                    block['desc'].insert(i, '')  # insert empty line before directive
                    i += 2
                    block['desc'].insert(i, '')  # insert empty line after directive
            else:
                if line == '*':  # code-block ends with !*
                    in_codeblock = False
                    block['desc'][i] = ''
                    continue
                block['desc'][i] = indent + '   ' + line
            i += 1

Please note that a code-block directive will start and end with !*. Here's a MWE:

!*
!      11 22 33 44 55 66 77 88 99
!      21 32 43 54 65 76 87 98  *
!      31 42 53 64 75 86 97  *  *
!      41 52 63 74 85 96  *  *  *
!*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants