class

Hwaro::Content::Processors::Markdown

Inherits Hwaro::Content::Processors::Base / Reference / Object

Markdown processor implementation

Constants

ANCHOR_LINK_REGEX = /<(h[1-6])((?:[^>"']|"[^"]*"|'[^']*')*?(?<![\w-])id="([^"]+)"(?:[^>"']|"[^"]*"|'[^']*')*)>(.*?)<\/\1>/m

Regex for matching h1-h6 tags with IDs to insert anchor links. Attribute scans here and below are quote-aware (a &gt; inside a quoted value, e.g. title=&quot;a &gt; b&quot;, is legal HTML5 and must not end the tag) and the id key uses a (?&lt;![\w-]) guard so data-id= never counts as the element's id.

HEADING_TAG_REGEX = /<(h([1-6]))(\s(?:[^>"']|"[^"]*"|'[^']*')*)?>(.+?)<\/h\2>/im

Regex for post_process_html — lightweight replacements for XML.parse_html Matches

through
, capturing tag name, level digit, attributes, and inner HTML

HTML_TAG_STRIP_REGEX = /<[^>]+>/

Strips HTML tags to get plain text

ID_ATTR_REGEX = /(?<![\w-])id\s*=\s*["']([^"']+)["']/

Extracts id=&quot;value&quot; from an attribute string

IMG_LAZY_REGEX = /<img(?!(?:[^>"']|"[^"]*"|'[^']*')*(?<![\w-])loading\s*=)((?:[^>"']|"[^"]*"|'[^']*')*?)\s*\/?>/i

Matches &lt;img ...&gt; tags that do NOT already have a loading= attribute (the lookahead is quote-aware too, so a loading= sitting after a quoted &gt; is still seen, and data-loading= doesn't count).

KNOWN_FRONT_MATTER_KEYS = Set {"title", "description", "image", "draft", "template", "in_sitemap", "toc", "date", "updated", "render", "slug", "path", "aliases", "tags", "transparent", "generate_feeds", "paginate", "pagination_enabled", "sort_by", "reverse", "authors", "in_search_index", "insert_anchor_links", "page_template", "paginate_path", "redirect_to", "weight", "categories", "series", "series_weight", "expires", "paginate_by", "taxonomies", "cascade", "menus", "menu"}

Known front-matter keys (shared between TOML, YAML, and JSON parsers). Using a Set for O(1) lookup instead of Array#includes? O(n).

NON_TAXONOMY_ARRAY_KEYS = Set {"tags", "aliases", "authors"}

Array-typed front matter keys that are NOT taxonomies. These are excluded from automatic taxonomy extraction.

TOML_FRONT_MATTER_REGEX = /\A\+\+\+\s*\n(.*?\n?)^\+\+\+\s*$\n?(.*)\z/m

Regex for TOML front matter

YAML_FRONT_MATTER_REGEX = /\A---\s*\n(.*?\n?)^---\s*$\n?(.*)\z/m

Regex for YAML front matter

Instance methods

extensions

Returns file extensions this processor can handle

Source
name

Returns the unique name identifier for this processor

Source
parse(raw_content : String, file_path : String = "")

Returns parsed metadata and content

Source
priority

Priority for processor ordering (higher = runs first)

Source
process(content : String, context : ProcessorContext) : ProcessorResult

Process content and return transformed result

Source
render(content : String, highlight : Bool = true, safe : Bool = false, lazy_loading : Bool = false, emoji : Bool = false, markdown_config : Models::MarkdownConfig | Nil = nil, hooks : Content::Processors::RenderHooks::HookRenderContext | Nil = nil) : Tuple(String, Array(Models::TocHeader))

Renders Markdown to HTML and generates a Table of Contents Returns {html_content, toc_headers} @param highlight - whether to enable syntax highlighting for code blocks @param safe - if true, raw HTML will not be passed through (replaced by comments) @param lazy_loading - if true, adds loading=&quot;lazy&quot; to img tags @param emoji - if true, converts emoji shortcodes to emoji characters @param hooks - render-hook context; nil (the default) renders exactly as before this parameter existed.

Source
render_with_anchors(content : String, highlight : Bool = true, safe : Bool = false, anchor_style : String = "heading", lazy_loading : Bool = false, emoji : Bool = false, markdown_config : Models::MarkdownConfig | Nil = nil, hooks : Content::Processors::RenderHooks::HookRenderContext | Nil = nil) : Tuple(String, Array(Models::TocHeader))

Render with anchor links inserted into headings

Source