neoground/charm-markdown

Charm Markdown Module

1.2 2023-07-08 12:59 UTC

This package is auto-updated.

Last update: 2024-04-04 17:43:18 UTC


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

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!