Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
Markdown

A growing implementation of Markdown-related utilities based on GitHub Flavored Markdown (GFM). More...

Classes

class  sourcemeta::core::MarkdownError

Functions

SOURCEMETA_CORE_MARKDOWN_EXPORT auto sourcemeta::core::markdown_to_html (const std::string_view input, const bool safe=true, std::size_t maximum_input_bytes=MARKDOWN_MAXIMUM_INPUT_BYTES) -> std::string

Variables

constexpr std::size_t sourcemeta::core::MARKDOWN_MAXIMUM_INPUT_BYTES

Detailed Description

A growing implementation of Markdown-related utilities based on GitHub Flavored Markdown (GFM).

This functionality is included as follows:

#include <sourcemeta/core/markdown.h>

Class Documentation

◆ sourcemeta::core::MarkdownError

class sourcemeta::core::MarkdownError

An error that represents a Markdown conversion that would exceed one of the bounds on the size of its output

Inheritance diagram for sourcemeta::core::MarkdownError:
sourcemeta::core::Error

Public Member Functions

 MarkdownError (const StaticString message) noexcept
 Construct an error with the given message.
Public Member Functions inherited from sourcemeta::core::Error
auto message () const noexcept -> StaticString

Additional Inherited Members

Protected Member Functions inherited from sourcemeta::core::Error
 Error (const StaticString message) noexcept
 Construct the error given its message.

Function Documentation

◆ markdown_to_html()

SOURCEMETA_CORE_MARKDOWN_EXPORT auto sourcemeta::core::markdown_to_html ( const std::string_view input,
const bool safe = true,
std::size_t maximum_input_bytes = MARKDOWN_MAXIMUM_INPUT_BYTES ) -> std::string

Convert a Markdown string to an HTML fragment using GitHub Flavored Markdown (GFM) with all standard extensions enabled (tables, autolinks, strikethrough, tag filtering, and task lists). Raw HTML and dangerous links are suppressed by default, so the result is safe to render from untrusted input. Passing a false safe argument lets raw HTML and unsafe links pass through unchanged, which must only be done for trusted input. The specification lets link references and short table rows expand to an output far larger than the input, so the conversion throws MarkdownError once the rendered link references expand past the larger of 16 times the input size and 1,048,576 bytes, or once a table inserts more than 524,288 empty cells. A bound smaller than the default refuses a larger input outright, counted after a NUL or a malformed byte sequence has been replaced, so a repaired input may exceed a bound the written one meets. For example:

#include <sourcemeta/core/markdown.h>
#include <cassert>
const auto result{sourcemeta::core::markdown_to_html("Hello **world**")};
assert(result == "<p>Hello <strong>world</strong></p>\n");
SOURCEMETA_CORE_MARKDOWN_EXPORT auto markdown_to_html(const std::string_view input, const bool safe=true, std::size_t maximum_input_bytes=MARKDOWN_MAXIMUM_INPUT_BYTES) -> std::string

Variable Documentation

◆ MARKDOWN_MAXIMUM_INPUT_BYTES

std::size_t sourcemeta::core::MARKDOWN_MAXIMUM_INPUT_BYTES
inlineconstexpr
Initial value:
{
std::numeric_limits<std::uint32_t>::max()}

The most input bytes accepted when a caller names no bound of its own, which is what the offsets the parser addresses its input through can reach, so a caller may name a smaller bound but never a larger one.