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

Ignore markup errors in comments #35

Open
ezio-melotti opened this issue Jun 10, 2022 · 5 comments
Open

Ignore markup errors in comments #35

ezio-melotti opened this issue Jun 10, 2022 · 5 comments

Comments

@ezio-melotti
Copy link
Collaborator

I ran sphinx-lint against a project that includes the following in the index.rst:

.. <project name> documentation master file, created by
   sphinx-quickstart on Sat Aug 28 22:34:16 2021.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Since I was using the --enable default-role option, I got the following error, even though the markup appears in a comment:

index.rst:4: default role used (hint: for inline literals, use double backticks) (default-role)

Should sphinx-lint ignore markup errors in a comment?

@AA-Turner
Copy link
Member

Perhaps a flag to ignore comments? Sometimes when writing documentation I comment things out that I want to return to later. However that is a niche use-case---Ezio's example is probably more common where people don't care about the markup in comments.

A

@hugovk
Copy link
Collaborator

hugovk commented Jun 10, 2022

I would ignore markup in comments, just as (I assume) Sphinx also does.

Similar to #34, where we want to ignore markup inside code blocks.

@ezio-melotti
Copy link
Collaborator Author

ezio-melotti commented Jun 10, 2022

As far as I know sphinx-lint works line by line, without parsing the markup (it only uses regexes), so this might be tricky to implement unless we change it to handle more context.

@AA-Turner
Copy link
Member

AA-Turner commented Jun 10, 2022

Docutils (and hence also Sphinx) just includes the text verbatim in a comment node:

(docutils) S:\Development\docutils>type comment-test.rst
.. This is a reStructuredText comment with :pep`42`` misformed markup.

(docutils) S:\Development\docutils>docutils --writer pseudoxml comment-test.rst
<document source="comment-test.rst">
    <comment xml:space="preserve">
        This is a reStructuredText comment with :pep`42`` misformed markup.

A

@AA-Turner
Copy link
Member

There is a check for comments, but only on the same line -- the in_literal state logic could be expanded to comments?

sphinx-lint/sphinxlint.py

Lines 511 to 512 in b377556

elif re.match(r" *\.\. ", line) and type_of_explicit_markup(line) == "comment":
line = "\n"

A

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

3 participants