@franlol/opencode-md-table-formatter 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +29 -35
  2. package/index.ts +8 -1
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -2,52 +2,48 @@
2
2
 
3
3
  Markdown table formatter plugin for Opencode with concealment mode support.
4
4
 
5
- ## Features
6
-
7
- - ✅ **Automatic table formatting** - Formats markdown tables after AI text completion
8
- - ✅ **Concealment mode compatible** - Correctly calculates column widths when markdown symbols are hidden
9
- - ✅ **Alignment support** - Left (`:---`), center (`:---:`), and right (`---:`) text alignment
10
- - ✅ **Nested markdown handling** - Strips bold, italic, strikethrough with multi-pass algorithm
11
- - ✅ **Code block preservation** - Preserves markdown symbols inside inline code (`` `**bold**` ``)
12
- - ✅ **Edge case handling** - Emojis, unicode characters, empty cells, long content
13
- - ✅ **Silent operation** - No console logs, errors don't interrupt workflow
14
- - ✅ **Validation feedback** - Invalid tables get helpful error comments
15
-
16
5
  ## Usage
17
6
 
18
7
  Add the plugin to your `.opencode/opencode.jsonc`:
19
8
 
20
9
  ```jsonc
21
10
  {
22
- "plugin": ["@franlol/opencode-md-table-formatter@0.0.2"],
11
+ "plugin": ["@franlol/opencode-md-table-formatter@latest"],
23
12
  }
24
13
  ```
25
14
 
26
- Restart Opencode. Tables in AI responses will now be automatically formatted!
27
-
28
15
  ## Example
29
16
 
30
- The plugin handles complex edge cases with concealment mode enabled:
31
-
32
- **Input** (unformatted table with nested markdown):
17
+ <table>
18
+ <tr>
19
+ <th style="text-align:center;">Original</th>
20
+ <th style="text-align:center;">Formatted</th>
21
+ </tr>
22
+ <tr>
23
+ <td>
24
+ <img src="https://github.com/user-attachments/assets/df71e950-c15d-4a10-8e08-fdd9b0216ba0"
25
+ alt="Screenshot 1"
26
+ style="height:250px; object-fit:cover;">
27
+ </td>
28
+ <td>
29
+ <img src="https://github.com/user-attachments/assets/c6f253e0-350f-487e-8da7-c8c6e8b2cb93"
30
+ alt="Screenshot 2"
31
+ style="height:250px; object-fit:cover;">
32
+ </td>
33
+ </tr>
34
+ </table>
33
35
 
34
- ```
35
- | Feature | Description | Status |
36
- |---|---|
37
- | **Bold text** | Has *italic* content | ✅ Done |
38
- | `Code` | With `**bold**` inside | ⏳ Progress |
39
- | Unicode | Greek α β γ | 💡 Idea |
40
- ```
36
+ ## Features
41
37
 
42
- **Output** (automatically formatted):
38
+ - **Automatic table formatting** - Formats markdown tables after AI text completion
39
+ - **Concealment mode compatible** - Correctly calculates column widths when markdown symbols are hidden
40
+ - **Alignment support** - Left (`:---`), center (`:---:`), and right (`---:`) text alignment
41
+ - **Nested markdown handling** - Strips bold, italic, strikethrough with multi-pass algorithm
42
+ - **Code block preservation** - Preserves markdown symbols inside inline code (`` `**bold**` ``)
43
+ - **Edge case handling** - Emojis, unicode characters, empty cells, long content
44
+ - **Silent operation** - No console logs, errors don't interrupt workflow
45
+ - **Validation feedback** - Invalid tables get helpful error comments
43
46
 
44
- ```
45
- | Feature | Description | Status |
46
- | ------------- | ---------------------- | ----------- |
47
- | **Bold text** | Has *italic* content | ✅ Done |
48
- | `Code` | With `**bold**` inside | ⏳ Progress |
49
- | Unicode | Greek α β γ | 💡 Idea |
50
- ```
51
47
 
52
48
  **Key behaviors:**
53
49
 
@@ -79,9 +75,7 @@ The plugin uses a multi-pass regex algorithm to handle nested markdown (like `**
79
75
 
80
76
  ## Requirements
81
77
 
82
- - Opencode CLI
83
- - Node.js >= 18.0.0 or Bun runtime
84
- - `@opencode-ai/plugin` >= 0.13.7
78
+ - Opencode >= 1.0.137
85
79
 
86
80
  ## License
87
81
 
package/index.ts CHANGED
@@ -12,6 +12,8 @@ export const FormatTables: Plugin = async () => {
12
12
  input: { sessionID: string; messageID: string; partID: string },
13
13
  output: { text: string },
14
14
  ) => {
15
+ if (typeof output.text !== "string") return;
16
+
15
17
  try {
16
18
  output.text = formatMarkdownTables(output.text)
17
19
  } catch (error) {
@@ -22,7 +24,7 @@ export const FormatTables: Plugin = async () => {
22
24
  } as Hooks
23
25
  }
24
26
 
25
- function formatMarkdownTables(text: string): string {
27
+ export function formatMarkdownTables(text: string): string {
26
28
  const lines = text.split("\n")
27
29
  const result: string[] = []
28
30
  let i = 0
@@ -180,9 +182,14 @@ function getStringWidth(text: string): number {
180
182
  previousText = visualText
181
183
  visualText = visualText
182
184
  .replace(/\*\*\*(.+?)\*\*\*/g, "$1") // ***bold+italic*** -> text
185
+ .replace(/___(.+?)___/g, "$1") // ___bold+italic___ -> text
183
186
  .replace(/\*\*(.+?)\*\*/g, "$1") // **bold** -> bold
187
+ .replace(/__(.+?)__/g, "$1") // __bold__ -> bold
184
188
  .replace(/\*(.+?)\*/g, "$1") // *italic* -> italic
189
+ .replace(/_(.+?)_/g, "$1") // _italic_ -> italic
185
190
  .replace(/~~(.+?)~~/g, "$1") // ~~strike~~ -> strike
191
+ .replace(/~(.+?)~/g, "$1") // ~subscript~ -> subscript
192
+ .replace(/\^(.+?)\^/g, "$1") // ^superscript^ -> superscript
186
193
  .replace(/!\[([^\]]*)\]\(([^)]+)\)/g, "$1") // ![alt](url) -> alt (OpenTUI shows only alt text)
187
194
  .replace(/\[([^\]]+)\]\(([^)]+)\)/g, "$1 ($2)") // [text](url) -> text (url)
188
195
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@franlol/opencode-md-table-formatter",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Markdown table formatter plugin for OpenCode with concealment mode support",
5
5
  "keywords": [
6
6
  "opencode",
@@ -30,7 +30,7 @@
30
30
  "README.md"
31
31
  ],
32
32
  "scripts": {
33
- "test": "echo \"Error: no test specified\" && exit 1"
33
+ "test": "bun test"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@opencode-ai/plugin": ">=0.13.7"