Skip to content

Commit 5fad40e

Browse files
Merge pull request #243 from adamtheturtle/inherit-pdf
Inherit from PDF library
2 parents c8a2111 + 8dbe8f9 commit 5fad40e

File tree

6 files changed

+14
-47
lines changed

6 files changed

+14
-47
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- name: Build sample
3535
run: |
36-
uv run --extra=sample --python=${{ matrix.python-version }} sphinx-build -W -b notion sample/ build-sample/
36+
uv run --python=${{ matrix.python-version }} sphinx-build -W -b notion sample/ build-sample/
3737
3838
- name: Run lint
3939
run: |

.github/workflows/publish-notion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Build documentation
2626
run: |
2727
rm -rf ./build-sample
28-
uv run --extra=sample sphinx-build -W -b notion sample ./build-sample
28+
uv run sphinx-build -W -b notion sample ./build-sample
2929
3030
- name: Publish to Notion
3131
run: |

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ repos:
301301

302302
- id: linkcheck
303303
name: linkcheck
304-
entry: uv run --extra=sample sphinx-build -W -b linkcheck sample build-sample/
304+
entry: uv run sphinx-build -W -b linkcheck sample build-sample/
305305
language: python
306306
types_or: [rst]
307307
stages: [manual]
@@ -310,7 +310,7 @@ repos:
310310

311311
- id: spelling
312312
name: spelling
313-
entry: uv run --extra=sample sphinx-build -W -b spelling sample build-sample/
313+
entry: uv run sphinx-build -W -b spelling sample build-sample/
314314
language: python
315315
types_or: [rst]
316316
stages: [manual]
@@ -319,15 +319,15 @@ repos:
319319

320320
- id: docs
321321
name: Build Documentation
322-
entry: uv run --extra=sample sphinx-build -W -b notion sample build-sample/notion
322+
entry: uv run sphinx-build -W -b notion sample build-sample/notion
323323
language: python
324324
stages: [manual]
325325
pass_filenames: false
326326
additional_dependencies: [uv==0.6.3]
327327

328328
- id: docs-as-html
329329
name: Build Documentation as HTML
330-
entry: uv run --extra=sample sphinx-build -W -b html sample build-sample/html
330+
entry: uv run sphinx-build -W -b html sample build-sample/html
331331
language: python
332332
stages: [manual]
333333
pass_filenames: false

README.rst

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,6 @@ PDF files can be embedded using the ``pdf-include`` directive. Both remote URLs
117117
118118
The PDF will be rendered as an embedded PDF viewer in the generated Notion page.
119119

120-
To make this work in HTML output, you need to install the sphinx-simplepdf extension:
121-
122-
.. code-block:: console
123-
124-
$ pip install sphinx-simplepdf
125-
126-
and add it to your ``conf.py`` file:
127-
128-
.. code-block:: python
129-
130-
"""Configuration for Sphinx."""
131-
132-
extensions = [
133-
"sphinx_simplepdf",
134-
"sphinx_notion",
135-
]
136-
137120
Uploading Documentation to Notion
138121
----------------------------------
139122

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies = [
3636
"click>=8.0.0",
3737
"docutils>=0.21",
3838
"sphinx>=8.2.3",
39+
"sphinx-simplepdf>=1.6.0",
3940
"sphinx-toolbox>=4.0.0",
4041
"sphinxcontrib-video>=0.4.0",
4142
"sphinxnotes-strike>=1.3",
@@ -79,10 +80,6 @@ optional-dependencies.dev = [
7980
"yamlfix==1.18.0",
8081
]
8182
optional-dependencies.release = [ "check-wheel-contents==0.6.3" ]
82-
optional-dependencies.sample = [
83-
# Needed for PDF support in the sample for HTML only.
84-
"sphinx-simplepdf==1.6.0",
85-
]
8683
urls.Source = "https://github.com/adamtheturtle/sphinx-notionbuilder"
8784

8885
scripts.notion-upload = "_notion_scripts.upload:main"

src/sphinx_notion/__init__.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
"""
44

55
import json
6-
from collections.abc import Callable
76
from dataclasses import dataclass
87
from functools import singledispatch
98
from pathlib import Path
10-
from typing import TYPE_CHECKING, Any, ClassVar
9+
from typing import Any
1110

1211
import sphinxnotes.strike
1312
from atsphinx.audioplayer.nodes import ( # pyright: ignore[reportMissingTypeStubs]
@@ -16,11 +15,13 @@
1615
from beartype import beartype
1716
from docutils import nodes
1817
from docutils.nodes import NodeVisitor
19-
from docutils.parsers.rst import Directive, directives
2018
from sphinx.application import Sphinx
2119
from sphinx.builders.text import TextBuilder
2220
from sphinx.util import docutils as sphinx_docutils
2321
from sphinx.util.typing import ExtensionMetadata
22+
from sphinx_simplepdf.directives.pdfinclude import ( # pyright: ignore[reportMissingTypeStubs]
23+
PdfIncludeDirective,
24+
)
2425
from sphinx_toolbox.collapse import CollapseNode
2526
from sphinxcontrib.video import ( # pyright: ignore[reportMissingTypeStubs]
2627
video_node,
@@ -63,9 +64,6 @@
6364
from ultimate_notion.obj_api.enums import BGColor, CodeLang
6465
from ultimate_notion.rich_text import Text, text
6566

66-
if TYPE_CHECKING:
67-
from _typeshed import Incomplete
68-
6967

7068
@beartype
7169
def _serialize_block_with_children(
@@ -87,30 +85,19 @@ def _serialize_block_with_children(
8785

8886

8987
@beartype
90-
class _PdfNode(nodes.Element):
88+
class _PdfNode(nodes.raw): # pylint: disable=too-many-ancestors
9189
"""
9290
Custom PDF node for Notion PDF blocks.
9391
"""
9492

9593

9694
@beartype
97-
class _NotionPdfIncludeDirective(Directive):
95+
class _NotionPdfIncludeDirective(PdfIncludeDirective):
9896
"""
9997
PDF include directive that creates Notion PDF blocks.
10098
"""
10199

102-
has_content = False
103-
required_arguments = 1
104-
optional_arguments = 0
105-
final_argument_whitespace = True
106-
option_spec: ClassVar[dict[str, Callable[[str], "Incomplete"]] | None] = {
107-
"width": directives.length_or_percentage_or_unitless,
108-
"height": directives.length_or_percentage_or_unitless,
109-
"page": directives.positive_int,
110-
"toolbar": directives.nonnegative_int,
111-
}
112-
113-
def run(self) -> list[_PdfNode]:
100+
def run(self) -> list[nodes.raw]:
114101
"""
115102
Create a Notion PDF block.
116103
"""

0 commit comments

Comments
 (0)