Modules@robinpath/markdown
markdown

@robinpath/markdown

0.1.2Node.jsPublic

Markdown processing: convert to HTML, extract headings, links, images, code blocks, frontmatter, and tables

Markdown

Markdown processing: convert to HTML, extract headings, links, images, code blocks, frontmatter, and tables

Package: @robinpath/markdown | Category: Utility | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the markdown module when you need to:

  • Convert markdown to basic HTML -- Use markdown.toHtml to perform this operation
  • Extract all headings with their levels -- Use markdown.extractHeadings to perform this operation
  • Extract all links -- Use markdown.extractLinks to perform this operation
  • Extract all images -- Use markdown.extractImages to perform this operation
  • Extract fenced code blocks -- Use markdown.extractCodeBlocks to perform this operation

Quick Reference

FunctionDescriptionReturns
toHtmlConvert markdown to basic HTMLHTML string
extractHeadingsExtract all headings with their levelsArray of {level, text}
extractLinksExtract all linksArray of {text, url}
extractImagesExtract all imagesArray of {alt, src}
extractCodeBlocksExtract fenced code blocksArray of {language, code}
stripMarkdownStrip all markdown formatting to plain textPlain text
extractFrontmatterParse YAML frontmatter from markdownKey-value object or null
extractTodosExtract task list itemsArray of {text, checked}
tableToArrayParse a markdown table into array of objectsArray of row objects
wordCountCount words in markdown (stripping formatting)Word count

Functions

toHtml

Convert markdown to basic HTML

Module: markdown | Returns: string -- HTML string

markdown.toHtml "# Hello"
ParameterTypeRequiredDescription
markdownstringYesMarkdown string

extractHeadings

Extract all headings with their levels

Module: markdown | Returns: array -- Array of {level, text}

markdown.extractHeadings $md
ParameterTypeRequiredDescription
markdownstringYesMarkdown string

extractLinks

Extract all links

Module: markdown | Returns: array -- Array of {text, url}

markdown.extractLinks $md
ParameterTypeRequiredDescription
markdownstringYesMarkdown string

extractImages

Extract all images

Module: markdown | Returns: array -- Array of {alt, src}

markdown.extractImages $md
ParameterTypeRequiredDescription
markdownstringYesMarkdown string

extractCodeBlocks

Extract fenced code blocks

Module: markdown | Returns: array -- Array of {language, code}

markdown.extractCodeBlocks $md
ParameterTypeRequiredDescription
markdownstringYesMarkdown string

stripMarkdown

Strip all markdown formatting to plain text

Module: markdown | Returns: string -- Plain text

markdown.stripMarkdown $md
ParameterTypeRequiredDescription
markdownstringYesMarkdown string

extractFrontmatter

Parse YAML frontmatter from markdown

Module: markdown | Returns: object -- Key-value object or null

markdown.extractFrontmatter $md
ParameterTypeRequiredDescription
markdownstringYesMarkdown with frontmatter

extractTodos

Extract task list items

Module: markdown | Returns: array -- Array of {text, checked}

markdown.extractTodos $md
ParameterTypeRequiredDescription
markdownstringYesMarkdown string

tableToArray

Parse a markdown table into array of objects

Module: markdown | Returns: array -- Array of row objects

markdown.tableToArray $table
ParameterTypeRequiredDescription
markdownstringYesMarkdown table

wordCount

Count words in markdown (stripping formatting)

Module: markdown | Returns: number -- Word count

markdown.wordCount $md
ParameterTypeRequiredDescription
markdownstringYesMarkdown string

Error Handling

All functions throw on failure. Common errors:

ErrorCause
(standard errors)Check function parameters and authentication
@desc "To html and validate result"
do
  set $result as markdown.toHtml "# Hello"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. Multi-step Markdown workflow

Chain multiple markdown operations together.

@desc "To html, extract headings, and more"
do
  set $r_toHtml as markdown.toHtml "# Hello"
  set $r_extractHeadings as markdown.extractHeadings $md
  set $r_extractLinks as markdown.extractLinks $md
  print "All operations complete"
enddo

2. Safe toHtml with validation

Check results before proceeding.

@desc "To html and validate result"
do
  set $result as markdown.toHtml "# Hello"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.2latest1 months ago
Install
$ robinpath add @robinpath/markdown

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.2
LicenseMIT
Unpacked Size4.7 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

utilities