tomakee/laravel-markdown-wrapper
Composer 安装命令:
composer require tomakee/laravel-markdown-wrapper
包简介
Simple Laravel wrapper class for markdown parser.
README 文档
README
Simple Laravel wrapper class for markdown parser such as michelf/php-markdown or cebe/markdown, etc.
This package is just wrapper classes for Laravel, it won't parse markdown by itself, for that you need a actual parser. Add your favorite Markdown Parser.
Environment
- PHP >= 5.6
- Laravel >= 5.4
- Markdown Parser
Functions
- Blade directives:
@markdown,@endmarkdown,@markdownFile. - Laravel helpers:
markdown(),markdown_config(),markdown_file(),markdown_capture(). - Laravel facade:
Markdown::parse(),Markdown::setConfig(),Markdown::file(),Markdown::start(),Markdown::end() - Wrapper class main:
Tomakee\Markdown\Parser
Howto Install PHP Composer
You need to install php coomposer first if you don't have it in your system.
#install composer (Linux or MacOS) curl -sS https://getcomposer.org/installer | php #move composer.phar into somewhere accessable (such as /usr/local/bin) mv composer.phar /usr/local/bin/composer chmod 755 /usr/local/bin/composer
Howto Create Laravel Project
After install php composer, you need to create a Laravel project.
You can skip this step if you simply add it in your project.
composer create-project --prefer-dist laravel/laravel LARAVEL_PROJECT_DIR #or with version composer create-project --prefer-dist laravel/laravel "5.4.*" LARAVEL_PROJECT_DIR
Howto Install
After install Laravel, you can install this package with follow commands.
cd LARAVEL_PROJECT_DIR
composer require tomakee/laravel-markddown-wrapper
php artisan vendor:publish
Add Laravel Service Provider into config/app.php.
//config/app.php return [ 'providers' => [ ... Tomakee\Markdown\MarkdownServiceProvider::class, ], ... ];
And add your favorite Markdown Parser such as:
cd LARAVEL_PROJECT_DIR composer require michelf/php-markdown #or composer require cebe/markdown
Blade Directives
You can create view mixed markdown and Blade.
For example:
single line
@markdown('some markdown text.')
multiple line
@markdown
some markdown text.
[link text](/link/path)
@endmarkdown
include markdown file
@markdownFile('path.to.markdownfile') {{-- path format is same as Laravel view. --}}
{{--
You can set different resources path.
But if your project always use different path from default,
change the config setting (app/config/markdown.php).
--}}
@markdownFile('path.to.markdownfile', [resources path,,,]);
Laravel Helpers
Anywhere Controller, etc., you can access to the wrapper class.
markdown()
//parse markdown text $html = markdown('some markdown text.');
markdown_config()
//change parser config $parser = markdown_config('hard_wrap', false); $html = $parser->parse('some markdown text.'); //change parser config and parse markdown $html = markdown_config(['hard_wrap' => false, 'code_class_prefix' => 'prefix-']) ->parse('some markdown text.');
markdown_file()
//parse markdown file $html = markdown_file('path.to.markdownfile'); //path format is same as Laravel view. //You can set different resources path. //But if your project always use different path from default, //change the config setting (app/config/markdown.php). $html = markdown_file('path.to.markdownfile', [resources path,,,,]);
markdown_capture()
$html = markdown_capture(function () { echo 'some markdown text.'; }); //with params $html = markdown_capture(function () use ($args1, $args2) { echo $args1 . $args2 . 'some markdown text.'; });
Laravel Facade
In your Controller, etc., you can access to the wrapper class with Laravel Facade.
Import markdown facade
To use Laravel Facade, first, you need import Markdown Facade.
Class path:
use Tomakee\Markdown\Facades\Markdown;
Markdown::parse()
//parse markdown text $html = Markdown::parse('some markdown text.');
Markdown::file()
//parse markdown file $html = Markdown::file('path.to.markdownfile'); //path format is same as Laravel view. //You can set different resources path. //But if your project always use different path from default, //change the config setting (app/config/markdown.php). $html = Markdown::file('path.to.markdownfile', [resources path,,,]);
Markdown::setConfig()
//change parser config $html = Markdown::setConfig('hard_wrap', false) ->parse('some markdown text.'); //temporary change parser config $html = Markdown::setConfig('hard_wrap', false)->parse('some markdown text.'); Markdown::setConfig('hard_wrap', true);
Markdown::PARSER_METHOD()
It's accessable to the original parser method directly through to __call() magic method:
//direct access to the original parser methods if you need Markdown::PARSER_METHOD();
Laravel App Container
It can access wrapper class instance from binded application container. See this php: src/MarkdownServiceProvider.php.
Tomakee\Markdown\MarkdownServiceProvider::register()
app('markdown'), app('Tomakee\Markdown\Parser')
//get instance $instance = app('markdown'); //or $instance = app('Tomakee\Markdown\Parser');
app('markdown')->parse()
//parse markdown text $html = app('markdown')->parse('some markdown text.');
app('markdown')->file()
//parse markdown file $html = app('markdown')->file('path.to.markdownfile'); //path format is same as Laravel view. //You can set different resources path. //But if your project always use different path from default, //change the config setting (app/config/markdown.php). $html = app('markdown')->file('path.to.markdownfile', [resources path,,,]);
app('markdown')->setConfig()
//change parser config $html = app('markdown')->setConfig('hard_wrap', false) ->parse('some markdown text.'); //temporary change parser config $html = app('markdown')->setConfig('hard_wrap', false) ->parse('some markdown text.'); app('markdown')->setConfig('hard_wrap', true);
app('markdown')->PARSER_METHOD()
It's accessable to the original parser method directly through to __call() magic method:
//direct access to the original parser methods if you need app('markdown')->PARSER_METHOD();
Markdown Parser Config
Markdown wrapper class config is placed at app/config/markdown.php after execute:
cd LARAVEL_PROJECT_DIR
php artisan vendor:publish
Example:
[
'default' => 'github',
'resources' => [resource_path('views')],
'extensions' => ['md', 'md.blade.php', 'blade.php', 'php'],
[
'id' => 'github',
'parser' => \cebe\markdown\GithubMarkdown::class,
'methods' => [
'single' => 'parseParagraph',
'multi' => 'parse',
],
'config' => [
'html5' => true,
'enableNewlines' => true,
'keepListStartNumber' => false,
],
],
];
default
Automatically loading parser class id (see Parser settings > id).
(default value: 'michelf-extra')
resources
Markdown file resources path. Markdown files will be finded in this path.
If they are placed in different pathes, then should be set all of pathes in this array().
(default value: [resource_path('views')])
extensions
Markdown file extensions array.
(default value: ['md', 'md.blade.php', 'blade.php', 'php'])
Parser settings
- id : Unique id string for the parser class. If it's unique, anything is possible.
- parser : Full path string of the parser class such as
\namespace\to\class::class. - methods : A single or multiple line to parse markdown method name. Array keys are "single" and "multi".
- single : for single line markdown.
- multi : for multipule line markdown.
- config : Parser class config properties array. If there is no config, value must be empty array().
tomakee/laravel-markdown-wrapper 适用场景与选型建议
tomakee/laravel-markdown-wrapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 10 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「markdown」 「extensible」 「laravel」 「markdown-extra」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tomakee/laravel-markdown-wrapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tomakee/laravel-markdown-wrapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tomakee/laravel-markdown-wrapper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
An extensible DTO library that allows map incoming API data to any of your entities/models by using a simple filed mapping language with filters and functions.
Adds more BBCode
Extensible search for Elemental.
Tool for easy and powerful data validations
A simple, scalable, highly extensible and seo friendly php sitemap generator.
统计信息
- 总下载量: 30
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-31