-
I would like code in "```" style blocks to be colored. {
"type": "TextBlock",
"text": "```python\ndef foo(a=33):\n return 3\n```"
} and I want it to be colored, like GitHub does: def foo(a=33):
return 3\n BTW here's the HTML for that: <div class="ac-container ac-adaptiveCard" style="display: flex; flex-direction: column; justify-content: flex-start; box-sizing: border-box; flex: 0 0 auto; padding: 16px; margin: 0px; background-color: rgb(255, 255, 255);">
<div class="ac-textBlock" style="overflow: hidden; font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; font-size: 14px; color: rgb(37, 36, 36); font-weight: 400; text-align: start; line-height: 18.62px; white-space: nowrap; text-overflow: ellipsis; box-sizing: border-box; flex: 0 0 auto;">
<pre style="margin-top: 0px; width: 100%; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0px;">
<code class="language-python x-hidden-focus">def foo(a=33):
return 3
</code>
</pre>
</div>
</div> I already tried removing the custom I see |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
AdaptiveCard supports a subset of MarkDown, and it's intentional. You can refer to our doc for supported MarkDown features. |
Beta Was this translation helpful? Give feedback.
-
Thanks for getting back to me so quickly! It seems like there's nothing free out-of-the-box, but there are a few options for custom ways to get colors:
For JavaScript/TypeScript, I got this to work. Easy WayFirst, make sure you support Markdown in cards: import MarkdownIt from 'markdown-it'
// For Markdown in Adaptive Cards.
window.markdownit = MarkdownIt Now we'll use another library to color code: import highlight from 'highlight.js'
import 'highlight.js/styles/github.css' Run: highlight.highlightAll() to update all your cards. If you run it twice, then it will try to update cards that it already updated, and you'll get warnings. If you're dynamically adding cards to the page: Explicit Way For Dynamically Adding Cardsimport * as AdaptiveCards from 'adaptivecards'
import highlight from 'highlight.js'
import 'highlight.js/styles/github.css'
import MarkdownIt from 'markdown-it'
const markdownRenderer = new MarkdownIt({
typographer: true,
highlight: (source, language): string => {
// https://highlightjs.readthedocs.io
// Default to use default highlighting which is probably nothing.
let result = ""
if (language && hljs.getLanguage(language)) {
try {
result = hljs.highlight(source, { language }).value
} catch (err) {
console.warn("Error highlighting code block.", err)
}
}
return result
},
})
AdaptiveCards.AdaptiveCard.onProcessMarkdown = (text, result): void => {
result.outputHtml = markdownRenderer.render(text)
result.didProcess = true
} |
Beta Was this translation helpful? Give feedback.
-
You can now use CodeBlock instead of TextBlock for preformatted text with syntax highlighting in AdaptiveCards. |
Beta Was this translation helpful? Give feedback.
-
Thanks @qris! Looks like CodeBlock is just for Microsoft Teams? |
Beta Was this translation helpful? Give feedback.
Thanks for getting back to me so quickly! It seems like there's nothing free out-of-the-box, but there are a few options for custom ways to get colors:
For JavaScript/TypeScript, I got this to work.
Easy Way
Firs…