Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table alignment config option #959

Merged
merged 1 commit into from
Feb 23, 2023
Merged

Table alignment config option #959

merged 1 commit into from
Feb 23, 2023

Conversation

colinodell
Copy link
Member

This PR introduces a new config option to control whether table cell alignment is rendered using style or align attributes. See #958 for more context.

@colinodell colinodell added enhancement New functionality or behavior feedback wanted We need your input! labels Feb 15, 2023
@colinodell colinodell added this to the v2.4 milestone Feb 15, 2023
@colinodell colinodell self-assigned this Feb 15, 2023
@colinodell colinodell force-pushed the table-align-css branch 2 times, most recently from 6e82587 to a15a930 Compare February 15, 2023 14:23
@colinodell
Copy link
Member Author

@ptmkenny Would something like this work for you?

@ptmkenny
Copy link

@colinodell Yeah, this is great-- it will eliminate the error for me and others who need to pass W3C for one reason or another.

Just a thought-- if we have the ability to inline CSS, is it also possible to add an option to supply the CSS classes for left/center/right align? This might complicate the config too much, but many design frameworks (Bootstrap and Bulma are the ones I am familiar with, but I would assume others as well) already provide classes for doing this alignment, so being able to specify the classes to use would be the optimal solution from the perspective of a framework user.

@colinodell
Copy link
Member Author

Great question... 🤔

Ideally, I wish I could just point users toward the Default Attributes extension and have them configure the alignment attributes there. This would allow them to choose whether to use align, style, or class. But the challenge is that you shouldn't need to configure this to get proper alignment out-of-the-box - the Table extension (and thus the GFM extension) should do this for you. But Default Attributes doesn't let you remove existing attributes, which means we can't use that to generate W3C-compliant output 😭 So it seems we do need to give users as much flexibility as possible in the Table extension's config to override the default behavior.

Perhaps instead of the approach I initially proposed here we should have three config options - something like this:

$config = [
    'table' => [
        'alignment_attributes' => [
            'left' => ['align' => 'left'],
            'center' => ['align' => 'center'],
            'right' => ['align' => 'right'],
        ],
    ],
];

It's not as tidy but it would let you easily switch to inline styles:

$config = [
    'table' => [
        'alignment_attributes' => [
            'left' => ['style' => 'text-align:left'],
            'center' => ['style' => 'text-align:center'],
            'right' => ['style' => 'text-align:right'],
        ],
    ],
];

Or to classes:

$config = [
    'table' => [
        'alignment_attributes' => [
            'left' => ['class' => 'text-start'],
            'center' => ['class' => 'text-center'],
            'right' => ['class' => 'text-end'],
        ],
    ],
];

What do you think about that approach? I'm also open to any alternative ideas you might have here :)

@ptmkenny
Copy link

@colinodell Wow, this looks great.

I've been thinking about it for the past couple days, and it seems robust enough to cover all the use cases I could think of--

  • Using GFM as is
  • Inlining the CSS to get W3C compliance
  • Integrating with a framework
  • Using arbitrary classes

I definitely think the additional complexity is worth it because it empowers the user to make the extension compatible with whatever other systems they have in place.

@ptmkenny
Copy link

@colinodell Thanks, I immediately installed and started testing this.

One snag-- when I use class, the rendered output includes both the result for class and align-- align doesn't get replaced; class just gets added. The same happens for style-- align is also added.

In TableCellRendered.php, Xdebug shows that $node->get->get('attributes') has both class and align set, and align is set even if change the DEFAULT_ATTRIBUTES constant to be class values instead of align. I was unable to debug further.

My understanding was that setting class or style is that it should replace the value for align, not supplement it, as the original goal was to generate W3C-compliant output, which requires removing align.

@colinodell
Copy link
Member Author

🤦 I forgot to instruct the configuration schema to replace (instead of merge) the default configs with the user-provided configs. This should be fixed in 8721df8 - sorry about that!

@ptmkenny
Copy link

@colinodell Thanks, with the latest version, it's working as expected!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New functionality or behavior feedback wanted We need your input!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Table centering is producing align="center" instead of style="text-align: center"
2 participants