-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
153 lines (134 loc) · 4.33 KB
/
index.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
<?php
$code = '<p>hello world</p>';
if (isset($_POST['code']) && $_POST['code'] != '') {
$code = $_POST['code'];
}
if (preg_match_all('/<(.+?)>/s', $code, $match)) {
$tags = $match[0];
$elem = $match[1];
$_code = '';
foreach (preg_split('/<(.+?)>/s', $code) as $i => $text) {
$tag = '';
if (isset($tags[$i])) {
$tag = htmlspecialchars($tags[$i], ENT_NOQUOTES);
$class = '';
if (preg_match('/^[\/]{0,1}(style|script)/si', $elem[$i], $match)) {
$class = ' class="' . str_replace('/', '', $match[0]) . '"';
} else {
$tag = preg_replace('/(?<= )([a-z]+)(?==)/si', '<i>$1</i>', $tag);
$tag = preg_replace('/("(.*?)")/s', '<b>$1</b>', $tag);
}
$tag = '<span' . $class . '>' . $tag . '</span>';
}
$_code .= $text . $tag;
}
} else {
$_code = $code;
}
if (isset($_POST['ajax'])) {
header('Content-type: application/xml');
?>
<?xml version="1.0" encoding="utf-8"?>
<response>
<code><?php echo htmlspecialchars($_code) . "\n" ?></code>
<result><![CDATA[<?php echo $_code ?>]]></result>
</response>
<?php
exit;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML prezr - convert code to entities with highlighted syntax</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<article>
<header>
<h1>HTML pre<i>zr</i></h1>
<p>Convert your <abbr title="HyperText Markup Language">HTML</abbr> to entities, copy the returned code and paste it between <code><span><pre></span><span></pre></span></code>. Add the style to your <abbr title="Cascade Style Sheet">CSS</abbr> for highlight the syntax.</p>
</header>
<form action="index.php" method="post">
<fieldset>
<legend>Paste your code here</legend>
<textarea name="code" id="code" cols="10" rows="5"><?php echo htmlspecialchars($code) ?></textarea>
<button type="submit">Enjoy!</button>
</fieldset>
</form>
<section>
<h2>The code</h2>
<pre>
<span><html></span>
<textarea id="_code" cols="10" rows="5"><?php echo htmlspecialchars($_code) . "\n" ?></textarea>
<span></html></span>
</pre>
</section>
<section>
<h2>The result</h2>
<pre id="result">
<?php echo $_code ?>
</pre>
</section>
<section>
<h2>The style</h2>
<pre>
<span class="style"><style></span>
<textarea cols="10" rows="5">
span {
color: #0000ff;
}
.script, .style {
color: #800080;
}
b {
color: #008080;
}
i {
color: #000080;
font-style: normal;
}
</textarea>
<span class="style"></style></span>
</pre>
</section>
<footer>
<h2>Credits</h2>
<p>Created by <a href="http://kawerin.com.ar">Camilo Kawerín</a> from <a href="http://convistaalmar.com.ar/">Con Vista Al Mar</a> in a saturday’s afternoon of June 2011.</p>
<p><b>Current version is 0.1.</b></p>
<h3>TO-DO</h3>
<ul>
<li><s>Offer to switch to a <i>white on black</i> style</s> Allow to submit your preferred colors!</li>
<li>Show <i>presets</i> and user submitted palettes for quick choice.</li>
<li>Support syntax highlight for CSS and Javascript</li>
</ul>
<h3>Unlicense</h3>
<pre class="unlicense">
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
</pre>
</footer>
</article>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>