PHP Classes

PHP Markdown Generator: Compose and generate Markdown documents

Recommend this page to a friend!
  Info   View files Example   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 98 All time: 9,812 This week: 488Up
Version License PHP version Categories
gen-md 1.0.0Custom (specified...5PHP 5, Files and Folders, Printing
Description 

Author

This package can compose and generate Markdown documents.

It provides a document class that can generate Markdown documents by adding different document elements like paragraphs, headings, lists, text formatted with styles, etc.

The package also provides a trait that can export the generated document to a file with a given path. The trait creates the directory of the output file path if it does not exist.

Innovation Award
PHP Programming Innovation award winner
August 2020
Winner


Prize: One official elePHPant Plush Mascott
Markdown became a popular file format to represent documents that can be displayed in plain text format, or in HTML Web pages or other document formats.

This package provides a solution to compose documents in a programmatic way, so it can output the document content in Markdown format.

Manuel Lemos
Picture of Temuri Takalandze
  Performance   Level  
Name: Temuri Takalandze <contact>
Classes: 6 packages by
Country: Georgia Georgia
Age: 24
All time rank: 35785 in Georgia Georgia
Week rank: 321 Up2 in Georgia Georgia Up
Innovation award
Innovation award
Nominee: 4x

Winner: 1x

Example

<?php

// Include Composer Autoloader.
require_once __DIR__ . '/../vendor/autoload.php';

use
ABGEO\MDGenerator\Document;
use
ABGEO\MDGenerator\Element;

$document = new Document();

$document
   
->addElement(Element::createHeading('Heading level 1'))
    ->
addElement(Element::createHeading('Heading level 5', 6))
    ->
addElement(Element::createParagraph('Paragraph 1'))
    ->
addElement(Element::createParagraph('Paragraph 2'))
    ->
addElement(
       
Element::concatenateElements(
           
'Paragraph',
           
Element::createBreak(),
           
'With Break.'
       
)
    )
    ->
addElement(Element::createBreak())
    ->
addElement(Element::createBold('Bold Text'))
    ->
addElement(Element::createItalic('Italic Text'))
    ->
addElement(Element::createBoldAndItalic('Bold and Italic Text'))
    ->
addElement(Element::createBlockquote('Blockquote 1'))
    ->
addElement(Element::createBreak())
    ->
addElement(Element::createBreak())
    ->
addElement(
       
Element::createBlockquote('Multiline', 'Blockquote')
    )
    ->
addElement(Element::createBreak())
    ->
addElement(Element::createBreak())
    ->
addElement(
       
Element::createBlockquote(
           
'Multiline',
           
Element::createBlockquote('Nested'),
           
'Blockquote'
       
)
    )
    ->
addElement(Element::createBreak())
    ->
addElement(Element::createList(['Unordered Item 1', 'Unordered Item 2']))
    ->
addElement(Element::createBreak())
    ->
addElement(
       
Element::createList(
            [
'Ordered Item 1', 'Ordered Item 2'],
           
Element::LIST_ORDERED
       
)
    )
    ->
addElement(Element::createLine())
    ->
addElement(Element::createLink('www.abgeo.dev', 'https://www.abgeo.dev'))
    ->
addElement(
       
Element::createLink(
           
'Link with title',
           
'https://informatics.ge',
           
'Informatics.Ge'
       
)
    )
    ->
addElement(Element::createLine())
    ->
addElement(
       
Element::createImage(
           
'https://informatics.ge/images/blue-robot-hi.png',
           
'Informatics.Ge',
           
'www.informatics.ge'
       
)
    )
   
// Create link with image.
   
->addElement(
       
Element::createLink(
           
Element::createImage(
               
'https://abgeo.dev/img/favicon.png',
               
'ABGEOs Personal website'
           
),
           
'https://abgeo.dev'
       
)
    );

// Export document to file.
$document->export2File(__DIR__ . '/generated/example.MD');


Details

gen-md

PHP Library for generating Markdown document

GitHub license

GitHub release

Packagist Version

Installation

You can install this library with Composer:

  • `composer require abgeo/gen-md`

Usage

Include composer autoloader in your main file (Ex.: index.php)

  • `require_once __DIR__ . '/../vendor/autoload.php';`

Classes

The library has two classes:

  • `\ABGEO\MDGenerator\Document` - For generating Markdown Document;
  • `\ABGEO\MDGenerator\Element` - For generating Markdown element;

Class Document

Import ABGEO\MDGenerator\Document class.

Public Methods

  • `addElement()` - Add element to Document content;
  • `clear()` -Clear Document content;

Note: See usage in example.php

Class Element

Import ABGEO\MDGenerator\Element class.

Public Methods

  • `concatenateElements()` - Concatenate given elements;
  • `createHeading()` - Create heading element;
  • `createParagraph()` - Create Paragraph element;
  • `createBreak()` - Create Line Break element;
  • `createBold()` - Create Bold element;
  • `createItalic()` - Create Italic element;
  • `createBoldAndItalic()` - Create Bold and Italic element;
  • `createBlockquote()` - Create Blockquote element;
  • `createList()` - Create List element;
  • `createLine()` - Create Line element;
  • `createLink()` - Create Link element;
  • `createImage()` - Create Image element;

Note: See usage in example.php

Exporting

The ABGEO\MDGenerator\Document class has export2File() method that takes one argument - File path for generated document.

Example

...
// Export document to file.
$document->export2File(__DIR__ . '/generated/example.MD');
...

Examples

See full example in example.php.

Authors

  • Temuri Takalandze - Initial work - ABGEO

License

This project is licensed under the MIT License - see the LICENSE file for details


  Files folder image Files  
File Role Description
Files folder image.github (1 file)
Files folder imageexamples (1 file, 1 directory)
Files folder imagesrc (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
  Accessible without login Plain text file FUNDING.yml Data Auxiliary data

  Files folder image Files  /  examples  
File Role Description
Files folder imagegenerated (1 file)
  Accessible without login Plain text file example.php Example Example script

  Files folder image Files  /  examples  /  generated  
File Role Description
  Accessible without login Plain text file example.MD Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageMDGenerator (3 files)

  Files folder image Files  /  src  /  MDGenerator  
File Role Description
  Plain text file Document.php Class Class source
  Plain text file Element.php Class Class source
  Plain text file ExporterTrait.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:98
This week:0
All time:9,812
This week:488Up