Skip to content

Commit

Permalink
Merge pull request #860 from sphinx-contrib/support-width-hints-for-c…
Browse files Browse the repository at this point in the history
…sv-tables

support csv width hints in v2 editor
  • Loading branch information
jdknight authored Nov 19, 2023
2 parents 17aea6f + 8c5d1a2 commit 7233db3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
7 changes: 7 additions & 0 deletions sphinxcontrib/confluencebuilder/std/confluence.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
# confluence trailing bind path for rest api
API_REST_BIND_PATH = 'rest/api'

# default width for a table (v2 editor)
#
# It has been observed that when attempting to fix specific column widths on
# a table in the v2 editor, Confluence applies a default data width of 760 on
# the table.
CONFLUENCE_DEFAULT_V2_TABLE_WIDTH = 760

# maximum length for a confluence page title
#
# The maximum length of a Confluence page is set to 255. This is a Confluence-
Expand Down
9 changes: 9 additions & 0 deletions sphinxcontrib/confluencebuilder/storage/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sphinxcontrib.confluencebuilder.exceptions import ConfluenceError
from sphinxcontrib.confluencebuilder.locale import L
from sphinxcontrib.confluencebuilder.nodes import confluence_parameters_fetch as PARAMS
from sphinxcontrib.confluencebuilder.std.confluence import CONFLUENCE_DEFAULT_V2_TABLE_WIDTH
from sphinxcontrib.confluencebuilder.std.confluence import CONFLUENCE_MAX_WIDTH
from sphinxcontrib.confluencebuilder.std.confluence import FALLBACK_HIGHLIGHT_STYLE
from sphinxcontrib.confluencebuilder.std.confluence import FCMMO
Expand Down Expand Up @@ -1066,6 +1067,14 @@ def visit_table(self, node):
table_classes = node.get('classes', [])
attribs = {}

# For v2 editor, if we have given explicit widths for columns in the
# table (e.g. CSV table), we need to apply a data table width or the
# editor will ignore the column-specific widths. If widths are
# detected, apply the default table width observed when using the v2
# editor.
if self.v2 and 'colwidths-given' in table_classes:
attribs['data-table-width'] = CONFLUENCE_DEFAULT_V2_TABLE_WIDTH

# [sphinxcontrib-needs]
# force needs tables to a maximum width
# (do not for v2 editor, as it will already use the page's width)
Expand Down
10 changes: 0 additions & 10 deletions tests/validation-sets/restructuredtext/csv-table.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
CSV Table
=========

.. only:: confluence_storage

.. ifconfig:: confluence_editor == 'v2'

.. attention::

Limitations using the Fabric (``v2``) editor:

- Confluence does not support customizing column widths.

reStructuredText defines a `csv-table`_. Example markup is as follows:

.. code-block:: none
Expand Down

0 comments on commit 7233db3

Please sign in to comment.