2017 © Pedro Peláez
 

magento2-module mage2-markdown

Markdown or Parsedown for Magento2

image

schumacherfm/mage2-markdown

Markdown or Parsedown for Magento2

  • Friday, June 8, 2018
  • by SchumacherFM
  • Repository
  • 1 Watchers
  • 4 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Magento2 Markdown Template Engine

Markdown template engine for Magento2., (*1)

This template engine is meant to be used additionally to the .phtml files and does not provide any .md template file., (*2)

A use case would be to replace some simple .phtml files with Markdown or uses the Markdown template files as some kind of CMS., (*3)

You can write any PHP in the Markdown files. After PHP has been executed the template will be transformed from Markdown to HTML., (*4)

Events & Configuration

The Markdown template engine class dispatches one event which lets you modify the current parser., (*5)

Event name: markdown_init with event object: engine., (*6)

Configuration options can be found Stores -> Settings -> Configuration -> Advanced -> Developer -> Markdown., (*7)

You can choose from one of the three engines:, (*8)

Default engine is the first one., (*9)

Frontend Integration

Example use case: Disable WYSIWYG editor and switch the content from the product tables to full Markdown support., (*10)

We're deactivating the WYSIWYG editor completely in the backend via the option, (*11)

Stores -> Configuration -> General -> Content Management -> WYSIWYG Options with value Disable completely. As a side effect you backend loads much faster ;-(, (*12)

Your template files must have the file extension .md to get automatically recognized., (*13)

In your theme change catalog_product_view.xml to, (*14)

    <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>

Note: We are only changing the template extension., (*15)

    <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 figure out best method to easily change the template name for those blocks., (*16)

These changes mean that product short description and long description will now be parsed with Markdown!, (*17)

Example attribute.phtml converted to attribute.md

Click here to view the original attribute.phtml, (*18)

The next excerpt is from attribute.md which only shows the last six lines:, (*19)

... 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; ?>

Note that we add here markdown="1" into the div and we must change the parser to michelfextra., (*20)

That's it! All our product descriptions will now be outputted with Markdown formatting!, (*21)

A hackathon project could be to replace the WYSIWYG editor with a Markdown editor in the backend., (*22)

Developers

If you wish to add any other Markdown engine simply create your own module and add a di.xml:, (*23)

<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>

This entry will also appear in the backend configuration section., (*24)

Your MyAwesomeMarkdownParser must implement: MarkdownEngineInterface., (*25)

Tests

@todo, (*26)

Installation via Composer

Add the following to the require section of your Magento 2 composer.json file, (*27)

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

additionally add the following in the repository section, (*28)

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

run composer update, (*29)

add the following to app/etc/config.php, (*30)

'SchumacherFM_Markdown'=>1

Compatibility

  • Magento >= 2
  • php >= 5.4.0

Support / Contribution

Report a bug using the issue tracker or send us a pull request., (*31)

Instead of forking I can add you as a Collaborator IF you really intend to develop on this module. Just ask :-), (*32)

I am using that model: A successful Git branching model, (*33)

For versioning have a look at Semantic Versioning 2.0.0, (*34)

History

0.1.0

  • Initial release

License

OSL-30, (*35)

Author

Cyrill Schumacher, (*36)

My pgp public key, (*37)

The Versions

08/06 2018

dev-master

9999999-dev

Markdown or Parsedown for Magento2

  Sources   Download

OSL-3.0

The Requires

 

08/06 2018

1.0.0

1.0.0.0

Markdown or Parsedown for Magento2

  Sources   Download

OSL-3.0

The Requires