在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):aptoma/twig-markdown开源软件地址(OpenSource Url):https://github.com/aptoma/twig-markdown开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):Twig Markdown ExtensionTwig Markdown extension provides a new filter and a tag to allow parsing of content as Markdown in Twig templates. This extension could be integrated with several Markdown parser as it provides an interface, which allows you to customize your Markdown parser. Supported parsers
Features
When used as a tag, the indentation level of the first line sets the default indentation level for the rest of the tag content. From this indentation level, all same indentation or outdented levels text will be transformed as regular text. This feature allows you to write your Markdown content at any indentation level without caring of Markdown internal transformation: <div>
<h1 class="someClass">{{ title }}</h1>
{% markdown %}
This is a list that is indented to match the context around the markdown tag:
* List item 1
* List item 2
* Sub List Item
* Sub Sub List Item
The following block will be transformed as code, as it is indented more than the
surrounding content:
$code = "good";
{% endmarkdown %}
</div> InstallationRun the composer command to install the latest stable version: composer require aptoma/twig-markdown Or update your {
"require": {
"aptoma/twig-markdown": "~3.0"
}
} You can choose to provide your own Markdown engine, although we recommend using michelf/php-markdown: composer require michelf/php-markdown ~1.8 {
"require": {
"michelf/php-markdown": "~1.8"
}
} You may also use the PHP League CommonMark engine: composer require league/commonmark ~0.19 {
"require": {
"league/commonmark": "~0.19"
}
} UsageTwig ExtensionThe Twig extension provides the Assuming that you are using composer autoloading, add the extension to the Twig environment: use Aptoma\Twig\Extension\MarkdownExtension;
use Aptoma\Twig\Extension\MarkdownEngine;
$engine = new MarkdownEngine\MichelfMarkdownEngine();
$twig->addExtension(new MarkdownExtension($engine)); Twig Token ParserThe Twig token parser provides the use Aptoma\Twig\TokenParser\MarkdownTokenParser;
$twig->addTokenParser(new MarkdownTokenParser()); SymfonyTo use this extension in a Symfony 3/4 app (including Pimcore), add the following snippet to your app's services:
# ...
markdown.engine:
class: Aptoma\Twig\Extension\MarkdownEngine\MichelfMarkdownEngine
twig.markdown:
class: Aptoma\Twig\Extension\MarkdownExtension
arguments: ['@markdown.engine']
tags:
- { name: twig.extension } GitHub Markdown Engine
use Aptoma\Twig\Extension\MarkdownEngine;
$engine = new MarkdownEngine\GitHubMarkdownEngine(
'aptoma/twig-markdown', // The GitHub repository to use as a context
true, // Whether to use GitHub's Flavored Markdown (GFM)
'/tmp/markdown-cache', // Path on filesystem to store rendered documents
); In order to authenticate the API client (for instance), it's possible to pass an own instance of $client = new \Github\Client;
$client->authenticate('GITHUB_CLIENT_ID', 'GITHUB_CLIENT_SECRET', \Github\Client::AUTH_URL_CLIENT_ID);
$engine = new MarkdownEngine\GitHubMarkdownEngine('aptoma/twig-markdown', true, '/tmp/markdown-cache', $client); Using a different Markdown parser engineIf you want to use a different Markdown parser, you need to create an adapter
that implements TestsThe test suite uses PHPUnit:
LicenseTwig Markdown Extension is licensed under the MIT license. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论