8000 Sphinx - docutils by AA-Turner · Pull Request #1931 · python/peps · GitHub
[go: up one dir, main page]

Skip to content
8000

Sphinx - docutils #1931

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

Merged
merged 15 commits into from
Jun 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add PEPParser document parser
  • Loading branch information
AA-Turner committed Jun 8, 2021
commit 0f5d44afc356fa94d664f87c5769c8aaf4b984ac
32 changes: 32 additions & 0 deletions pep_sphinx_extensions/pep_processor/parsing/pep_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from sphinx import parsers

from pep_sphinx_extensions.pep_processor.transforms import pep_headers
from pep_sphinx_extensions.pep_processor.transforms import pep_title
from pep_sphinx_extensions.pep_processor.transforms import pep_contents
from pep_sphinx_extensions.pep_processor.transforms import pep_footer

if TYPE_CHECKING:
from docutils import transforms


class PEPParser(parsers.RSTParser):
"""RST parser with custom PEP transforms."""

supported = ("pep", "python-enhancement-proposal") # for source_suffix in conf.py

def __init__(self):
"""Mark the document as containing RFC 2822 headers."""
super().__init__(rfc2822=True)

def get_transforms(self) -> list[type[transforms.Transform]]:
"""Use our custom PEP transform rules."""
return [
pep_headers.PEPHeaders,
pep_title.PEPTitle,
pep_contents.PEPContents,
pep_footer.PEPFooter,
]
0