mpratt/luthor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mpratt/luthor

Composer 安装命令:

composer require mpratt/luthor

包简介

An extendable Markdown Lexer/Parser for PHP

README 文档

README

Build Status Scrutinizer Quality Score Code Coverage Latest Stable Version Total Downloads

** Warning: This library is not production ready **

Luthor is an extendable Markdown Lexer/Parser for PHP. It converts markdown text into HTML. In other words, what it does is, It reads the markdown text line by line and analyses its content. It uses a Lexer to tokenize each element and passes them to the parser. The Parser operates on that token and returns an HTML string.

The key feature of this library, is that you can extend the token map quite easily, giving you the hability to practically have custom notations and build your own flavored markdown. There are other cool things that can be easily done, like applying filters or modifying the way a token is handled or displayed. It also has a bunch of configuration options which can be used to change the behaviour of the library! See the Usage section for more information about how everything is done. Or better yet, hop into the source and take a peak.

Here is a quick list of supported markup:

  • Paragraphs and line breaks
  • Headers
  • Blockquotes
  • Code blocks and Fenced code blocks
  • Lists (starting with * , - , + , or 1. )
  • Horizontal Rules
  • Span Elements (links, emphasis, code, images, striked out text)
  • Element Escaping
  • Footnotes and Abbreviations
  • Special attributes on headers, links and images via {#id .class1 .class2}

The library works but is not stable enough to be used on production environments. In comparision with other markdown parsers, this one is slow! Very slow! And It takes indentation very seriously, maybe a little too much.

Im not giving support for this library, this was just a hobby project. Some parts of the library could be done more elegantly and perhaps later I will cleanup the codebase, but Im not making any promises.

I think the best alternative, if you are looking for an extandable markdown parser is Ciconia! Elegant and stable, requires PHP 5.4.

Requirements

  • PHP >= 5.3

Installation

Install with Composer

If you're using Composer to manage dependencies, you can use this library by creating a composer.json and adding this:

{
    "require": {
        "mpratt/luthor": "dev-master"
    }
}

Save it and run composer.phar install

Standalone Installation (without Composer)

Download the latest release or clone this repository, place the Lib/Luthor directory on your project. Afterwards, you only need to include the Autoload.php file.

    require '/path/to/Luthor/Autoload.php';
    $embera = new \Luthor\Luthor();

Or if you already have PSR-0 complaint autoloader, you just need to register Luthor

    $loader->registerNamespace('Luthor', 'path/to/Luthor');

Basic Usage

    $lex = new \Luthor\Luthor();
    echo $lex->parse('**I dont like Superman**');
    // <p><strong>I dont like Superman</strong></p>

In order to extend the lexer/parser you need to create a new class extending the InlineAdapter or BlockAdapter. Use the addExtension() method to register the extension

    class MyExtension extends \Luthor\Parser\Extensions\Adapters\InlineAdapter
    {
        protected $regex = '~\^([^ ]+)~A';
        public function parse()
        {
            return '<strong>' . $this->matches['1'] . '</strong>';
        }
    }

    $lex = new \Luthor\Luthor();
    $lex->addExtension(new MyExtension());
    echo $lex->parse('I love ^Luthor !');
    // <p>I love <strong>Luthor</strong>!</p>

Filters are runned when the text is already processed

    $lex = new \Luthor\Luthor();
    $lex->addFilter(function ($text){
        return str_replace('Hello', 'World', $text);
    });

    echo $lex->parse('Hello World!');
    // <p>World World!</p>

Take a look at the Lib or Tests directory in order to see other configuration options.

License

MIT For the full copyright and license information, please view the LICENSE file.

Why Oh' Why?

Yeah, I know right?, another markdown parser? really? - You know, there are days where you think to yourself, stuff like "hey, I wanna learn more about X, so Im going to write Y and see what happens"?, Well that happened to me a long time ago, and started coding this lexer/parser just for fun/learning. The thing is, I never finished it.

So one day I was digging around my "un-finished projects" folder and found about half of this code base and decided it was time to either finish it or delete it. I end up rewriting most of the code, there are bits here and there that could be done with more though in mind, but in the end I think it turned out not that bad.

Author

Hi! I'm Michael Pratt and I'm from Colombia!

My Personal Website is in spanish.

mpratt/luthor 适用场景与选型建议

mpratt/luthor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 1, 最近一次更新时间为 2013 年 11 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「parser」 「markdown」 「lexer」 「md」 「Mark down」 「extendable markdown」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mpratt/luthor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mpratt/luthor 我们能提供哪些服务?
定制开发 / 二次开发

基于 mpratt/luthor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-11-15