Class: SmartMarkdown

SmartMarkdown(config)

SmartMarkdown is a class designed to parse and manipulate markdown content based on specified configurations. It provides functionalities to extract specific blocks of text based on heading paths, handle exclusions of certain headings, and manage the size of text blocks according to maximum and minimum character limits.

Constructor

new SmartMarkdown(config)

Creates an instance of SmartMarkdown with the given configuration.

Parameters:
Name Type Description
config Object

User-defined configuration settings.

Source:

Members

excluded_headings

Retrieves the list of headings to be excluded from parsing, if any.

Source:

(static) defaults

Returns the default configuration for the SmartMarkdown parser.

Source:

Methods

file_path_to_breadcrumbs(file_path) → {string}

Converts a file path to a breadcrumb string format.

Parameters:
Name Type Description
file_path string

The file path to convert.

Source:
Returns:

The breadcrumb string.

Type
string

get_block_from_path(block_path, markdown, opts) → {string}

Extracts a specific block of markdown based on a heading path.

Parameters:
Name Type Description
block_path string

The path to the block, specified as a series of headings.

markdown string

The markdown content to parse.

opts Object

Options for block extraction, such as character limits per line.

Source:
Returns:

The extracted block of markdown text.

Type
string

get_headings_meta(content) → {Array}

Analyzes the markdown content to extract metadata about each heading.

Parameters:
Name Type Description
content string

The markdown content to analyze.

Source:
Returns:

An array of objects containing metadata about each heading.

Type
Array

handle_duplicate_headings(acc)

Handles duplicate headings by appending a unique identifier to the heading path.

Parameters:
Name Type Description
acc Object

The accumulator object used in reduce function.

Source:

heading_level(line) → {number}

Determines the level of a heading based on the number of '#' characters.

Parameters:
Name Type Description
line string

The heading line to evaluate.

Source:
Returns:

The level of the heading.

Type
number

is_content_line(line) → {boolean}

Determines if a line of text should be considered as content.

Parameters:
Name Type Description
line string

The line of text to evaluate.

Source:
Returns:

True if the line is content, false otherwise.

Type
boolean

is_heading(line, line) → {boolean|boolean}

Checks if a line is a heading.

Parameters:
Name Type Description
line string

The line to check.

line string

The line to check.

Source:
Returns:
  • True if the line is a heading, false otherwise.

    Type
    boolean
  • True if the line is a heading, false otherwise.

    Type
    boolean

output_block(acc)

Outputs the current block into the structured blocks array after validation.

Parameters:
Name Type Description
acc Object

The accumulator object used in reduce function.

Source:

parse(params) → {Object}

Parses the markdown content and organizes it into structured blocks based on headings.

Parameters:
Name Type Description
params Object

Parameters containing content and optional file path.

Source:
Returns:

An object containing parsed blocks and other metadata.

Type
Object

validate_block_path(block_path) → {boolean}

Validates if the block path is correctly formatted to include at least one heading.

Parameters:
Name Type Description
block_path string

The block path to validate.

Source:
Returns:

True if the block path is valid, false otherwise.

Type
boolean

validate_heading(headings) → {boolean}

Validates a heading against the list of excluded headings.

Parameters:
Name Type Description
headings string

The heading to validate.

Source:
Returns:

True if the heading is not excluded, false if it is.

Type
boolean