Enhance Flextable: Strikethrough Formatting Feature Request

by Felix Dubois 60 views

Hey guys,

I'm super stoked to dive into a crucial enhancement for the amazing flextable package, along with its friends officer and ftextra. Big shoutout to David Gohel for creating these tools – they've seriously become the backbone of creating top-notch Word documents in my R workflow. Today, let's chat about a feature request that's been on my mind: strikethrough formatting support. This is something that would be incredibly useful, and we'll explore how it can be implemented in two key areas.

1. Strikethrough via Markdown in colformat_md() (from ftextra)

Let's kick things off by talking about strikethrough formatting in Markdown within the colformat_md() function. Currently, this function is a champ at handling bold and italic Markdown syntax. You know, the usual **Bold** and *Italic* stuff. But what about strikethrough? Imagine you've got this chunk of code:

df <- data.frame(text = "**Bold**, *Italic*, and ~~Strikethrough~~")
flextable(df) %>% colformat_md()

In this scenario, the bold and italic text shines through like stars, rendering perfectly in your Word table. But that ~~Strikethrough~~? It's either ignored, like that one friend who always misses the joke, or it just shows up as plain text. Not cool, right?

So, here's the main request: Let's get colformat_md() to parse that ~~text~~ syntax and turn it into actual Word-compatible strikethrough formatting. Think about it – this would seriously boost the expressive power of Markdown-based formatting in our R-to-Word pipelines. We're talking about taking our document game to the next level, guys! This enhancement will allow users to clearly indicate revisions, deletions, or outdated information directly within their tables, making documents more transparent and easier to understand. By simply using the ~~ syntax, users can strike through text, providing a visual cue that something has been changed or is no longer valid. This is particularly useful in reports, presentations, and other documents where tracking changes and revisions is essential. The current limitation forces users to resort to workarounds, such as manually formatting the text in Word after the table is generated, which is time-consuming and defeats the purpose of using automated tools like flextable. Adding strikethrough support would streamline the workflow and enhance the overall efficiency of document creation.

2. Native strikethrough support in fp_text() / ftext()

Now, let's switch gears and talk about native strikethrough support in the fp_text() and ftext() functions. Right now, fp_text() is a formatting wizard, handling bold, italic, underlined text, colors, font sizes – the whole shebang. But it's missing one key ingredient: a strikeout or strikethrough argument. It's like having a superhero team without the healer – you're powerful, but not quite complete.

This absence makes it tricky to apply strikethrough formatting when you're using compose() or set_flextable_content(). Imagine you're crafting a table with carefully styled text, and you need to strikethrough a specific word or phrase. Without native support, you're stuck improvising, which isn't always ideal.

Here’s the request: Let's beef up the fp_text() API by adding a strikeout = TRUE (or strikethrough = TRUE) argument. This would unlock native strikethrough styling in custom-formatted text, giving us the power to fine-tune our tables exactly how we want them. This addition would significantly improve the flexibility and control users have over text formatting in flextable. Currently, achieving strikethrough effects requires complex workarounds or is simply not possible within the flextable framework. By integrating a strikeout parameter directly into fp_text(), users can easily apply this formatting style to specific parts of their text, enhancing the clarity and professionalism of their documents. This feature would be especially beneficial in scenarios where highlighting changes, marking deletions, or indicating outdated information is crucial. For instance, in legal documents or financial reports, strikethrough is often used to show text that has been removed or is no longer applicable. Native support within fp_text() would make this process seamless and efficient.

Use Case

So, why are we pushing for this? Think about the use cases. These enhancements would be a game-changer for dynamically generating Word tables where you need to visually represent deprecated values, removed terms, or replaced statuses. Strikethrough is the universal signal for