Skip to content

Commit e20f753

Browse files
authored
Skipping code blocks and fixing docs build. (#47)
While working on another PR I ran into this bug on my test website. I had a test document with only an HTML code block and found out unescaped HTML was added to the meta tag: ```html <meta property="og:description" content="<meta property="og:image" content="_images/normal.jpg" /> <img alt="_images/normal.jpg" src="_images/normal.jpg" />" /> <meta property="og:image" content="_images/normal.jpg" /> ``` Fixing this by skipping literal blocks. Also fixed docs build. I was getting the exception: `AttributeError: 'Values' object has no attribute 'section_self_link'` This was caused by sphinx-doc/sphinx#9825. Updating dependencies fixed the issue.
1 parent 16a291d commit e20f753

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

docs/requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
myst-parser==0.13.0
2-
furo==2020.12.30b24
3-
sphinx==3.4.0
1+
myst-parser==0.15.2
2+
furo==2021.11.12.1
3+
sphinx==4.2.0
44
./

sphinxext/opengraph/descriptionparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def dispatch_visit(self, node: nodes.Element) -> None:
6767
if node.astext() in self.known_titles:
6868
raise nodes.SkipNode
6969

70-
if isinstance(node, nodes.raw):
70+
if isinstance(node, nodes.raw) or isinstance(node.parent, nodes.literal_block):
7171
raise nodes.SkipNode
7272

7373
# Only include leaf nodes in the description
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extensions = ["sphinxext.opengraph"]
2+
3+
master_doc = "index"
4+
exclude_patterns = ["_build"]
5+
6+
html_theme = "basic"
7+
8+
ogp_site_url = "http://example.org/"
9+
ogp_description_length = 100
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This text should be included.
2+
3+
.. code-block:: html
4+
5+
<p> This text should be skipped. </p>
6+
7+
This text should also be included.

tests/test_options.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ def test_skip_raw(og_meta_tags):
127127
)
128128

129129

130+
@pytest.mark.sphinx("html", testroot="skip-code-block")
131+
def test_skip_code_block(og_meta_tags):
132+
description = get_tag_content(og_meta_tags, "description")
133+
assert "<p>" not in description
134+
assert (
135+
description
136+
== "This text should be included. This text should also be included."
137+
)
138+
139+
130140
# use same as simple, as configuration is identical to overriden
131141
@pytest.mark.sphinx("html", testroot="simple")
132142
def test_rtd_override(app: Sphinx, monkeypatch):

0 commit comments

Comments
 (0)