neoground / charm-markdown
Charm Markdown Module
Requires
- php: >=8.1
- erusev/parsedown: ^1.7
- erusev/parsedown-extra: ^0.8.1
- neoground/charm: ^3.1
README
Welcome to the charm-markdown module, a remarkable addition to the Charm Framework galaxy, designed to provide seamless integration of Markdown and YAML frontmatter functions. Whether you're a Markdown padawan or a seasoned YAML-Frontmatter Jedi, this module is the perfect companion for your Charm framework journey.
Harness the power of Charm's built-in Symfony/Yaml package and Parsedown + Parsedown-Extra for HTML creation, bringing balance to the Markdown Force in your application.
Installation
Begin your quest by adding charm-markdown to your project via Composer:
composer require neoground/charm-markdown
Next, install charm-markdown in your application:
bob cm:i neoground/charm-markdown
Usage
Awaken the charm-markdown Force by initializing it with a file or a string:
$filepath = C::Storage()->getDataPath() . DS . 'demo.md'; $doc = C::Markdown()->fromFile($filepath);
or
$doc = C::Markdown()->fromString('# Hello World');
Unlock the secrets of the Markdown galaxy by accessing:
$doc->getMarkdownContent();
to obtain the Markdown content part of the document$doc->getYaml();
to retrieve the YAML frontmatter data as an array (or an empty array if not set)$doc->getHtml();
to generate the HTML content, with Markdown Extra support and "id" tags added to each heading for easy anchoring$doc->getContentsList()
to get an array of all headings as an easy table of contents
Experience the power of charm-markdown with direct access:
This returns an array with keys yaml
(array) and markdown
(string), containing each part of the document:
$arr = C::Markdown()->separateMarkdownFromYaml($content);
Extract the YAML array directly from the content string as an array:
C::Markdown()->getYaml($content);
Obtain the Markdown part directly from the content string as a string:
C::Markdown()->getMarkdownContent($content);
Format the Markdown part of the content string as HTML:
C::Markdown()->toHtml($content);
Usage in Views
In Twig views you can output a markdown string directly as HTML with:
<div id="content">{{ markdownToHtml(markdownString)|raw }}</div>
Embrace the charm-markdown Force and embark on an epic adventure of Markdown and YAML mastery in your Charm Framework application. May the Markdown be with you!