forked from thephpleague/html-to-markdown
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.php
169 lines (123 loc) · 3.77 KB
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
require_once( dirname( __FILE__) . '/html2markdown.php' );
$markdown = '';
$html = ($_POST) ? $_POST["html"] : null;
if ( !is_null($html) )
{
if (get_magic_quotes_gpc()) {
$html = stripslashes($html);
} else {
$html = $html;
}
$markdown = html2markdown($html);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>html2markdown demo</title>
<style>
body{font-family:helvetica, arial, sans;}
</style>
</head>
<body>
<div style="width:50%;float:left;">
<h3>HTML</h3>
<form method="post" action="">
<?php if ( !is_null($html) ): ?>
<textarea rows="30" style="width:95%" name="html" id="html"><?php echo $html ?></textarea><br />
<?php else: ?>
<textarea rows="30" style="width:95%" name="html" id="html">
<h1>A level one header</h1>
<p>Some paragraph text™ containing “UTF-8” chars…</p>
<h2>A longer level two header</h2>
<h3>Here's a <em>level 3</em> title</h3>
<p>Some text containing<br/>a forced break.</p>
<h2>Blockquotes and horizontal rules</h2>
<blockquote>Here's a blockquote</blockquote>
<hr />
<blockquote>
<p>This should have a single arrow.</p>
<blockquote>
<p>A blockquote inside a blockquote, with a double arrow, on a new line.</p>
</blockquote>
</blockquote>
<hr />
<blockquote>
<p>A multi-paragraph blockquote.</p>
<p>Here's the second paragraph. (Should be inside blockquote.)</p>
<h4>A header inside a blockquote</h4>
<p><img src="/path/img.jpg" alt="Image in a blockquote" title="Image in a blockquote" /></p>
<ul>
<li>List in a blockquote</li>
<li>Second list item</li>
</ul>
</blockquote>
<h2>Lists</h2>
<ul>
<li>An unordered list</li>
<li>Appears with hyphens</li>
</ul>
<ol>
<li>An ordered list</li>
<li>Appears with numbers.</li>
<li>Automatically indexed.</li>
</ol>
<h2>Links and images</h2>
<p><img src="/path/img.jpg" alt="alt text" title="Title" /></p>
<p>An example of a <a href="http://url.com/" title="Title">link.</a></p>
<p>An image inside a link:<br /><a href="http://url.com/" title="Title"><img src="/path/img.jpg" alt="alt text" title="Title" /></a></p>
<h2>Inline elements</h2>
<p><em>This text is in italics.</em></p>
<p><strong>This text is in bold.</strong></p>
<p>An <em>em</em> and a <strong>strong</strong> inside a paragraph.</p>
<p>A <em><span>span</span> inside</em> an em.</p>
<p>A <em><strong>strong</strong> inside</em> an em.</p>
<p>A <span><strong>strong</strong> inside</span> a span.</p>
<h2>Code blocks and spans</h2>
<p><code>
#sidebar h1 {
font-size: 1.5em;
font-weight: bold;
}
</code></p>
<p><code>A <strong>code</strong> span</code></p>
<h2>Bugs (tests from here on fail)</h2>
<h4>A list with multiple paragraphs</h4>
<ul>
<li><p>A list item.</p>
<p>With multiple paragraphs.</p></li>
<li>List item two.</li>
</ul>
<h4>Mixed ordered and unordered nested lists</h4>
<ul>
<li>List 1
<ul><li>List 2</li></ul></li>
<li>List 1b
<ol>
<li>List 3a</li>
<li>List 3b
<ul>
<li>List 4</li>
</ul>
</li>
<li>List 3c</li>
</ol>
</li>
<li>List 1c</li>
</ul></textarea>
<?php endif; ?>
<input type="submit" value="Convert HTML to Markdown >>" name="submit">
</form>
</div>
<div style="width:50%;float:right;">
<h3>Markdown</h3>
<textarea rows="30" style="width:95%; font-family:monospace;" name="markdown" id="markdown" style="font-family:monospace"><?php
echo htmlspecialchars($markdown); ?></textarea><br />
</div>
<div style="clear:both;"></div>
<h3>html2markdown for PHP</h3>
<p><a href="https://github.com/nickcernis/html2markdown">html2markdown</a> by <a href="http://twitter.com/nickcernis/">@nickcernis</a> is a PHP script to convert valid HTML into Markdown. It's available from GitHub and licensed under The MIT License.</p>
</body>
</html>