Skip to content

Commit 20a2073

Browse files
authored
Merge pull request #1099 from sphinx-contrib/limited-inline-comment-check
initial/limited inlined comment check support
2 parents 34fcafd + 8991d63 commit 20a2073

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

doc/configuration.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,6 +1795,29 @@ Advanced publishing configuration
17951795

17961796
.. versionadded:: 2.10
17971797

1798+
.. confval:: confluence_publish_skip_commented_pages
1799+
1800+
.. note::
1801+
1802+
There is no support to keep inlined comments on updated pages at
1803+
this time.
1804+
1805+
Indicates to skip updates on pages which have inlined comments. Before
1806+
a page update is issued, a warning will be generated if this extension
1807+
detects that a page has inlined comments added to it. Page updates
1808+
remove any inlined comments embedded in the page source. If a users
1809+
wants to prevent any updates on pages to prevent the loss of inlined
1810+
comments, they can configure this option to ``True``. By default, pages
1811+
will always be updated with a value of ``False``.
1812+
1813+
.. code-block:: python
1814+
1815+
confluence_publish_skip_commented_pages = True
1816+
1817+
See also :lref:`suppress_warnings_config`.
1818+
1819+
.. versionadded:: 2.13
1820+
17981821
.. confval:: confluence_request_session_override
17991822

18001823
A hook to manipulate a Requests_ session prepared by this extension. Allows
@@ -2294,6 +2317,8 @@ Third-party related options
22942317
Other options
22952318
-------------
22962319

2320+
.. _suppress_warnings_config:
2321+
22972322
.. confval:: suppress_warnings
22982323

22992324
This extension supports suppressing warnings using Sphinx's
@@ -2303,8 +2328,17 @@ Other options
23032328
- ``confluence`` -- All warnings
23042329
- ``confluence.deprecated`` -- Configuration deprecated warnings
23052330
- ``confluence.deprecated_develop`` -- Development deprecated warnings
2331+
- ``confluence.inline-comment`` -- Inlined comment warnings
23062332
- ``confluence.unsupported_code_lang`` -- Unsupported code language
23072333

2334+
For example:
2335+
2336+
.. code-block:: python
2337+
2338+
suppress_warnings = [
2339+
'confluence.unsupported_code_lang',
2340+
]
2341+
23082342
.. versionadded:: 2.1
23092343

23102344
Deprecated options

sphinxcontrib/confluencebuilder/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ def setup(app):
218218
cm.add_conf('confluence_publish_retry_attempts')
219219
# Duration (in seconds) between retrying failed API requests
220220
cm.add_conf('confluence_publish_retry_duration')
221+
# Whether to skip page updates for pages that have inlined comments
222+
cm.add_conf_bool('confluence_publish_skip_commented_pages')
221223
# Manipulate a requests instance.
222224
cm.add_conf('confluence_request_session_override')
223225
# Authentication passthrough for Confluence REST interaction.

sphinxcontrib/confluencebuilder/publisher.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,13 @@ def store_page(self, page_name, data, parent_id=None):
10411041
logger.verbose(f'no changes in page: {page_name}')
10421042
return page['id']
10431043

1044+
# check for inlined comments
1045+
if page:
1046+
icdrop = self._manage_inlined_comments(page, page_name, data)
1047+
if icdrop and self.config.confluence_publish_skip_commented_pages:
1048+
logger.verbose(f'skipping publish due to comments: {page_name}')
1049+
return page['id']
1050+
10441051
try:
10451052
# new page
10461053
if not page:
@@ -1222,6 +1229,13 @@ def store_page_by_id(self, page_name, page_id, data):
12221229
logger.verbose(f'no changes in page: {page_name}')
12231230
return page_id
12241231

1232+
# check for inlined comments
1233+
if page:
1234+
icdrop = self._manage_inlined_comments(page, page_name, data)
1235+
if icdrop and self.config.confluence_publish_skip_commented_pages:
1236+
logger.verbose(f'skipping publish due to comments: {page_name}')
1237+
return page_id
1238+
12251239
try:
12261240
self._update_page(page, page_name, data)
12271241
except ConfluencePermissionError as ex:
@@ -1498,6 +1512,40 @@ def _build_page(self, page_name, data):
14981512

14991513
return page
15001514

1515+
def _manage_inlined_comments(self, page, page_name, data):
1516+
"""
1517+
manage inlined comments for a page update
1518+
1519+
This call will attempt to manage a page update event where the
1520+
original page (``page``) may include inlined comments that are not
1521+
included in the proposed page update (``data``).
1522+
1523+
Args:
1524+
page: the page data from confluence to update
1525+
page_name: the page title to use on the update page
1526+
data: the new page data to be applied
1527+
1528+
Returns:
1529+
whether at least one inlined comment will be dropped
1530+
"""
1531+
1532+
try:
1533+
existing_data = page['body']['storage']['value']
1534+
except KeyError:
1535+
return False
1536+
1537+
# At this time, we only have this crude check for inlined comments.
1538+
# We check if the original page has any inlined comment markers. If
1539+
# so, we generate a warning. A publish even will still go through,
1540+
# but it generates a warning to inform users and allows a publish
1541+
# even to stop if `--fail-on-warning` is set.
1542+
if '<ac:inline-comment-marker' in existing_data:
1543+
logger.warn(f'inline comment detected (page "{page_name}")',
1544+
subtype='inline-comment')
1545+
return True
1546+
1547+
return False
1548+
15011549
def _next_page_fields(self, rsp, fields, offset):
15021550
"""
15031551
extract next query fields from a response

0 commit comments

Comments
 (0)