Skip to content

Commit

Permalink
Merge pull request #931 from sphinx-contrib/url-encode-v2-anchor-links
Browse files Browse the repository at this point in the history
builder: improve workaround for v2 editor anchor links
  • Loading branch information
jdknight authored Mar 29, 2024
2 parents 3598480 + ff0824c commit 2c57187
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions sphinxcontrib/confluencebuilder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from sphinxcontrib.confluencebuilder.util import first
from sphinxcontrib.confluencebuilder.util import handle_cli_file_subset
from sphinxcontrib.confluencebuilder.writer import ConfluenceWriter
from urllib.parse import quote
import os
import tempfile

Expand Down Expand Up @@ -1168,16 +1169,13 @@ def _register_doctree_title_targets(self, docname, doctree):
if section_id > 0:
target = f'{target}.{section_id}'

# v2 editor does not link anchors with parenthesis
# gracefully; inject a workaround
# v2 editor does not link anchors with select characters;
# provide a workaround that url encodes targets
#
# See: https://jira.atlassian.com/browse/CONFCLOUD-7469
if not self.config.confluence_adv_disable_confcloud_74698:
if editor == 'v2':
if any(x in target for x in ['(', ')']):
target = 2*'[inlineExtension]' + target
target = target.replace('(', '%28')
target = target.replace(')', '%29')
target = quote(target)

for raw_id in section_node['ids']:
full_id = f'{docname}#{raw_id}'
Expand Down

0 comments on commit 2c57187

Please sign in to comment.