bx-markdown
bx-markdown: Markdown Support
Installation
install-bx-module bx-markdown
# CommandBox
box install bx-markdown
BIFs
markdown( txt ) — Markdown → HTML
Converts a Markdown string to HTML using the Flexmark library.
html = markdown( "# Hello World" )
// Returns: <h1>Hello World</h1>
html = markdown( "**Bold** and _italic_ text" )
// Returns: <p><strong>Bold</strong> and <em>italic</em> text</p>
// Multi-line markdown
content = "
# Title
A paragraph with **bold** text.
- Item one
- Item two
- Item three
"
html = markdown( content )
HtmlToMarkdown( markup ) — HTML → Markdown
Converts an HTML string to Markdown.
md = HtmlToMarkdown( "<h1>Hello World</h1>" )
// Returns: # Hello World
md = HtmlToMarkdown( "<p><strong>Bold</strong> and <em>italic</em></p>" )
// Returns: **Bold** and _italic_
// Convert a full HTML page body to Markdown
body = "<h2>Section</h2><p>Content with a <a href='https://boxlang.io'>link</a>.</p>"
md = HtmlToMarkdown( body )
Common Usage Patterns
// Render user-authored markdown content safely
post = queryExecute( "SELECT content FROM posts WHERE id = :id", { id: postId }, { returntype: "array" } )
renderedHtml = markdown( post[1].content )
writeOutput( renderedHtml )
// Store HTML from markdown in DB
rawMarkdown = form.postContent
storedHtml = markdown( rawMarkdown )
queryExecute(
"INSERT INTO posts (markdown_content, html_content) VALUES (:md, :html)",
{ md: rawMarkdown, html: storedHtml }
)
// Read markdown from a file and render
content = fileRead( "/app/docs/readme.md" )
html = markdown( content )
Common Pitfalls
- ✅
markdown()returns an HTML fragment, not a full HTML document — embed it inside your page layout - ❌ Don't output user-provided markdown directly without sanitizing the resulting HTML (consider pairing with
bx-jsoupfor XSS protection) - ✅
HtmlToMarkdown()is useful for migrating rich-text editor content to a markdown-based system
More from ortus-boxlang/skills
boxlang-functional-programming
Use this skill when working with BoxLang lambdas, closures, arrow functions, higher-order functions, functional array/struct pipelines (map, filter, reduce, flatMap, groupBy, etc.), destructuring, or spread syntax.
10boxlang-code-reviewer
Use this skill when reviewing BoxLang code for quality, correctness, security vulnerabilities, performance issues, style violations, or when providing structured code review feedback following BoxLang best practices and security guidelines.
9boxlang-best-practices
Use this skill when writing, reviewing, or improving BoxLang code to ensure it follows community best practices for naming, structure, scoping, error handling, performance, and maintainability.
9boxlang-classes-and-oop
Use this skill when writing BoxLang classes, components, interfaces, inheritance hierarchies, annotations, properties, constructors, or applying object-oriented design patterns in BoxLang.
9boxlang-web-development
Use this skill when building BoxLang web applications: Application.bx lifecycle, request/response handling, sessions, forms, REST APIs, HTTP clients, routing, CSRF protection, Server-Sent Events, or configuring CommandBox/MiniServer.
8boxlang-configuration
Use this skill when configuring BoxLang runtime settings via boxlang.json, setting environment variables for config overrides, configuring datasources, caches, executors, modules, logging, security, or schedulers — or when helping someone understand the BoxLang configuration system.
8