schumacherfm/mage2-markdown

Markdown 或 Parsedown for Magento2

安装: 12

依赖: 0

建议者: 0

安全: 0

星标: 4

关注者: 3

分支: 2

开放问题: 0

类型:magento2-module

1.0.0 2018-06-08 18:05 UTC

This package is not auto-updated.

Last update: 2024-09-15 13:44:19 UTC


README

为 Magento2 提供的 Markdown 模板引擎。

此模板引擎旨在与 .phtml 文件一起使用,不提供任何 .md 模板文件。

一个用例是将一些简单的 .phtml 文件替换为 Markdown 或使用 Markdown 模板文件作为某种类型的 CMS。

你可以在 Markdown 文件中写入任何 PHP 代码。PHP 执行后,模板将转换为 HTML。

事件 & 配置

Markdown 模板引擎类触发一个事件,允许你修改当前解析器。

事件名称:markdown_init,事件对象:engine

配置选项可以在“商店”->“设置”->“配置”->“高级”->“开发者”->“Markdown”中找到。

你可以从三个引擎中选择一个

默认引擎是第一个。

前端集成

示例用例:禁用 WYSIWYG 编辑器,并将产品表格的内容切换到完全支持 Markdown。

我们通过选项完全禁用了后端的 WYSIWYG 编辑器

商店 -> 配置 -> 一般 -> 内容管理 -> WYSIWYG 选项,其值为 完全禁用。作为副作用,你的后端加载速度将大大提高 ;-(

你的模板文件必须具有 .md 扩展名才能自动识别。

在你的主题中,将 catalog_product_view.xml 修改为

    <block template="product/view/attribute.md" class="Magento\Catalog\Block\Product\View\Description" name="product.info.overview" group="detailed_info" after="product.info.extrahint">
        <arguments>
            <argument name="at_call" xsi:type="string">getShortDescription</argument>
            <argument name="at_code" xsi:type="string">short_description</argument>
            <argument name="css_class" xsi:type="string">overview</argument>
            <argument name="at_label" translate="true" xsi:type="string">none</argument>
            <argument name="title" translate="true" xsi:type="string">Overview</argument>
            <argument name="add_attribute" xsi:type="string">itemprop="description"</argument>
        </arguments>
    </block>

注意:我们只更改了模板扩展名。

    <block template="product/view/attribute.md" class="Magento\Catalog\Block\Product\View\Description" name="product.info.description" group="detailed_info">
        <arguments>
            <argument name="at_call" xsi:type="string">getDescription</argument>
            <argument name="at_code" xsi:type="string">description</argument>
            <argument name="css_class" xsi:type="string">description</argument>
            <argument name="at_label" xsi:type="string">none</argument>
            <argument name="title" translate="true" xsi:type="string">Details</argument>
        </arguments>
    </block>

@todo 找出更改这些块模板名称的最佳方法。

这些更改意味着产品简短描述和详细描述现在将使用 Markdown 进行解析!

示例属性.phtml 转换为属性.md

点击此处查看原始属性.phtml

以下摘录来自 attribute.md,仅显示最后六行

... PHP stuff ...
<?php if ($_attributeValue): ?>
<div class="product attibute <?php echo $_className?>">
    <?php if ($_attributeLabel != 'none'): ?><strong class="type"><?php echo $_attributeLabel?></strong><?php endif; ?>
    <div markdown="1" class="value" <?php echo $_attributeAddAttribute;?>><?php echo $_attributeValue; ?></div>
</div>
<?php endif; ?>

注意,我们在 div 中添加了 markdown="1",并必须将解析器更改为 michelfextra

就这样!现在我们的产品描述将以 Markdown 格式输出!

一个黑客马拉松项目可能是用 Markdown 编辑器替换后端中的 WYSIWYG 编辑器。

开发者

如果你想要添加任何其他 Markdown 引擎,只需创建自己的模块并添加一个 di.xml

<type name="SchumacherFM\Markdown\Framework\View\MarkdownEngineFactory">
    <arguments>
        <argument name="engines" xsi:type="array">
            <item name="myParser" xsi:type="string">\Namespace\Module\MyAwesomeMarkdownParser</item>
        </argument>
    </arguments>
</type>

此条目也将出现在后端配置部分。

你的 MyAwesomeMarkdownParser 必须实现:MarkdownEngineInterface

测试

@todo

通过 Composer 安装

将以下内容添加到你的 Magento 2 composer.json 文件的 require 部分

"schumacherfm/mage2-markdown": "dev-master"

此外,在 repository 部分添加以下内容

    "repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/SchumacherFM/Magento2-Markdown.git"
    }
]

运行 composer update

将以下内容添加到 app/etc/config.php

'SchumacherFM_Markdown'=>1

兼容性

  • Magento >= 2
  • php >= 5.4.0

支持 / 贡献

使用问题跟踪器报告错误或发送给我们拉取请求。

如果你真的打算开发此模块,我可以将你添加为协作者。只需问一下 :-)

我正在使用这个模型:一个成功的Git分支模型

关于版本控制,请查看语义版本控制2.0.0

历史

0.1.0

  • 初始发布

许可协议

OSL-30

作者

Cyrill Schumacher

我的PGP公钥