diff --git a/README.md b/README.md
index 14f677b..59d0602 100644
--- a/README.md
+++ b/README.md
@@ -164,6 +164,10 @@ Currently supported options are listed below:
Whether the caption should be on the top of the element.
+* `id_caption`:
+
+ Add an id to the element.
+
The default values for each type of content is synthesised in the following table:
| Config | Image | Table | Other |
@@ -174,6 +178,7 @@ The default values for each type of content is synthesised in the following tabl
| `caption_class` | - | - | - |
| `caption_prefix_class` | - | - | - |
| `caption_top` | False | True | True |
+| `caption_id` | True | True | True |
## Why?
diff --git a/caption/caption.py b/caption/caption.py
index 8d5f495..c21ce20 100644
--- a/caption/caption.py
+++ b/caption/caption.py
@@ -34,6 +34,7 @@ def __init__(
content_class=None,
link_process=None,
caption_top=True,
+ caption_id=True,
):
self.caption_prefix = caption_prefix
self.numbering = numbering
@@ -43,6 +44,7 @@ def __init__(
self.content_class = content_class
self.link_process = link_process
self.caption_top = caption_top
+ self.caption_id = caption_id
def build_content_element(self, par, caption, replace=True):
"""Format the content element containing the caption"""
@@ -54,7 +56,8 @@ def build_content_element(self, par, caption, replace=True):
par.set(k, v)
if self.content_class:
par.set("class", self.content_class)
- par.set("id", "_{}-{}".format(self.name, self.number))
+ if self.caption_id:
+ par.set("id", "_{}-{}".format(self.name, self.number))
if replace:
par.text = "\n"
par.tail = "\n"
@@ -144,6 +147,7 @@ def __init__(self, **kwargs):
"content_class": ["", "CSS class to add to the content element."],
"link_process": ["", "Some content types support linked processes."],
"caption_top": [False, "Put the caption at the top of the content."],
+ "caption_id": [True, "Add an id to the element."],
}
super(CaptionExtension, self).__init__(**kwargs)
diff --git a/caption/image_caption.py b/caption/image_caption.py
index 52d48d5..762b995 100644
--- a/caption/image_caption.py
+++ b/caption/image_caption.py
@@ -11,6 +11,7 @@
SPDX-License-Identifier: GPL-3.0-or-later
"""
+
from markdown import Extension
from .caption import CaptionTreeprocessor
@@ -30,6 +31,7 @@ def __init__(
content_class=None,
strip_title=True,
caption_top=False,
+ caption_id=True,
):
super(ImageCaptionTreeProcessor, self).__init__(
md=md,
@@ -39,6 +41,7 @@ def __init__(
caption_class=caption_class,
content_class=content_class,
caption_top=caption_top,
+ caption_id=caption_id,
)
self.strip_title = strip_title
@@ -90,6 +93,7 @@ def __init__(self, **kwargs):
"content_class": ["", "CSS class to add to the content element."],
"strip_title": [True, "Remove the title from the img tag."],
"caption_top": [False, "Put the caption at the top of the image."],
+ "caption_id": [True, "Add an id to the element."],
}
super(ImageCaptionExtension, self).__init__(**kwargs)
diff --git a/caption/table_caption.py b/caption/table_caption.py
index a8c87fe..e509bf7 100644
--- a/caption/table_caption.py
+++ b/caption/table_caption.py
@@ -64,6 +64,7 @@ def __init__(self, **kwargs):
"caption_class": ["", "CSS class to add to the caption element."],
"content_class": ["", "CSS class to add to the content element."],
"caption_top": [True, "Put the caption at the top of the table."],
+ "caption_id": [True, "Add an id to the element."],
}
super(TableCaptionExtension, self).__init__(**kwargs)
diff --git a/test/test_image_caption.py b/test/test_image_caption.py
index b6eb520..b7af3c0 100644
--- a/test/test_image_caption.py
+++ b/test/test_image_caption.py
@@ -185,7 +185,6 @@ def test_caption_prefix_class():
)
assert out_string == expected_string
-
def test_caption_prefix():
in_string = """\
"""
@@ -248,3 +247,31 @@ def test_combined_options():
],
)
assert out_string == expected_string
+
+def test_caption_id_false():
+ in_string = """\
+"""
+ expected_string = """\
+
+
+