Skip to content

Commit

Permalink
Merge pull request #24 from natedrake/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
natedrake committed Apr 2, 2017
2 parents 0cd5551 + 69699c4 commit 21e8404
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 39 deletions.
54 changes: 32 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@

[![Monthly Downloads](https://poser.pugx.org/natedrake/markdown/d/monthly)](https://packagist.org/packages/natedrake/markdown)
[![Daily Downloads](https://poser.pugx.org/natedrake/markdown/d/daily)](https://packagist.org/packages/natedrake/markdown)
### PHP Markdown Converter

## PHP Markdown Converter

1. [Headings](https://github.com/natedrake/markdown/blob/master/README.md#headings)
2. [Italics](https://github.com/natedrake/markdown/blob/master/README.md#italics)
3. [Bold](https://github.com/natedrake/markdown/blob/master/README.md#bold)
4. [Strike Through](https://github.com/natedrake/markdown/blob/master/README.md#strike-through)
5. [Links](https://github.com/natedrake/markdown/blob/master/README.md#links)
6. [Images](https://github.com/natedrake/markdown/blob/master/README.md#images)
7. [Lists](https://github.com/natedrake/markdown/blob/master/README.md#lists)
- [Unordered List](https://github.com/natedrake/markdown/blob/master/README.md#unordered-lists)
- [Ordered List](https://github.com/natedrake/markdown/blob/master/README.md#ordered-lists)
8. [Block Quotes](https://github.com/natedrake/markdown/blob/master/README.md#block-quotes)
9. [Tables](https://github.com/natedrake/markdown/blob/master/README.md#tables)

Markdown is a PHP library for converting markdown to markup. It is a useful tool
for creating documentation on a web page. For example, if your website contains
a blog, wiki pages, any sort of editing from users you could allow them to
style their documents using markdown.

## Supports:
- headings
- italics
- bold
- links
- images
- ordered lists
- unordered lists
- block quotes

### Headings

``#`` ``<h1>``
Expand Down Expand Up @@ -55,14 +58,6 @@ Wrap text in ``**`` to make it bold

``**this text is bold**`` will produce the following markup ``<strong>this text is bold</strong>``

### Strike Through

``~~text~~``

Wrap text in ``~~`` to strike through the text.

``~~text~~`` produces the following markup ``<del>text</del>``

### Links

``[Text](Hyperlink)``
Expand All @@ -83,8 +78,23 @@ Create images by inserting the alternate text in square brackets followed by the

``![Git Logo](https://assets-cdn.github.com/images/modules/logos_page/GitHub-Logo.png)`` will produce the following markup ``<img src="https://assets-cdn.github.com/images/modules/logos_page/GitHub-Mark.png" alt="Git Logo" />``

### Lists
### Code

Create inline code elements by surrounding elements in `` ```var x;``` ``;

``
```var x;```
``

produces the following markup

````html
<code>var x;</code>
````

if you need to span multiple lines use 4 back-ticks instead of three, and make sure to have one line break inside the back-ticks

### Lists

#### Unordered Lists

Expand Down Expand Up @@ -141,7 +151,7 @@ will product the following markup
Tables can now be created by using the bar character. Use the ``|`` character to outline your table and it's columns

````markdown
|Heading One|Heading Two|Heading Three
|Heading One|Heading Two|Heading Three|
|Row1Col1|Row1Col2|Row1Col2|
|Row2Col1|Row2Col2|Row2Col2|
|Row3Col1|Row3Col2|Row3Col2|
Expand All @@ -168,4 +178,4 @@ produces a HTML table like:
</tr>
</tbody>
</table>
````
````
2 changes: 1 addition & 1 deletion src/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function parse()
/**
* @note explode items from matches array
*/
$items=explode("\n", ltrim(rtrim($element->value[3])));
$items=explode("\n", ltrim(rtrim($element->value[2])));

$return.='<ul style="list-style: disc;padding-left:0px;">';
$return.='<span style="font-size:1.1em;">'.$element->value[1].'</span>';
Expand Down
20 changes: 8 additions & 12 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class Lexer
* @var string $input
*/
public $input;

/**
* Lexer constructor.
* @param $input
Expand Down Expand Up @@ -77,9 +76,6 @@ protected function scanInput($regex, $type)
$matches=array();
if (preg_match($regex, $this->input, $matches)) {
$this->consumeInput(mb_strlen($matches[0]));
if ($type==='heading') {

}
return new Token($type, $matches);
}
}
Expand Down Expand Up @@ -115,23 +111,23 @@ protected function scanReturn()
*/
protected function scanEm()
{
return $this->scanInput('/^[_]{2}([^_;]+)[_]{2}/', 'em');
return $this->scanInput('/^[_]{2}([^_]+)[_]{2}/', 'em');
}

/**
* @return Token
*/
protected function scanHeading()
{
return $this->scanInput('/(^[#]+)([^\n;]+)/', 'heading');
return $this->scanInput('/(^[#]+)([^\n]+)/', 'heading');
}

/**
* @return Token
*/
protected function scanStrong()
{
return $this->scanInput('/^\*{2}([^\*;]+)[\*]{2}/', 'strong');
return $this->scanInput('/^\*{2}([^\*]+)[\*]{2}/', 'strong');
}

/**
Expand All @@ -147,7 +143,7 @@ public function scanQuoteBlock()
*/
protected function scanCode()
{
return $this->scanInput('/^[`]{3}([^`;]+)[`]{3}/', 'code');
return $this->scanInput('/^[`]{3}([^`]+)[`]{3}/', 'code');
}

/**
Expand All @@ -171,7 +167,7 @@ protected function scanHR()
*/
protected function scanLink()
{
return $this->scaninput('/^\[([^\];]+)]\(([^\);]+)\)/', 'a');
return $this->scaninput('/^\[([^\]]+)]\(([^\);]+)\)/', 'a');
}

/**
Expand All @@ -187,15 +183,15 @@ protected function scanImg()
*/
protected function scanUnorderedList()
{
return $this->scanInput('/(^[^\*#_\[\n`;]+)([\n]([\s][-][\s][^;]+))[\n]/', 'ul');
return $this->scanInput('/^([^\n]+)(([\n]?\s\-\s[^\n]+)+)/', 'ul');
}

/**
* @return Token
*/
protected function scanOrderedList()
{
return $this->scanInput('/(^[^\*#_\[\n`;]+)[\n]([\s][\d\.\w]+[\s][^;]+)[\n]/', 'ol');
return $this->scanInput('/^([^\n]+)(([\n]?\s\d\.\s[^\n]+)+)/', 'ol');
}

/**
Expand All @@ -216,7 +212,7 @@ public function scanStrikeThrough()
*/
protected function scanText()
{
return $this->scanInput('/^[^\*#_\[\n`;]+/', 'text');
return $this->scanInput('/^[^\*#_\[\n`]+/', 'text');
}

/**
Expand Down
54 changes: 50 additions & 4 deletions tests/src/MarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ public function testUnorderedList()
- MVC Framework
- ORM Framework
- Hash Class
- Input Class
";
- Input Class";
$markup='<ul style="list-style: disc;padding-left:0px;"><span style="font-size:1.1em;">Contains:</span><li style="margin-left: 30px;">MVC Framework</li><li style="margin-left: 30px;">ORM Framework</li><li style="margin-left: 30px;">Hash Class</li><li style="margin-left: 30px;">Input Class</li></ul>';
$bootstrap=new BootStrap($markdown);
$this->assertEquals($markup, $bootstrap->dumper->parse());
Expand All @@ -158,8 +157,7 @@ public function testOrderedList()
1. MVC Framework
2. ORM Framework
4. Hash Class
3. Input Class
";
3. Input Class";
$markup='<ol style="padding-left: 0px;"><span style="font-size:1.1em;">Contains:</span><li style="margin-left: 30px;"> MVC Framework</li><li style="margin-left: 30px;"> ORM Framework</li><li style="margin-left: 30px;"> Hash Class</li><li style="margin-left: 30px;"> Input Class</li></ol>';
$bootstrap=new BootStrap($markdown);
$this->assertEquals($markup, $bootstrap->dumper->parse());
Expand Down Expand Up @@ -194,4 +192,52 @@ public function testStrikeThrough()
$bootstrap=new BootStrap($markdown);
$this->assertEquals($markup, $bootstrap->dumper->parse());
}

public function testAllTokens()
{
$markdown="# Heading One
## Heading Two
### Heading Three
#### Heading Four
##### Heading Five
###### Heading Six
__italics__
**bold**
~~strike~~
[google.ie](https://google.ie/)
![Alternative Text](https://s3-eu-west-1.amazonaws.com/ogradyjohn.com/cover.png)
Unordered List
- item one
- item two
- item three
Ordered List
1. item one
2. item two
3. item three
> block quote
|Heading One|Heading Two|Heading Three|
|Row1Col1|Row1Col2|Row1Col2|
|Row2Col1|Row2Col2|Row2Col2|
|Row3Col1|Row3Col2|Row3Col2|";

$markup="<h1> Heading One</h1><h2> Heading Two</h2><h3> Heading Three</h3><h4> Heading Four</h4><h5> Heading Five</h5><h6> Heading Six</h6><i>italics</i><br /><strong>bold</strong><br /><del>strike</del><br /><a target=\"_blank\" href=\"https://google.ie/\">google.ie</a><br /><img alt=\"Alternative Text\" src=\"https://s3-eu-west-1.amazonaws.com/ogradyjohn.com/cover.png\" style=\"width:100%;\" /><br /><ul style=\"list-style: disc;padding-left:0px;\"><span style=\"font-size:1.1em;\">Unordered List</span><li style=\"margin-left: 30px;\">item one</li><li style=\"margin-left: 30px;\">item two</li><li style=\"margin-left: 30px;\">item three</li></ul><br /><ol style=\"padding-left: 0px;\"><span style=\"font-size:1.1em;\">Ordered List</span><li style=\"margin-left: 30px;\"> item one</li><li style=\"margin-left: 30px;\"> item two</li><li style=\"margin-left: 30px;\"> item three</li></ol><br /><blockquote> block quote</blockquote><br /><table border=\"border\"><thead><th>Heading One</th><th>Heading Two</th><th>Heading Three</th></thead><tbody><tr><td>Row1Col1</td><td>Row1Col2</td><td>Row1Col2</td></tr><tr><td>Row2Col1</td><td>Row2Col2</td><td>Row2Col2</td></tr><tr><td>Row3Col1</td><td>Row3Col2</td><td>Row3Col2</td></tr></tbody></table>";

$bootstrap=new BootStrap($markdown);

$this->assertEquals($markup, $bootstrap->dumper->parse());
}
}

0 comments on commit 21e8404

Please sign in to comment.