@@ -323,6 +323,13 @@ const (
323
323
TypeElementTextRun string = "TextRun" // Introduced in version 1.2
324
324
)
325
325
326
+ // Known exension types for an Adaptive Card element.
327
+ //
328
+ // - https://learn.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cdesktop%2Cconnector-html#codeblock-in-adaptive-cards
329
+ const (
330
+ TypeElementMSTeamsCodeBlock string = "CodeBlock"
331
+ )
332
+
326
333
// Sentinel errors for this package.
327
334
var (
328
335
// ErrInvalidType indicates that an invalid type was specified.
@@ -601,6 +608,15 @@ type Element struct {
601
608
// Separator, when true, indicates that a separating line shown should be
602
609
// drawn at the top of the element.
603
610
Separator bool `json:"separator,omitempty"`
611
+
612
+ // CodeSnippet provides the content for a CodeBlock element, specific to MSTeams.
613
+ CodeSnippet string `json:"codeSnippet,omitempty"`
614
+
615
+ // Language specifies the langauge of a CodeBlock element, specific to MSTeams.
616
+ Language string `json:"language,omitempty"`
617
+
618
+ // StartLineNumber specifies the initial line number of CodeBlock element, specific to MSTeams.
619
+ StartLineNumber int `json:"startLineNumber,omitempty"`
604
620
}
605
621
606
622
// Container is an Element type that allows grouping items together.
@@ -1374,6 +1390,10 @@ func (e Element) Validate() error {
1374
1390
v .SelfValidate (TableRows (e .Rows ))
1375
1391
1376
1392
v .SelfValidate (TableColumnDefinitions (e .Columns ))
1393
+
1394
+ case e .Type == TypeElementMSTeamsCodeBlock :
1395
+ v .NotEmptyValue (e .CodeSnippet , "CodeSnippet" , e .Type , ErrMissingValue )
1396
+ v .NotEmptyValue (e .Language , "Language" , e .Type , ErrMissingValue )
1377
1397
}
1378
1398
1379
1399
// Return the last recorded validation error, or nil if no validation
@@ -3145,6 +3165,18 @@ func (c *Card) AddContainer(prepend bool, container Container) error {
3145
3165
return nil
3146
3166
}
3147
3167
3168
+ // NewCodeBlock creates a new CodeBlock element with snippet, language, and
3169
+ // optional firstLine. This is an MSTeams extension element.
3170
+ func NewCodeBlock (snippet string , language string , firstLine int ) Element {
3171
+ codeBlock := Element {
3172
+ Type : TypeElementMSTeamsCodeBlock ,
3173
+ CodeSnippet : snippet ,
3174
+ Language : language ,
3175
+ StartLineNumber : firstLine ,
3176
+ }
3177
+ return codeBlock
3178
+ }
3179
+
3148
3180
// cardBodyHasMention indicates whether an Adaptive Card body contains all
3149
3181
// specified Mention values. For every user mention, we require at least one
3150
3182
// match in an applicable Element in the Card Body.
0 commit comments