@chat-adapter/teams 4.15.0 → 4.16.1
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.d.ts +5 -0
- package/dist/index.js +80 -15
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,11 @@ declare class TeamsFormatConverter extends BaseFormatConverter {
|
|
|
69
69
|
*/
|
|
70
70
|
toAst(teamsText: string): Root;
|
|
71
71
|
private nodeToTeams;
|
|
72
|
+
/**
|
|
73
|
+
* Render an mdast table node as a GFM markdown table.
|
|
74
|
+
* Teams renders markdown tables natively.
|
|
75
|
+
*/
|
|
76
|
+
private tableToGfm;
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
interface TeamsAdapterConfig {
|
package/dist/index.js
CHANGED
|
@@ -3588,6 +3588,7 @@ import {
|
|
|
3588
3588
|
mapButtonStyle,
|
|
3589
3589
|
cardToFallbackText as sharedCardToFallbackText
|
|
3590
3590
|
} from "@chat-adapter/shared";
|
|
3591
|
+
import { cardChildToFallbackText } from "chat";
|
|
3591
3592
|
var convertEmoji = createEmojiConverter("teams");
|
|
3592
3593
|
var ADAPTIVE_CARD_SCHEMA = "http://adaptivecards.io/schemas/adaptive-card.json";
|
|
3593
3594
|
var ADAPTIVE_CARD_VERSION = "1.4";
|
|
@@ -3659,8 +3660,18 @@ function convertChildToAdaptive(child) {
|
|
|
3659
3660
|
],
|
|
3660
3661
|
actions: []
|
|
3661
3662
|
};
|
|
3662
|
-
|
|
3663
|
+
case "table":
|
|
3664
|
+
return { elements: [convertTableToElement(child)], actions: [] };
|
|
3665
|
+
default: {
|
|
3666
|
+
const text = cardChildToFallbackText(child);
|
|
3667
|
+
if (text) {
|
|
3668
|
+
return {
|
|
3669
|
+
elements: [{ type: "TextBlock", text, wrap: true }],
|
|
3670
|
+
actions: []
|
|
3671
|
+
};
|
|
3672
|
+
}
|
|
3663
3673
|
return { elements: [], actions: [] };
|
|
3674
|
+
}
|
|
3664
3675
|
}
|
|
3665
3676
|
}
|
|
3666
3677
|
function convertTextToElement(element) {
|
|
@@ -3744,6 +3755,42 @@ function convertSectionToElements(element) {
|
|
|
3744
3755
|
}
|
|
3745
3756
|
return { elements, actions };
|
|
3746
3757
|
}
|
|
3758
|
+
function convertTableToElement(element) {
|
|
3759
|
+
const columns = element.headers.map((header) => ({
|
|
3760
|
+
type: "Column",
|
|
3761
|
+
width: "stretch",
|
|
3762
|
+
items: [
|
|
3763
|
+
{
|
|
3764
|
+
type: "TextBlock",
|
|
3765
|
+
text: convertEmoji(header),
|
|
3766
|
+
weight: "bolder",
|
|
3767
|
+
wrap: true
|
|
3768
|
+
}
|
|
3769
|
+
]
|
|
3770
|
+
}));
|
|
3771
|
+
const headerRow = {
|
|
3772
|
+
type: "ColumnSet",
|
|
3773
|
+
columns
|
|
3774
|
+
};
|
|
3775
|
+
const dataRows = element.rows.map((row) => ({
|
|
3776
|
+
type: "ColumnSet",
|
|
3777
|
+
columns: row.map((cell) => ({
|
|
3778
|
+
type: "Column",
|
|
3779
|
+
width: "stretch",
|
|
3780
|
+
items: [
|
|
3781
|
+
{
|
|
3782
|
+
type: "TextBlock",
|
|
3783
|
+
text: convertEmoji(cell),
|
|
3784
|
+
wrap: true
|
|
3785
|
+
}
|
|
3786
|
+
]
|
|
3787
|
+
}))
|
|
3788
|
+
}));
|
|
3789
|
+
return {
|
|
3790
|
+
type: "Container",
|
|
3791
|
+
items: [headerRow, ...dataRows]
|
|
3792
|
+
};
|
|
3793
|
+
}
|
|
3747
3794
|
function convertFieldsToElement(element) {
|
|
3748
3795
|
const facts = element.children.map((field) => ({
|
|
3749
3796
|
title: convertEmoji(field.label),
|
|
@@ -3763,20 +3810,20 @@ function cardToFallbackText(card) {
|
|
|
3763
3810
|
}
|
|
3764
3811
|
|
|
3765
3812
|
// src/markdown.ts
|
|
3813
|
+
import { escapeTableCell } from "@chat-adapter/shared";
|
|
3766
3814
|
import {
|
|
3767
3815
|
BaseFormatConverter,
|
|
3768
3816
|
getNodeChildren,
|
|
3769
|
-
getNodeValue,
|
|
3770
3817
|
isBlockquoteNode,
|
|
3771
3818
|
isCodeNode,
|
|
3772
3819
|
isDeleteNode,
|
|
3773
3820
|
isEmphasisNode,
|
|
3774
3821
|
isInlineCodeNode,
|
|
3775
3822
|
isLinkNode,
|
|
3776
|
-
isListItemNode,
|
|
3777
3823
|
isListNode,
|
|
3778
3824
|
isParagraphNode,
|
|
3779
3825
|
isStrongNode,
|
|
3826
|
+
isTableNode,
|
|
3780
3827
|
isTextNode,
|
|
3781
3828
|
parseMarkdown
|
|
3782
3829
|
} from "chat";
|
|
@@ -3874,14 +3921,7 @@ ${node.value}
|
|
|
3874
3921
|
return getNodeChildren(node).map((child) => `> ${this.nodeToTeams(child)}`).join("\n");
|
|
3875
3922
|
}
|
|
3876
3923
|
if (isListNode(node)) {
|
|
3877
|
-
return
|
|
3878
|
-
const prefix = node.ordered ? `${i + 1}.` : "-";
|
|
3879
|
-
const content = getNodeChildren(item).map((child) => this.nodeToTeams(child)).join("");
|
|
3880
|
-
return `${prefix} ${content}`;
|
|
3881
|
-
}).join("\n");
|
|
3882
|
-
}
|
|
3883
|
-
if (isListItemNode(node)) {
|
|
3884
|
-
return getNodeChildren(node).map((child) => this.nodeToTeams(child)).join("");
|
|
3924
|
+
return this.renderList(node, 0, (child) => this.nodeToTeams(child));
|
|
3885
3925
|
}
|
|
3886
3926
|
if (node.type === "break") {
|
|
3887
3927
|
return "\n";
|
|
@@ -3889,11 +3929,36 @@ ${node.value}
|
|
|
3889
3929
|
if (node.type === "thematicBreak") {
|
|
3890
3930
|
return "---";
|
|
3891
3931
|
}
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3932
|
+
if (isTableNode(node)) {
|
|
3933
|
+
return this.tableToGfm(node);
|
|
3934
|
+
}
|
|
3935
|
+
return this.defaultNodeToText(node, (child) => this.nodeToTeams(child));
|
|
3936
|
+
}
|
|
3937
|
+
/**
|
|
3938
|
+
* Render an mdast table node as a GFM markdown table.
|
|
3939
|
+
* Teams renders markdown tables natively.
|
|
3940
|
+
*/
|
|
3941
|
+
tableToGfm(node) {
|
|
3942
|
+
const rows = [];
|
|
3943
|
+
for (const row of node.children) {
|
|
3944
|
+
const cells = [];
|
|
3945
|
+
for (const cell of row.children) {
|
|
3946
|
+
const cellContent = getNodeChildren(cell).map((child) => this.nodeToTeams(child)).join("");
|
|
3947
|
+
cells.push(cellContent);
|
|
3948
|
+
}
|
|
3949
|
+
rows.push(cells);
|
|
3950
|
+
}
|
|
3951
|
+
if (rows.length === 0) {
|
|
3952
|
+
return "";
|
|
3953
|
+
}
|
|
3954
|
+
const lines = [];
|
|
3955
|
+
lines.push(`| ${rows[0].map(escapeTableCell).join(" | ")} |`);
|
|
3956
|
+
const separators = rows[0].map(() => "---");
|
|
3957
|
+
lines.push(`| ${separators.join(" | ")} |`);
|
|
3958
|
+
for (let i = 1; i < rows.length; i++) {
|
|
3959
|
+
lines.push(`| ${rows[i].map(escapeTableCell).join(" | ")} |`);
|
|
3895
3960
|
}
|
|
3896
|
-
return
|
|
3961
|
+
return lines.join("\n");
|
|
3897
3962
|
}
|
|
3898
3963
|
};
|
|
3899
3964
|
|