2017 © Pedro Peláez
 

craft-plugin html-to-markdown

provide conversion of html to markdown in Craft CMS Twig scripts

image

narrationsd/html-to-markdown

provide conversion of html to markdown in Craft CMS Twig scripts

  • Saturday, July 21, 2018
  • by narrationsd
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Craft html-to-markdown plugin

(very preliminary documentation), (*1)

Description

This plugin implements HTML to Markdown conversion for Craft 3., (*2)

It provides Twig filter extension for The Php League's html-to-markdown library, and allows using their options where desired., (*3)

Licensing

Will decide when adding to the Craft Store shortly. This plugin is copyrighted. This is a pre-release beta for development use only., (*4)

Installation

As with any other plugin, once present in your Craft Plugins page, you'll want to Install there., (*5)

Usage

Employing html-to-markdown is straightforward. Given you have a Twig variable containing html, emit it using the html-to-markdown filter., (*6)

For example:, (*7)

{% set testhtml = '

Here\'s a bit of Markdown from html...

%}
{{ testhtml | htmltomarkdown }}

This will result in very simple:, (*8)

### Here's a bit of Markdown from html...

If there are multiple lines, this won't show on your browser screen as whitespace is reduced, but returns and spacing are proper, as you can verify using view-source or in your intended application., (*9)

Options

For whitespace, and for translation of emphasis html codes, there are optional behaviors available with the League library., (*10)

You can implement these by providing an array of options you want to use, and passing these to the function form of this html-to-markdown filter., (*11)

Here's a more extensive example showing several options being used., (*12)

{% set testhtml = '

Here\'s a bit of Markdown from html...

We can control how em and strong come out., (*13)

a break here..
and there it was., (*14)

< p>Images show as expectedin Markdown source when you set the alt: <img src="https://narrationsd.com/resources/images/share/svolvaer.jpg" alt="The image"> < p>

And links are as you expect, Cobbler Shoes, (*15)

' %}
{{ testhtml | htmltomarkdown }}
{% set options = { italic_style: '*', bold_style: '__', hard_break: true } %}

Here with some options set:

{{ testhtml | htmltomarkdown(options) }}

The results will be as follows, presuming your Markdown reader handles html, or if you try the code online in a browser. The Markdown itself will show the images and the link as expected., (*16)

Html to Markdown Test

### Here's a bit of Markdown from html...

We can control how _em_ and **strong** come out.

a break here..  
and there it was.

Images show as expected in Markdown source when you set the alt: ![The image](https://narrationsd.com/resources/images/share/svolvaer.jpg)

And links are as you expect, [The Cobbler's Shoes](https://narrationsd.com)

Here with some options set

### Here's a bit of Markdown from html...

We can control how *em* and __strong__ come out.

a break here..
and there it was.

Images show as expected in Markdown source when you set the alt: ![The image](https://narrationsd.com/resources/images/share/svolvaer.jpg)

And links are as you expect, [The Cobbler's Shoes](https://narrationsd.com)

n.b. You may note that the distinction for the hard_break option is quite subtle, but it is there, and the description can be found from the link in the next section., (*17)

Documentation for Options

Since we are passing your array of options to the League's library, you can find the capabilities and limitations nicely laid out on their Github page: https://github.com/thephpleague/html-to-markdown., (*18)

The Versions

21/07 2018

dev-master

9999999-dev https://narrationsd.com

provide conversion of html to markdown in Craft CMS Twig scripts

  Sources   Download

proprietary

The Requires