module BBS::Markdown
Markdown to ANSI line array renderer.
BBS::Markdown.to_lines(text, width:, theme:)
Returns an array of strings (one per terminal line) with embedded ANSI SGR codes, suitable for BBS::Widgets::ScrollView. Each inline span ends with the theme :text SGR so that trailing text keeps the right background.
Handled: headings, paragraphs, fenced code blocks, block quotes, bullet and numbered lists, horizontal rules, GFM tables, and inline links, code, bold and italic.
Constants
- BOLD
-
Bold text between double asterisks.
- BULLET_ITEM
-
A bullet list item: indent, a
-,*or+mark, and the text. - CODE_SPAN
-
Inlinecode between backticks. - CONTINUATION
-
An indented line that may continue a list item.
- DELIMITER_CELL
-
A cell of a table delimiter row: dashes with optional colons.
- ESCAPED
-
A backslash escape of a
Markdownpunctuation character. - HEADING
-
A heading: one to six
#, the text, optional closing marks. - ITALIC_STAR
-
Italic text between single asterisks, not inside a word.
- ITALIC_UNDERSCORE
-
Italic text between underscores, not inside a word.
- ITEM_START
-
The start of a bullet or numbered list item.
- LINE_BREAK
-
A line break in the source: LF or CRLF.
- LINK
-
A link
[text](url); the groups are the text and the url. - NUMBERED_ITEM
-
A numbered list item: indent, the number, and the text.
- QUOTE
-
A block quote line; the first group is the quoted text.
- RULE
-
A horizontal rule: three or more of the same
-,*or_. - STYLE_ROLES
-
The theme role each part of the output is styled with.
Public Class Methods
# File lib/bbs/markdown.rb, line 65 def self.to_lines(text, width:, theme:) styles = STYLE_ROLES.transform_values { |role| theme[role] } Renderer.new(width, styles).render(FrameBuffer.text(text).split(LINE_BREAK)) end
Renders the Markdown text as terminal lines.
- width
-
the line width in columns; paragraphs wrap and code lines are clipped to it
- theme
-
a
BBS::Theme(or a Hash) whose:text,:text_bright,:text_dim,:accentand:labelSGR styles colour the output
Returns an Array of String, one per line.