Skip to content

Commit c832e45

Browse files
committed
added sample Man render.
1 parent b2dd5e7 commit c832e45

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

examples/Man.php

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/*
3+
* The MIT License
4+
*
5+
* Copyright (c) 2011 - 2012 Shuhei Tanuma
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
namespace Sundown\Render;
26+
27+
/**
28+
* Man Render - sample custom render for Sundown
29+
*
30+
* <code>
31+
* $sd = new Sundown\Markdown(new Sundown\Render\Man());
32+
* echo $sd->render("# parsed as markdown, render as Man format")
33+
* </code>
34+
*/
35+
class Man extends Base
36+
{
37+
public function normal_text($text)
38+
{
39+
return preg_replace("/-/","\\-",$text);
40+
}
41+
42+
public function block_code($code, $language)
43+
{
44+
return "\n.nf\n{$this->normal_text($code)}\n.fi\n";
45+
}
46+
47+
public function codespan($code)
48+
{
49+
return $this->block_code($code, null);
50+
}
51+
52+
public function header($title, $level)
53+
{
54+
switch($level)
55+
{
56+
case 1:
57+
return "\n.TH {$title}\n";
58+
break;
59+
case 2:
60+
return "\n.SH {$title}\n";
61+
break;
62+
case 3:
63+
return "\n.SS {$title}\n";
64+
break;
65+
}
66+
}
67+
68+
public function double_emphasis($text)
69+
{
70+
return "\\fI{$text}\\fP";
71+
}
72+
73+
public function linebreak()
74+
{
75+
return "\n.LP\n";
76+
}
77+
78+
public function paragraph($text)
79+
{
80+
return "\n.TP\n{$text}\n";
81+
}
82+
83+
public function list_box($content, $list_type)
84+
{
85+
switch($list_type)
86+
{
87+
case 0:
88+
return "\n\n.nr step 0 1\n{$content}\n";
89+
break;
90+
case 1:
91+
return "\n.\n{$content}\n";
92+
break;
93+
}
94+
}
95+
96+
public function list_item($content, $list_type)
97+
{
98+
$content = trim($content);
99+
switch($list_type)
100+
{
101+
case 0:
102+
return ".IP \\n+[step]\n{$content}\n";
103+
break;
104+
case 1:
105+
return ".IP \\[bu] 2 \n{$content}\n";
106+
break;
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)