A generic content parser based on the devto markdown + frontmatter format, with liquid tag support

Related tags

Code Analysis parsed
Overview

Parsed

A generic content parser based on the devto post format, with front matter and liquid tag support. Parsed uses league/commonmark as base markdown parser.

Current liquid tags implemented:

  • HTML Video embed (mp4): {% video path_to_video.mp4 %}
  • HTML Audio embed (mp3): {% audio path_to_audio.mp3 %}
  • Twitter embed: {% twitter tweet_id %}
  • Youtube video embed: {% youtube video_id %}
  • GitHub File (Gists not supported atm): {% github full_path_to_repo_file %}

More to come, contributions welcome.

Installation

composer require librarianphp/parsed

Usage Examples

<?php
use Parsed\Content;
use Parsed\ContentParser;

$content = "---\n";
$content .= "title: Content Title\n";
$content .= "description: My Description\n";
$content .= "custom: custom\n";
$content .= "---\n";
$content .= "## Testing";

$article = new Content($content);
$article->parse(new ContentParser(), true);

print_r($article);
Parsed\Content Object
(
    [raw] => ---
title: Content Title
description: My Description
custom: custom
---
## Testing
    [front_matter] => Array
        (
            [title] => Content Title
            [description] => My Description
            [custom] => custom
        )

    [body_markdown] => ## Testing
    [body_html] => <h2>Testing</h2>
)

Obtaining Front Matter

There are two methods to work with the front matter: frontMatterHas and frontMatterGet:

$article = new Content($content);
$article->parse(new ContentParser(), true);

if ($article->frontMatterHas('title')) {
    return $article->frontMatterGet('title');
}

Creating Custom Liquid Tags

Liquid tags are classes that implement the CustomTagParserInterface. They need to implement a method named parse, which receives the string provided to the liquid tag when called from the markdown file. For instance, this is the full code for the video liquid tag parser class:

<?php
#src/CustomTagParser/VideoTagParser.php

namespace Parsed\CustomTagParser;

use Parsed\CustomTagParserInterface;

class VideoTagParser implements CustomTagParserInterface
{
    public function parse($tag_value, array $params = [])
    {
        return "<video controls>" .
         "<source src=\"$tag_value\" type=\"video/mp4\">" .
         "Your browser does not support the video tag." .
         "</video>";
    }
}

You'll have to include your custom tag parser class within the ContentParser:

$parser = new \Parsed\ContentParser();
$parser->addCustomTagParser('video', new VideoTagParser());

Note: The built-in tag parsers are already registered within ContentParser. These are: video, audio, twitter, youtube and github.

For instance, if you have in your markdown:

{% video /videos/test.mp4 %}

It will convert to the tag into the following code:

<video controls>
   <source src="/videos/test.mp4" type="video/mp4">
    Your browser does not support the video tag.
</video>

Tests

Parsed uses Pest as testing framework. To run the tests:

./vendor/bin/pest
You might also like...
Liquid template engine for PHP

Liquid is a PHP port of the Liquid template engine for Ruby, which was written by Tobias Lutke. Although there are many other templating engines for PHP, including Smarty (from which Liquid was partially inspired)

Tag support for Laravel Eloquent models - Taggable Trait

Laravel Taggable Trait This package is not meant to handle javascript or html in any way. This package handles database storage and read/writes only.

A simple regex-based Markdown parser in PHP

Slimdown A simple regex-based Markdown parser in PHP. Supports the following elements (and can be extended via Slimdown::add_rule()): Headers Links Bo

Pico disk, Not need any database, support html5, support mp3, mp4, support streaming media, support AriaNg
Pico disk, Not need any database, support html5, support mp3, mp4, support streaming media, support AriaNg

Nano netdisk, Now changed to pico disk. Pico disk,does not need any database, support html5, support mp3, mp4, support streaming media, support AriaNg.

A proof-of-concept parser for the SMART Health Cards format.

SMART Health Cards parser A proof-of-concept parser for the SMART Health Cards format. This is not intended for production use. I just hacked this tog

🛬🧾 A PHP8 TacView ACMI file format parser

A PHP8 TacView ACMI file format parser This package offers parsing support for TacView ACMI flight recordings version 2.1, it follows the standard des

Better Markdown Parser in PHP
Better Markdown Parser in PHP

Parsedown Better Markdown Parser in PHP - Demo. Features One File No Dependencies Super Fast Extensible GitHub flavored Tested in 5.3 to 7.3 Markdown

Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.
Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.

league/commonmark league/commonmark is a highly-extensible PHP Markdown parser created by Colin O'Dell which supports the full CommonMark spec and Git

A super fast, highly extensible markdown parser for PHP

A super fast, highly extensible markdown parser for PHP What is this? A set of PHP classes, each representing a Markdown flavor, and a command line to

A New Markdown parser for PHP5.4

Ciconia - A New Markdown Parser for PHP The Markdown parser for PHP5.4, it is fully extensible. Ciconia is the collection of extension, so you can rep

Better Markdown Parser in PHP
Better Markdown Parser in PHP

Parsedown Better Markdown Parser in PHP - Demo. Features One File No Dependencies Super Fast Extensible GitHub flavored Tested in 5.3 to 7.3 Markdown

Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.
Highly-extensible PHP Markdown parser which fully supports the CommonMark and GFM specs.

league/commonmark league/commonmark is a highly-extensible PHP Markdown parser created by Colin O'Dell which supports the full CommonMark spec and Git

A super lightweight Markdown parser for PHP projects and applications.

A speedy Markdown parser for PHP applications. This is a super lightweight Markdown parser for PHP projects and applications. It has a rather verbose

DBML parser for PHP8. It's a PHP parser for DBML syntax.
DBML parser for PHP8. It's a PHP parser for DBML syntax.

DBML parser written on PHP8 DBML (database markup language) is a simple, readable DSL language designed to define database structures. This page outli

php html parser,类似与PHP Simple HTML DOM Parser,但是比它快好几倍

HtmlParser php html解析工具,类似与PHP Simple HTML DOM Parser。 由于基于php模块dom,所以在解析html时的效率比 PHP Simple HTML DOM Parser 快好几倍。 注意:html代码必须是utf-8编码字符,如果不是请转成utf-8

It's MX Player API gives All Content in JSON format

💞 MXPlayer API 🎵 🍻 MXPlayer API Can get Streaming URLs and Other Data in JSON Format From mxplayer.in links for Streaming 👑 How to Use : 🔐 Method

👮 A PHP desktop/mobile user agent parser with support for Laravel, based on Mobiledetect
👮 A PHP desktop/mobile user agent parser with support for Laravel, based on Mobiledetect

Agent A PHP desktop/mobile user agent parser with support for Laravel, based on Mobile Detect with desktop support and additional functionality. Insta

A Zabbix 5.4 module to group items under Monitoring -> Latest data per Tag as it used to be with Application grouping in previous versions of Zabbix
A Zabbix 5.4 module to group items under Monitoring - Latest data per Tag as it used to be with Application grouping in previous versions of Zabbix

zabbix-module-latest-data Written according to Zabbix official documentation https://www.zabbix.com/documentation/current/manual/modules A Zabbix 5.4

Bracket and tag highlighter for Sublime Text
Bracket and tag highlighter for Sublime Text

BracketHighlighter Bracket Highlighter matches a variety of brackets such as: [], (), {}, "", '', tag/tag, and even custom brackets. This was orig

Releases(0.3.7)
  • 0.3.7(Mar 16, 2022)

  • 0.3.6(Dec 14, 2021)

  • 0.3.5(Dec 14, 2021)

  • 0.3.4(May 10, 2021)

  • 0.3.3(May 5, 2021)

    Version 0.3.3 fixes a bug in ContentParser that wouldn't allow for parsing markdown when a front matter was not set within the content object.

    Source code(tar.gz)
    Source code(zip)
  • 0.3.2(Apr 30, 2021)

  • 0.3.1(Apr 30, 2021)

  • 0.3.0(Apr 29, 2021)

    This version might cause a few backwards compatibility breaks, mostly in tests because the new parsed html comes with line breaks. I'm moving away from erusev's markdown parser to league/commonmark, since that offers extended markdown support (inline code, for instance, wasn't supported by the former dependency).

    • moved to league/commonmark for markdown parsing
    • adjusted video and audio tags to remove hardcoded media directories
    • updated readme to include more examples, and how to create custom tag parser
    Source code(tar.gz)
    Source code(zip)
  • 0.2.1(Apr 28, 2021)

  • 0.2.0(Apr 13, 2021)

    Updates:

    • parse() method now has an additional parameter to indicate if you want a full parse including markdown + liquid tags, or just a "lazy parse" to build the front matter array from a full post. Default is set to "false" for lazy loading, which performs much better for content listing.
    • added GH workflow for running tests and php_cs_fixer
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Apr 12, 2021)

Owner
null
A web tool to explore the ASTs generated by PHP-Parser.

phpast.com A web tool to explore the ASTs generated by PHP-Parser. About This web tool provides a GUI for exploring the AST of your PHP code. You can

Ryan Chandler 23 Nov 29, 2022
A full-scale PHP sandbox class that utilizes PHP-Parser to prevent sandboxed code from running unsafe code

A full-scale PHP 7.4+ sandbox class that utilizes PHP-Parser to prevent sandboxed code from running unsafe code. It also utilizes FunctionParser to di

Corveda 192 Dec 10, 2022
A project to add Psalm support for Drupal for security testing, focused only on taint analysis.

psalm-plugin-drupal A Drupal integration for Psalm focused on security scanning (SAST) taint analysis. Features Stubs for sinks, sources, and sanitize

Samuel Mortenson 38 Aug 29, 2022
A toolbar for Laravel Telescope, based on the Symfony Web Profiler.

Laravel Telescope Toolbar Extends Laravel Telescope to show a powerful Toolbar See https://github.com/laravel/telescope Install First install Telescop

Fruitcake 733 Dec 30, 2022
TypeResolver - A PSR-5 based resolver of Class names, Types and Structural Element Names

TypeResolver and FqsenResolver The specification on types in DocBlocks (PSR-5) describes various keywords and special constructs but also how to stati

phpDocumentor 9k Dec 29, 2022
Parser for Markdown and Markdown Extra derived from the original Markdown.pl by John Gruber.

PHP Markdown PHP Markdown Lib 1.9.0 - 1 Dec 2019 by Michel Fortin https://michelf.ca/ based on Markdown by John Gruber https://daringfireball.net/ Int

Michel Fortin 3.3k Jan 1, 2023
Parser for Markdown and Markdown Extra derived from the original Markdown.pl by John Gruber.

PHP Markdown PHP Markdown Lib 1.9.0 - 1 Dec 2019 by Michel Fortin https://michelf.ca/ based on Markdown by John Gruber https://daringfireball.net/ Int

Michel Fortin 3.3k Jan 1, 2023
A full PHP implementation of Minecraft's Named Binary Tag (NBT) format.

php-nbt A full PHP implementation of Minecraft's Named Binary Tag (NBT) format. In contrast to other implementations, this library provides full suppo

Aternos 8 Oct 7, 2022
A package that uses blade templates to control how markdown is converted to HTML inside Laravel, as well as providing support for markdown files to Laravel views.

Install Install via composer. $ composer require olliecodes/laravel-etched-blade Once installed you'll want to publish the config. $ php artisan vendo

Ollie Codes 19 Jul 5, 2021
A PHP port of Ruby's Liquid Templates

Liquid template engine for PHP Liquid is a PHP port of the Liquid template engine for Ruby, which was written by Tobias Lutke. Although there are many

Alexander Guz 141 Nov 4, 2022