conde-nast-international/copilot-markdown-generator

This package is abandoned and no longer maintained. No replacement package was suggested.

Generator classes for Copilot-flavored Markdown tags.


README

Generator classes for Copilot-flavored Markdown tags.

This is a utility library for generating Copilot-flavored Markdown, created for use in PHP implementations of the Flyway Integration API.

Install

Using Composer:

$ composer require conde-nast-international/copilot-markdown-generator

Basic usage

use CopilotTags\Text;

$tag = new Text("Hello world!");
$markdown = $tag->render();
echo $markdown;
// Hello world!

See the example implementation, which shows how the library can be used to convert custom XML content.

Contributing

See the Contributing document for guidance on making contributions to the project.

API

This library is a collection of simple Markdown generator classes namespaced in CopilotTags (e.g. CopilotTags\Paragraph).

Several of the generators take a text parameter. The given text value can contain any valid Copilot-flavored Markdown, which allows for tags to be nested.

NOTE: You need to escape any Markdown characters in the source content that should not be treated as Markdown:

addcslashes($content, "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~");

CopilotTag

Interface for tag generator classes.

  • CopilotTag->render()

    Render tag object as beautified Copilot-flavored Markdown string.
    Return: string (Markdown)

Text

Generator for unformatted text.

(new Text("Hello world!"))->render();
// "Hello world!"
  • new Text($text)
    text: string (Markdown)

Heading

Generator for ATX headings.

(new Heading("Hello world!", 3))->render();
// "\n\n### Hello world!\n"
  • new Heading($text[, $level])
    text: string (Markdown)
    level: int (default: 2) (min: 2) (max: 4)

Paragraph

Generator for paragraphs.

(new Paragraph("Hello world!"))->render();
// "\n\nHello world!\n\n"
  • new Paragraph($text)
    text: string (Markdown)

InlineText

Generator for inline text tags: emphasis, strong and delete.

(new InlineText("Hello world!", InlineTextDelimiter::EMPHASIS))->render();
// "*Hello world!*"
  • new InlineText($text[, $delimiter])
    text: string (Markdown)
    delimiter: string (InlineTextDelimiter) (default: "")

InlineTextDelimiter

Class Constant Value Also known as
EMPHASIS * Italic, em
STRONG ** Bold
DELETE ~~ Strikethrough, strike, del

Link

Generator for links.

(new Link("Hello world!", "https://github.com/"))->render();
// "[Hello world!](https://github.com/)"
(new Link("Hello world!", "https://github.com/", array("rel"=>"nofollow")))->render();
// "[Hello world!](https://github.com/){: rel=\"nofollow\" }"
  • new Link([$text, $href, $attributes])
    text: string (Markdown) (default: "")
    href: string (default: "")
    attributes: array (default: [])

Blockquote

Generator for block quotes.

(new Blockquote("Hello world!"))->render();
// "\n> Hello world!\n"
  • new Blockquote($text)
    text: string (Markdown)

ListTag

Generator for lists.

(new ListTag(["First", "Second"]))->render();
// "\n\n* First\n* Second\n\n"
(new ListTag(["First", "Second"], TRUE))->render();
// "\n\n1. First\n2. Second\n\n"
  • new ListTag($items[, $ordered])
    items: array (Markdown)
    ordered: boolean (default: FALSE)

Embed

Generator for embeds.

(new Embed("https://github.com", EmbedSubtype::IFRAME))->render();
// "\n\n[#iframe: https://github.com]\n\n"
(new Embed("https://github.com", EmbedSubtype::IFRAME, "My caption."))->render();
// "\n\n[#iframe: https://github.com]|||My caption.|||\n\n"
  • new Embed($uri[, $subtype, $caption])
    uri: string
    subtype: string (default: EmbedSubtype::IFRAME)
    caption: string (default: "")

EmbedSubtype

Class constants for valid embed subtypes. See the source file for reference.

See also