Skip to content

Distribute and run LLMs with a single file.

Improve markdown to html rendering

Justine Tunneyfa1c98f9ba6e
diff --git a/llamafile/server/www/chatbot.css b/llamafile/server/www/chatbot.css
index 27f7afc4..f4b1dacb 100644
--- a/llamafile/server/www/chatbot.css
+++ b/llamafile/server/www/chatbot.css
@@ -49,6 +49,37 @@ p {
padding: 1rem;
}
+ol,
+ul {
+ margin: 0.5rem 0;
+ padding-left: 2rem;
+}
+
+ol li,
+ul li {
+ padding: 0.25rem 0;
+ margin: 0;
+}
+
+ol li::marker {
+ color: #666;
+ font-weight: 500;
+}
+
+ul li::marker {
+ color: #666;
+}
+
+ol li:last-child,
+ul li:last-child {
+ padding-bottom: 0;
+}
+
+ol li:first-child,
+ul li:first-child {
+ padding-top: 0;
+}
+
.message {
margin-bottom: 1rem;
padding: 0.75rem;
@@ -86,6 +117,40 @@ p {
border-radius: 6px;
font-size: 1rem;
outline: none;
+ resize: none;
+ max-height: 200px;
+ min-height: 44px;
+ line-height: 1.5;
+ font-family: inherit;
+ overflow-y: auto;
+ scrollbar-width: thin; /* Firefox */
+ scrollbar-color: #cbd5e1 transparent; /* Firefox */
+}
+
+/* Chrome, Edge, and Safari */
+.chat-input::-webkit-scrollbar {
+ width: 8px;
+ background: transparent;
+}
+
+.chat-input::-webkit-scrollbar-track {
+ background: transparent;
+}
+
+.chat-input::-webkit-scrollbar-thumb {
+ background-color: #cbd5e1;
+ border-radius: 20px;
+ border: 2px solid transparent;
+ background-clip: padding-box;
+}
+
+/* Only show scrollbar when needed */
+.chat-input::-webkit-scrollbar-thumb:vertical {
+ min-height: 30px;
+}
+
+.chat-input:not(:hover)::-webkit-scrollbar-thumb {
+ background-color: transparent;
}
.chat-input:focus {
diff --git a/llamafile/server/www/chatbot.js b/llamafile/server/www/chatbot.js
index 7e48c147..e7843952 100644
--- a/llamafile/server/www/chatbot.js
+++ b/llamafile/server/www/chatbot.js
@@ -19,7 +19,7 @@ const chatMessages = document.getElementById("chat-messages");
const chatInput = document.getElementById("chat-input");
const sendButton = document.getElementById("send-button");
const typingIndicator = document.getElementById("typing-indicator");
-const stopButton = document.getElementById('stop-button');
+const stopButton = document.getElementById("stop-button");
let abortController = null;
let streamingMessageContent = [];
@@ -51,12 +51,17 @@ function setTypingIndicatorVisibility(visible) {
typingIndicator.style.display = visible ? "flex" : "none";
}
+function onChatInput() {
+ chatInput.style.height = "auto"; // computes scrollHeight
+ chatInput.style.height = Math.min(chatInput.scrollHeight, 200) + "px";
+}
+
function cleanupAfterMessage() {
setTypingIndicatorVisibility(false);
chatMessages.scrollTop = chatMessages.scrollHeight;
chatInput.disabled = false;
- sendButton.style.display = 'inline-block';
- stopButton.style.display = 'none';
+ sendButton.style.display = "inline-block";
+ stopButton.style.display = "none";
abortController = null;
chatInput.focus();
}
@@ -102,7 +107,7 @@ async function handleChatStream(response) {
buffer = lines[lines.length - 1];
}
} catch (error) {
- if (error.name !== 'AbortError') {
+ if (error.name !== "AbortError") {
console.error("Error reading stream:", error);
}
} finally {
@@ -125,7 +130,8 @@ async function sendMessage() {
// disable input while processing
chatInput.value = "";
chatInput.disabled = true;
- sendButton.style.display = 'none';
+ onChatInput();
+ sendButton.style.display = "none";
stopButton.style.display = "inline-block";
stopButton.focus();
abortController = new AbortController();
@@ -164,11 +170,11 @@ async function sendMessage() {
await handleChatStream(response);
// update chat history with response
- const lastMessage = streamingMessageContent.join('');
+ const lastMessage = streamingMessageContent.join("");
chatHistory.push({ role: "assistant", content: lastMessage });
} catch (error) {
- if (error.name !== 'AbortError') {
+ if (error.name !== "AbortError") {
console.error("Error:", error);
const errorMessage = createMessageElement(
"Sorry, there was an error processing your request.",
@@ -189,7 +195,8 @@ for (let i = 0; i < chatHistory.length; i++) {
// setup events
sendButton.addEventListener("click", sendMessage);
stopButton.addEventListener("click", stopMessage);
-chatInput.addEventListener("keypress", (e) => {
+chatInput.addEventListener("input", onChatInput);
+chatInput.addEventListener("keydown", function(e) {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault();
sendMessage();
diff --git a/llamafile/server/www/highlight.js b/llamafile/server/www/highlight.js
index db47525b..8354d219 100644
--- a/llamafile/server/www/highlight.js
+++ b/llamafile/server/www/highlight.js
@@ -45,24 +45,9 @@ class HighlightDom extends Highlight {
feed(s) {
for (let i = 0; i < s.length; ++i) {
- if (s[i] == '\n') {
- let classes = [];
+ this.text += s[i];
+ if (isspace(s[i])) {
this.flushText();
- while (this.currentElement.tagName == 'SPAN') {
- classes.push([this.currentElement.tagName,
- this.currentElement.className]);
- this.currentElement = this.currentElement.parentNode;
- }
- this.currentElement.appendChild(document.createElement('br'));
- while (classes.length) {
- let c = classes.pop();
- this.push(c[0], c[1]);
- }
- } else {
- this.text += s[i];
- if (isspace(s[i])) {
- this.flushText();
- }
}
}
}
@@ -70,7 +55,8 @@ class HighlightDom extends Highlight {
push(tagName, className) {
this.flushText();
const elem = document.createElement(tagName);
- elem.className = className;
+ if (className)
+ elem.className = className;
this.currentElement.appendChild(elem);
this.currentElement = elem;
return elem;
diff --git a/llamafile/server/www/highlight_markdown.js b/llamafile/server/www/highlight_markdown.js
index 8f28e986..8d270a26 100644
--- a/llamafile/server/www/highlight_markdown.js
+++ b/llamafile/server/www/highlight_markdown.js
@@ -40,10 +40,33 @@ class HighlightMarkdown extends Highlighter {
static LAB = 23;
static LAB_BACKSLASH = 24;
static HYPHEN = 25;
-
- static STYLE_STRONG = 0;
- static STYLE_EMPHASIS = 1;
- static STYLE_LIST = 2;
+ static TILDE = 26;
+ static EMPHASIS_STAR2 = 27;
+ static OLNAME = 28;
+ static OLNAME_DOT = 29;
+
+ static STYLE_SPAN = 16;
+ static STYLE_STRONG = 16;
+ static STYLE_EMPHASIS = 17;
+ static STYLE_STRIKE = 18;
+
+ static STYLE_LIST = 32;
+ static STYLE_UL = 32;
+ static STYLE_OL = 33;
+
+ static STYLE_DIV = 64;
+ static STYLE_LI = 64;
+
+ static get_style_tag(t) {
+ switch (t) {
+ case HighlightMarkdown.STYLE_UL:
+ return 'UL';
+ case HighlightMarkdown.STYLE_OL:
+ return 'OL';
+ default:
+ throw new Error('bad style');
+ }
+ }
static is_escapable(c) {
switch (c) {
@@ -71,6 +94,14 @@ class HighlightMarkdown extends Highlighter {
}
}
+ static is_sublist(depth, next) {
+ if (!depth) {
+ return next > 0;
+ } else {
+ return next >= depth + 4;
+ }
+ }
+
constructor(delegate) {
super(delegate);
this.bol = true;
@@ -82,33 +113,48 @@ class HighlightMarkdown extends Highlighter {
this.text = '';
this.href = '';
this.style = [];
+ this.trailing_spaces = 0;
+ this.olname = '';
}
inside(style) {
- return this.style.length && this.style[this.style.length - 1] == style;
+ return this.style.length && this.style[this.style.length - 1][0] == style;
}
- li(c) {
- if (this.inside(HighlightMarkdown.STYLE_LIST)) {
+ li(t) {
+ while (this.style.length &&
+ (this.style[this.style.length - 1][0] == HighlightMarkdown.STYLE_LI ||
+ (this.style[this.style.length - 1][0] & HighlightMarkdown.STYLE_SPAN) ||
+ ((this.style[this.style.length - 1][0] & HighlightMarkdown.STYLE_LIST) &&
+ (this.spaces < this.style[this.style.length - 1][1] ||
+ (this.style[this.style.length - 1][0] != t &&
+ !HighlightMarkdown.is_sublist(this.style[this.style.length - 1][1], this.spaces)))))) {
this.pop();
- this.push('li', '');
- } else if (!this.style.length) {
- this.style.push(HighlightMarkdown.STYLE_LIST);
- this.push('li', '');
- } else {
- this.append(c);
+ this.style.pop();
}
+ if (!this.style.length ||
+ ((this.style[this.style.length - 1][0] & HighlightMarkdown.STYLE_LIST) &&
+ HighlightMarkdown.is_sublist(this.style[this.style.length - 1][1], this.spaces))) {
+ this.style.push([t, this.spaces]);
+ this.push(HighlightMarkdown.get_style_tag(t), '');
+ }
+ this.style.push([HighlightMarkdown.STYLE_LI, this.spaces]);
+ this.push('LI', '');
this.bol = false;
}
got() {
if (this.bol) {
this.bol = false;
- if (this.spaces < 2 && this.inside(HighlightMarkdown.STYLE_LIST)) {
+ while (this.style.length &&
+ (this.style[this.style.length - 1][0] == HighlightMarkdown.STYLE_LI ||
+ (this.style[this.style.length - 1][0] & HighlightMarkdown.STYLE_LIST)) &&
+ this.spaces <= this.style[this.style.length - 1][1]) {
this.pop();
this.style.pop();
}
}
+ this.spaces = 0;
}
feed(input) {
@@ -130,42 +176,58 @@ class HighlightMarkdown extends Highlighter {
this.state = HighlightMarkdown.STAR;
}
break;
- } else if (c == '[') {
- this.state = HighlightMarkdown.LSB;
- } else if (c == '<') {
- this.state = HighlightMarkdown.LAB;
- } else if (c == '\\') {
- this.state = HighlightMarkdown.BACKSLASH;
} else if (c == '-' && this.bol) {
this.state = HighlightMarkdown.HYPHEN;
+ break;
+ } else if (isdigit(c) && this.bol) {
+ this.epsilon(HighlightMarkdown.OLNAME);
} else if (c == '\n') {
this.bol = true;
this.tail = false;
this.state = HighlightMarkdown.NEWLINE;
this.newlines = 1;
+ this.trailing_spaces = this.spaces;
this.spaces = 0;
break;
- } else {
- this.append(c);
- }
- this.tail = true;
- if (isblank(c)) {
+ } else if (c == '~') {
+ this.state = HighlightMarkdown.TILDE;
+ this.got();
+ } else if (c == '[') {
+ this.state = HighlightMarkdown.LSB;
+ this.got();
+ } else if (c == '<') {
+ this.state = HighlightMarkdown.LAB;
+ this.got();
+ } else if (c == '\\') {
+ this.state = HighlightMarkdown.BACKSLASH;
+ this.got();
+ } else if (c == ' ') {
++this.spaces;
+ this.append(c);
+ } else if (c == '\t') {
+ this.spaces += 4;
+ this.append(c);
} else {
this.got();
+ this.append(c);
}
+ this.tail = true;
break;
case HighlightMarkdown.NEWLINE:
if (c == '\n') {
++this.newlines;
+ this.spaces = 0;
+ } else if (c == ' ') {
+ ++this.spaces;
+ } else if (c == '\t') {
+ this.spaces += 4;
} else {
if (this.newlines >= 2) {
- if (this.inside(HighlightMarkdown.STYLE_LIST)) {
- this.pop();
- this.style.pop();
- }
- this.push('p', '');
+ this.push("p", "");
+ this.pop();
+ } else if (this.trailing_spaces >= 2) {
+ this.push('br', '');
this.pop();
} else {
this.append('\n');
@@ -174,10 +236,22 @@ class HighlightMarkdown extends Highlighter {
}
break;
+ case HighlightMarkdown.SPACE_SPACE:
+ if (c == '\n') {
+ this.state = HighlightMarkdown.NORMAL;
+ this.push('br', '');
+ this.pop();
+ this.append('\n');
+ } else {
+ this.append(" ");
+ this.epsilon(HighlightMarkdown.NORMAL);
+ }
+ break;
+
case HighlightMarkdown.HYPHEN:
if (isblank(c)) {
// - handle list item
- this.li('-');
+ this.li(HighlightMarkdown.STYLE_UL);
this.append(c);
this.state = HighlightMarkdown.NORMAL;
} else {
@@ -186,6 +260,33 @@ class HighlightMarkdown extends Highlighter {
}
break;
+ case HighlightMarkdown.OLNAME:
+ if (isdigit(c)) {
+ this.olname += c;
+ } else if (c == '.') {
+ this.olname += '.';
+ this.state = HighlightMarkdown.OLNAME_DOT;
+ } else {
+ this.got();
+ this.append(this.olname);
+ this.olname = '';
+ this.epsilon(HighlightMarkdown.NORMAL);
+ }
+ break;
+
+ case HighlightMarkdown.OLNAME_DOT:
+ if (isspace(c)) {
+ this.li(HighlightMarkdown.STYLE_OL);
+ this.olname = '';
+ this.state = HighlightMarkdown.NORMAL;
+ } else {
+ this.got();
+ this.append(this.olname);
+ this.olname = '';
+ this.epsilon(HighlightMarkdown.NORMAL);
+ }
+ break;
+
case HighlightMarkdown.BACKSLASH:
if (HighlightMarkdown.is_escapable(c)) {
this.append(c);
@@ -200,33 +301,59 @@ class HighlightMarkdown extends Highlighter {
if (c == '*') {
// handle **strong** text
// we don't call this.got() in case this is *** bar
+ this.got();
this.push('strong', '');
this.state = HighlightMarkdown.NORMAL;
- this.style.push(HighlightMarkdown.STYLE_STRONG);
+ this.style.push([HighlightMarkdown.STYLE_STRONG, 0]);
} else if (this.bol && isblank(c)) {
// * handle list item
- this.li('*');
+ this.li(HighlightMarkdown.STYLE_UL);
this.append(c);
this.state = HighlightMarkdown.NORMAL;
} else {
// handle *emphasis* text
this.got();
this.push('em', '');
- this.style.push(HighlightMarkdown.STYLE_EMPHASIS);
+ this.style.push([HighlightMarkdown.STYLE_EMPHASIS, 0]);
this.epsilon(HighlightMarkdown.NORMAL);
}
break;
case HighlightMarkdown.EMPHASIS_STAR:
if (c == '*') {
- // handle *italic **strong** text*
- this.push('strong', '');
- this.state = HighlightMarkdown.NORMAL;
- this.style.push(HighlightMarkdown.STYLE_STRONG);
+ this.state = HighlightMarkdown.EMPHASIS_STAR2;
} else {
// leave *italic* text
+ // ^
+ this.style.pop();
+ this.pop();
+ this.epsilon(HighlightMarkdown.NORMAL);
+ }
+ break;
+
+ case HighlightMarkdown.EMPHASIS_STAR2:
+ if (c == '*') {
this.style.pop();
this.pop();
+ if (this.inside(HighlightMarkdown.STYLE_STRONG)) {
+ // handle ***strong emphasis*** closing
+ // ^
+ this.style.pop();
+ this.pop();
+ this.state = HighlightMarkdown.NORMAL;
+ } else {
+ // handle *emphasis***strong**
+ // ^
+ this.push('strong', '');
+ this.state = HighlightMarkdown.NORMAL;
+ this.style.push([HighlightMarkdown.STYLE_STRONG, 0]);
+ this.state = HighlightMarkdown.NORMAL;
+ }
+ } else {
+ // handle *italic **strong** text*
+ // ^
+ this.push('strong', '');
+ this.style.push([HighlightMarkdown.STYLE_STRONG, 0]);
this.epsilon(HighlightMarkdown.NORMAL);
}
break;
@@ -238,6 +365,7 @@ class HighlightMarkdown extends Highlighter {
this.pop();
} else if (c == '\n' && !this.tail) {
// handle *** line break
+ this.got();
this.style.pop();
this.pop();
this.push('hr', '');
@@ -245,7 +373,24 @@ class HighlightMarkdown extends Highlighter {
this.epsilon(HighlightMarkdown.NORMAL);
} else {
this.push('em', '');
- this.style.push(HighlightMarkdown.STYLE_EMPHASIS);
+ this.style.push([HighlightMarkdown.STYLE_EMPHASIS, 0]);
+ this.epsilon(HighlightMarkdown.NORMAL);
+ }
+ break;
+
+ case HighlightMarkdown.TILDE:
+ if (c == '~') {
+ // handle ~~strikethrough text~~
+ if (this.inside(HighlightMarkdown.STYLE_STRIKE)) {
+ this.pop();
+ this.style.pop();
+ } else {
+ this.push('s', '');
+ this.style.push([HighlightMarkdown.STYLE_STRIKE, 0]);
+ }
+ this.state = HighlightMarkdown.NORMAL;
+ } else {
+ this.append('~');
this.epsilon(HighlightMarkdown.NORMAL);
}
break;
@@ -255,11 +400,11 @@ class HighlightMarkdown extends Highlighter {
if (this.bol) {
this.state = HighlightMarkdown.TICK_TICK;
} else {
- this.push("span", "incode");
+ this.push("code", "");
this.state = HighlightMarkdown.INCODE2;
}
} else {
- this.push('code', '');
+ this.push("code", "");
this.append(c);
this.state = HighlightMarkdown.INCODE;
}
@@ -461,8 +606,13 @@ class HighlightMarkdown extends Highlighter {
this.lang = '';
break;
case HighlightMarkdown.STAR:
+ case HighlightMarkdown.STRONG_STAR:
+ case HighlightMarkdown.EMPHASIS_STAR:
this.append('*');
break;
+ case HighlightMarkdown.EMPHASIS_STAR2:
+ this.append("**");
+ break;
case HighlightMarkdown.TICK:
this.append('`');
break;
@@ -512,6 +662,18 @@ class HighlightMarkdown extends Highlighter {
this.text = '';
this.href = '';
break;
+ case HighlightMarkdown.TILDE:
+ this.append('~');
+ break;
+ case HighlightMarkdown.SPACE:
+ for (let i = 0; i < this.spaces; ++i)
+ this.append(' ');
+ break;
+ case HighlightMarkdown.OLNAME:
+ case HighlightMarkdown.OLNAME_DOT:
+ this.append(this.olname);
+ this.olname = '';
+ break;
default:
break;
}
diff --git a/llamafile/server/www/highlight_ruby.js b/llamafile/server/www/highlight_ruby.js
index 2ac835ea..cc39088d 100644
--- a/llamafile/server/www/highlight_ruby.js
+++ b/llamafile/server/www/highlight_ruby.js
@@ -651,7 +651,7 @@ class HighlightRuby extends Highlighter {
}
break;
- case PERCENT_HASH_DOLLAR:
+ case HighlightRuby.PERCENT_HASH_DOLLAR:
if (HighlightRuby.is_dollar_one(c)) {
this.append('#');
this.push("strong", "");
@@ -672,7 +672,7 @@ class HighlightRuby extends Highlighter {
}
break;
- case PERCENT_HASH_DOLLAR_WORD:
+ case HighlightRuby.PERCENT_HASH_DOLLAR_WORD:
if (HighlightRuby.isident(c)) {
this.append(c);
} else {
diff --git a/llamafile/server/www/index.html b/llamafile/server/www/index.html
index 43cad884..6d3c10df 100644
--- a/llamafile/server/www/index.html
+++ b/llamafile/server/www/index.html
@@ -21,7 +21,7 @@
<span></span>
</div>
<div class="chat-input-container">
- <input type="text" class="chat-input" id="chat-input" placeholder="Type your message..." autocomplete="off">
+ <textarea class="chat-input" id="chat-input" placeholder="Type your message..." rows="1" autocomplete="off"></textarea>
<button class="send-button" id="send-button">Send</button>
<button class="stop-button" id="stop-button" style="display:none">Stop</button>
</div>
diff --git a/llamafile/server/www/test/test.html b/llamafile/server/www/test/test.html
new file mode 100644
index 00000000..7723b8d2
--- /dev/null
+++ b/llamafile/server/www/test/test.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html lang="en">
+<meta charset="utf-8">
+<link rel="stylesheet" href="../highlight.css">
+<div id="code"></div>
+
+<script src="../ctype.js"></script>
+<script src="../clipboard.js"></script>
+<script src="../highlight.js"></script>
+<script src="../highlight_txt.js"></script>
+<script src="../highlight_markdown.js"></script>
+<script src="../highlight_cpp.js"></script>
+<script src="../highlight_c.js"></script>
+<script src="../highlight_d.js"></script>
+<script src="../highlight_cxx.js"></script>
+<script src="../highlight_ada.js"></script>
+<script src="../highlight_asm.js"></script>
+<script src="../highlight_basic.js"></script>
+<script src="../highlight_cobol.js"></script>
+<script src="../highlight_csharp.js"></script>
+<script src="../highlight_css.js"></script>
+<script src="../highlight_forth.js"></script>
+<script src="../highlight_fortran.js"></script>
+<script src="../highlight_go.js"></script>
+<script src="../highlight_haskell.js"></script>
+<script src="../highlight_html.js"></script>
+<script src="../highlight_java.js"></script>
+<script src="../highlight_js.js"></script>
+<script src="../highlight_julia.js"></script>
+<script src="../highlight_kotlin.js"></script>
+<script src="../highlight_ld.js"></script>
+<script src="../highlight_lisp.js"></script>
+<script src="../highlight_lua.js"></script>
+<script src="../highlight_m4.js"></script>
+<script src="../highlight_make.js"></script>
+<script src="../highlight_matlab.js"></script>
+<script src="../highlight_ocaml.js"></script>
+<script src="../highlight_pascal.js"></script>
+<script src="../highlight_perl.js"></script>
+<script src="../highlight_php.js"></script>
+<script src="../highlight_python.js"></script>
+<script src="../highlight_r.js"></script>
+<script src="../highlight_ruby.js"></script>
+<script src="../highlight_rust.js"></script>
+<script src="../highlight_scala.js"></script>
+<script src="../highlight_shell.js"></script>
+<script src="../highlight_sql.js"></script>
+<script src="../highlight_swift.js"></script>
+<script src="../highlight_tcl.js"></script>
+<script src="../highlight_tex.js"></script>
+<script src="../highlight_typescript.js"></script>
+<script src="../highlight_zig.js"></script>
+<script src="../highlight_cmake.js"></script>
+
+<script src="test.js"></script>
diff --git a/llamafile/server/www/test/test.js b/llamafile/server/www/test/test.js
new file mode 100644
index 00000000..2a78372c
--- /dev/null
+++ b/llamafile/server/www/test/test.js
@@ -0,0 +1,21 @@
+const xhr = new XMLHttpRequest();
+const lang = 'markdown';
+xhr.open('GET', 'test.md');
+
+xhr.onload = function() {
+ if (xhr.status == 200) {
+ let code = document.getElementById('code');
+ let hdom = new HighlightDom(code);
+ const h = Highlighter.create(lang, hdom);
+ h.feed(xhr.responseText);
+ h.flush();
+ } else {
+ throw new Error(`HTTP error! status: ${xhr.status}`);
+ }
+};
+
+xhr.onerror = function() {
+ throw new Error('Network error');
+};
+
+xhr.send();
diff --git a/llamafile/server/www/test/test.md b/llamafile/server/www/test/test.md
new file mode 100644
index 00000000..cd2c47ff
--- /dev/null
+++ b/llamafile/server/www/test/test.md
@@ -0,0 +1,70 @@
+1. hi
+ - there
+
+bold: **bold**
+italic: *italic*
+strike: ~~strike~~
+bold+italic: ***bold***
+italic→bold: *hi***there**
+bold→italic: **hi***there*
+italic+strike: *~~strike~~*
+bold+strike: **~~strike~~**
+bold+italic+strike: ***~~strike~~***
+code: `plain`, *`italic`*, **`bold`**
+code+tick: ```left``, ``right```
+link: [link **bold** and *italic* stuff](https://google.com)
+escapable: \! \# \( \)\* \+ \- \. \< \> \[ \\ \[ \] \_ \` \{ \| \}
+non-escapable: \a \0 \Z \~
+
+* one
+ * two
+ - three
+- one
+
+¶1
+lorem ipsum
+dolor sit amet
+
+¶2
+consectetur adipiscing elit
+sed do eiusmod tempor incididunt
+
+***
+
+more text <http://google.com> link
+
+***
+
+```cpp
+#include <iostream>
+
+int main() {
+ // Declare a variable to store an integer
+ int age = 25;
+
+ // Print a message to the console
+ std::cout << "Hello, world! My name is AI, and I am " << age << " years old." << std::endl;
+
+ return 0;
+}
+```
+
+**Explanation:**
+
+1. **`#include <iostream>`:** This line includes the `iostream` library, which provides input and output functionalities in C++. It allows us to use objects like `std::cout` for printing to the console.
+
+2. **`int main() { ... }`:** This defines the `main` function, which is the entry point of any C++ program. The code inside the curly braces `{}` will be executed when the program runs.
+
+3. **`int age = 25;`:** This line declares an integer variable named `age` and initializes it with the value 25.
+
+4. **`std::cout << "Hello, world! My name is AI, and I am " << age << " years old." << std::endl;`:** This line prints a message to the console. Let's break it down:
+ - `std::cout` is the standard output stream object.
+ - `<<` is the insertion operator, used to send data to the output stream.
+ - `"Hello, world! My name is AI, and I am "` is a string literal that will be printed as is.
+ - `age` is the variable we declared earlier. Its value (25) will be inserted into the output stream.
+ - `" years old."` is another string literal.
+ - `std::endl` inserts a newline character, moving the cursor to the next line for any subsequent output.
+
+5. **`return 0;`:** This line indicates that the program executed successfully. Returning 0 from the `main` function is a convention in C++ to signal successful execution.
+
+**In summary:** This code snippet declares a variable, assigns it a value, and then prints a message to the console including the variable's value. It demonstrates basic C++ syntax for variable declaration, output, and program structure.