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.
Using Composer:
$ composer require conde-nast-international/copilot-markdown-generator
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.
See the Contributing document for guidance on making contributions to the project.
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, "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~");
Interface for tag generator classes.
-
CopilotTag->render()
Render tag object as beautified Copilot-flavored Markdown string.
Return: string (Markdown)
Generator for unformatted text.
(new Text("Hello world!"))->render();
// "Hello world!"
new Text($text)
text: string (Markdown)
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
)
Generator for paragraphs.
(new Paragraph("Hello world!"))->render();
// "\n\nHello world!\n\n"
new Paragraph($text)
text: string (Markdown)
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:""
)
Class Constant | Value | Also known as |
---|---|---|
EMPHASIS |
* |
Italic, em |
STRONG |
** |
Bold |
DELETE |
~~ |
Strikethrough, strike, del |
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:[]
)
Generator for block quotes.
(new Blockquote("Hello world!"))->render();
// "\n> Hello world!\n"
new Blockquote($text)
text: string (Markdown)
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
)
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:""
)
Class constants for valid embed subtypes. See the source file for reference.