Ejemplo n.º 1
0
 public function testSave()
 {
     // Arrange
     $document = new MW\Document();
     $document->add(new Paragraph('This is some text.'));
     $paragraph = new Paragraph('Here some more.');
     $document->add($paragraph);
     // Act
     $result = $document->save(new Adapter\NullAdapter(), 'bogus.md');
     // Assert
     $this->assertTrue($result);
 }
Ejemplo n.º 2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Pachico\MarkdownWriter\Document;
use League\Flysystem\Adapter;
use Pachico\MarkdownWriter\Element as El;
// Create Document
$document = new Document();
// Add Header elements
$document->add(new El\H1('This is a H1 header.'))->add(new El\H2('This is a H2 header.'))->add(new El\H3('This is a H3 header.'))->add(new El\H4('This is a H4 header.'))->add(new El\H5('This is a H5 header.'))->add(new El\H6('This is a H6 header.'));
$adapter = new Adapter\Local(__DIR__);
$document->save($adapter, basename(__FILE__, 'php') . 'md');
Ejemplo n.º 3
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Pachico\MarkdownWriter\Document;
use League\Flysystem\Adapter;
// Create Document
$document = new Document();
//...
// To fetch the markdown as a string simply
$markdown = $document->toMarkdown();
// To save it somewhere we use the great FlySystem abstraction layer:
// Define file system adapter
$adapter = new Adapter\Local(__DIR__);
// Inject it to the save method and it will be persisted
$document->save($adapter, basename(__FILE__, 'php') . 'md');
// Check http://flysystem.thephpleague.com/ to see the adapters list
Ejemplo n.º 4
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Pachico\MarkdownWriter\Document;
use League\Flysystem\Adapter;
use Pachico\MarkdownWriter\Element as El;
// Create Document
$document = new Document();
// Create a first paragraph with elements in its constructor
// Direct string and Text objects will be put inline
// You can also add instances of Image and Link
$paragraph1 = new El\Paragraph('First span of text as simple string.', new El\Text('Second span of text as instance of Text.'), new El\Text('Third span of text as decorated instance of Text.', El\Text::BOLD));
$document->add($paragraph1);
// Paragraphs can also be injected with content after being instantiated
$paragraph2 = new El\Paragraph();
$paragraph2->addContent('Fourth span of text added to second paragraph.');
$paragraph2->addContent(new El\Text('Fifth span of text added to second paragraph as instance of Text.'));
$paragraph2->addContent(new El\Text('Sixth span of text added to second paragraph as decorated instance of Text.'));
$document->add($paragraph2);
$adapter = new Adapter\Local(__DIR__);
$document->save($adapter, basename(__FILE__, 'php') . 'md');
Ejemplo n.º 5
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Pachico\MarkdownWriter\Document;
use League\Flysystem\Adapter;
use Pachico\MarkdownWriter\Element as El;
$document = new Document();
$document->add(new El\H1('This is a simple example'))->add(new El\Paragraph('And here is something I want to say.', 'And something more.'))->add(new El\Code('$variable =  new Foo\\Bar();'))->add(new El\Paragraph('Time to wrap up.', new El\Text('Something italic', El\Text::ITALIC)));
$paragraph = new El\Paragraph();
$paragraph->addContent(new El\Text('Some bold text', El\Text::BOLD));
$document->add($paragraph);
$document->add(new El\H2('Some subtitle too'));
$document->add(new El\HRule(El\HRule::ASTERISK));
$adapter = new Adapter\Local(__DIR__);
$document->save($adapter, basename(__FILE__, 'php') . 'md');
Ejemplo n.º 6
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Pachico\MarkdownWriter\Document;
use League\Flysystem\Adapter;
use Pachico\MarkdownWriter\Element as El;
// Create Document
$document = new Document();
// Create a link
$link = new El\Link('Markdown Writer!', 'https://github.com/pachico/markdownwriter');
// Add it to the document
$document->add($link);
$adapter = new Adapter\Local(__DIR__);
$document->save($adapter, basename(__FILE__, 'php') . 'md');
Ejemplo n.º 7
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Pachico\MarkdownWriter\Document;
use League\Flysystem\Adapter;
use Pachico\MarkdownWriter\Element as El;
// Create Document
$document = new Document();
// Create a first blockquote with elements in its constructor
// Direct string and Text objects will be put inline
// You can also add instances of Image and Link
$blockquote1 = new El\Blockquote('First span of text as simple string.', new El\Text('Second span of text as instance of Text.'), new El\Text('Third span of text as decorated instance of Text.', El\Text::BOLD));
$document->add($blockquote1);
// Blockquotes can also be injected with content after being instantiated
$blockquote2 = new El\Blockquote();
$blockquote2->addContent('Fourth span of text added to second blockquote.');
$blockquote2->addContent(new El\Text('Fifth span of text added to second blockquote as instance of Text.'));
$blockquote2->addContent(new El\Text('Sixth span of text added to second blockquote as decorated instance of Text.'));
$document->add($blockquote2);
$adapter = new Adapter\Local(__DIR__);
$document->save($adapter, basename(__FILE__, 'php') . 'md');
Ejemplo n.º 8
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Pachico\MarkdownWriter\Document;
use League\Flysystem\Adapter;
use Pachico\MarkdownWriter\Element as El;
// Create Document
$document = new Document();
// Create diffent types of horizontal rules
$hRule1 = new El\HRule(El\HRule::ASTERISK);
$hRule2 = new El\HRule(El\HRule::DASH);
$hRule3 = new El\HRule(El\HRule::UNDERSCORE);
// Add them to the document
$document->add($hRule1)->add($hRule2)->add($hRule3);
$adapter = new Adapter\Local(__DIR__);
$document->save($adapter, basename(__FILE__, 'php') . 'md');
Ejemplo n.º 9
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Pachico\MarkdownWriter\Document;
use League\Flysystem\Adapter;
use Pachico\MarkdownWriter\Element as El;
// Create Document
$document = new Document();
$code1 = new El\Code('var code = "This is Javascript code";', El\Code::JAVASCRIPT);
$code2 = new El\Code('This is generic code');
$document->add($code1)->add($code2);
$adapter = new Adapter\Local(__DIR__);
$document->save($adapter, basename(__FILE__, 'php') . 'md');
Ejemplo n.º 10
0
<?php

require __DIR__ . '/../../vendor/autoload.php';
use Pachico\MarkdownWriter as MW;
use Pachico\MarkdownWriter\Element as El;
use League\Flysystem\Adapter;
$examplesFolder = __DIR__ . '/../';
// Create document
$document = new MW\Document();
// Add Title
$document->add(new El\H1('MarkdownWriter'));
// Add badges
$document->add(new El\Paragraph(new El\Image('https://travis-ci.org/pachico/markdownwriter.svg?branch=master', 'https://travis-ci.org/pachico/markdownwriter', 'Build Status', 'Markdown Writer'), ' ', new El\Image('https://styleci.io/repos/57068965/shield', 'https://styleci.io/repos/57068965', 'StyleCI', 'StyleCI')));
//
$document->add((new El\Paragraph())->addContent('Php package to write markdown documents.'));
$document->add(new El\Paragraph(new El\Text('What it is: ', El\Text::BOLD), new El\Text('a markdown writer.'), new El\Text('What it isn\'t: ', El\Text::BOLD), new El\Text('a markdown parser.')));
$document->add(new El\Paragraph(new El\Text('Why?', El\Text::BOLD), 'Because coding it was fun and because you might want to programmatically write documentation, blog entries, etc. ' . ' with data that comes from a databases, csv files, etc. More and more there are static site generators that use' . ' markdown as source so, I thought I would give it a try.'));
// Add Index
$document->add(new El\H2('Table of Contents'));
$document->add((new El\Lizt())->addUnorderedItem(new El\Link('Install', '#install'))->addUnorderedItem(new El\Link('Usage', '#usage'))->levelDown()->addUnorderedItem(new El\Link('Headers', '#headers'))->addUnorderedItem(new El\Link('Paragraph', '#paragraph'))->addUnorderedItem(new El\Link('Blockquote', '#blockquote'))->addUnorderedItem(new El\Link('Code', '#code'))->addUnorderedItem(new El\Link('Horizontal rule', '#horizontal-rule'))->addUnorderedItem(new El\Link('Image', '#image'))->addUnorderedItem(new El\Link('Link', '#link'))->addUnorderedItem(new El\Link('Lizt (list)', '#lizt-list'))->addUnorderedItem(new El\Link('Output', '#output'))->addUnorderedItem(new El\Link('Example', '#example')));
// Add Install
$document->add(new El\H2('Install'));
$document->add((new El\Paragraph())->addContent('Via Composer'));
$document->add(new El\Code('$ composer require pachico/markdownwriter'));
// Add Usage
$document->add(new El\H2('Usage'));
//
$document->add(new El\H3('Headers'));
$document->add(new El\Code(file_get_contents($examplesFolder . '02-headers.php'), El\Code::PHP));
$document->add(new El\Paragraph('Will output:'));
$document->add(new El\Code(file_get_contents($examplesFolder . '02-headers.md')));