@friendlyrobot/discord-pi-agent 0.5.1 → 0.5.2
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.
- package/dist/index.js +21 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
import { Lexer } from "marked";
|
|
18
18
|
var CODE_BLOCK_WRAPPER = "```\n{TABLE}\n```";
|
|
19
19
|
async function transformMarkdownTablesToCodeBlocks(text) {
|
|
20
|
-
const
|
|
20
|
+
const normalized = normalizeCodeFences(text);
|
|
21
|
+
const formatted = await formatWithPrettier(normalized);
|
|
21
22
|
const tokens = Lexer.lex(formatted);
|
|
22
23
|
const result = [];
|
|
23
24
|
for (const token of tokens) {
|
|
@@ -29,6 +30,25 @@ async function transformMarkdownTablesToCodeBlocks(text) {
|
|
|
29
30
|
}
|
|
30
31
|
return formatWithPrettier(result.join(""));
|
|
31
32
|
}
|
|
33
|
+
function normalizeCodeFences(text) {
|
|
34
|
+
const lines = text.split(`
|
|
35
|
+
`);
|
|
36
|
+
const result = [];
|
|
37
|
+
for (const line of lines) {
|
|
38
|
+
const trimmed = line.trimEnd();
|
|
39
|
+
if (trimmed.endsWith("```") && !trimmed.startsWith("```")) {
|
|
40
|
+
const beforeFence = trimmed.slice(0, -3).trimEnd();
|
|
41
|
+
if (beforeFence) {
|
|
42
|
+
result.push(beforeFence);
|
|
43
|
+
}
|
|
44
|
+
result.push("```");
|
|
45
|
+
} else {
|
|
46
|
+
result.push(line);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result.join(`
|
|
50
|
+
`);
|
|
51
|
+
}
|
|
32
52
|
async function formatWithPrettier(text) {
|
|
33
53
|
const prettier = await import("prettier");
|
|
34
54
|
try {
|