Skip to content

Feature proposal: Using transformers in plaintext #962

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

Open
3 tasks done
brc-dd opened this issue Mar 7, 2025 · 1 comment
Open
3 tasks done

Feature proposal: Using transformers in plaintext #962

brc-dd opened this issue Mar 7, 2025 · 1 comment

Comments

@brc-dd
Copy link
Contributor

brc-dd commented Mar 7, 2025

Clear and concise description of the problem

Currently, the comments based solution doesn't work with plaintext blocks:

```txt
foo // [!code --]
bar // [!code ++]
```

This used to work with Enzo's shiki-processor implementation because it was using a regex-based solution to do stuff regardless of the language.

x-ref: vuejs/vitepress#4602

Suggested solution

We can support the syntax above or maybe without need for comment markers in plaintext? This workaround seems to work fine for simple cases:

codeTransformers: [
  {
    span(span, i, j, line) {
      if (this.options.lang !== 'txt') return
      const text = span.children[0]
      if (!text || text.type !== 'text') return
      if (text.value.endsWith('[!code ++]')) {
        text.value = text.value.slice(0, -10)
        this.addClassToHast(this.pre, 'has-diff')
        this.addClassToHast(line, ['diff', 'add'])
      } else if (text.value.endsWith('[!code --]')) {
        text.value = text.value.slice(0, -10)
        this.addClassToHast(this.pre, 'has-diff')
        this.addClassToHast(line, ['diff', 'remove'])
      }
    }
  }
]

Alternative

No response

Additional context

No response

Validations

@bsdayo
Copy link

bsdayo commented Mar 11, 2025

Faced a similar problem today. I'm rendering a Markdown codeblock with diffs, but due to the fact that Markdown doesn't have comments, it's impossible to show a diff line in a Markdown codeblock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants