Skip to content

Commit a075a87

Browse files
authored
Skip comments in dom tree traversal (#9)
1 parent 89fba45 commit a075a87

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

sphinxext/opengraph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def dispatch_visit(self, node: nodes.Element) -> None:
6666
if self.stop:
6767
raise nodes.StopTraversal
6868

69+
# Skip comments
70+
if isinstance(node, nodes.Invisible):
71+
raise nodes.SkipNode
72+
6973
# Skip all admonitions
7074
if isinstance(node, nodes.Admonition):
7175
raise nodes.SkipNode
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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/"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. This is a comment.
2+
This is still a comment.
3+
4+
This is text.

tests/test_options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,9 @@ def test_list_punctuation(og_meta_tags):
8080
def test_nested_list_punctuation(og_meta_tags):
8181
description = get_tag_content(og_meta_tags, "description")
8282
assert description == "Item 1, Item 2- Nested Item 1, Nested Item 2., Item 3, Item 4."
83+
84+
85+
@pytest.mark.sphinx("html", testroot="skip-comments")
86+
def test_skip_comments(og_meta_tags):
87+
assert get_tag_content(og_meta_tags, "description") == "This is text."
88+

0 commit comments

Comments
 (0)