]> git.mxchange.org Git - friendica.git/blob - library/php-markdown/Readme.md
Merge pull request #2148 from annando/issue-1871
[friendica.git] / library / php-markdown / Readme.md
1 PHP Markdown
2 ============
3
4 PHP Markdown Lib 1.4.1 - 4 May 2013
5
6 by Michel Fortin  
7 <http://michelf.ca/>
8
9 based on Markdown by John Gruber  
10 <http://daringfireball.net/>
11
12
13 Introduction
14 ------------
15
16 This is a library package that includes the PHP Markdown parser and its 
17 sibling PHP Markdown Extra with additional features.
18
19 Markdown is a text-to-HTML conversion tool for web writers. Markdown
20 allows you to write using an easy-to-read, easy-to-write plain text
21 format, then convert it to structurally valid XHTML (or HTML).
22
23 "Markdown" is actually two things: a plain text markup syntax, and a 
24 software tool, originally written in Perl, that converts the plain text 
25 markup to HTML. PHP Markdown is a port to PHP of the original Markdown 
26 program by John Gruber.
27
28 *       [Full documentation of the Markdown syntax](<http://daringfireball.net/projects/markdown/>)
29         - Daring Fireball (John Gruber)
30 *       [Markdown Extra syntax additions](<http://michelf.ca/projects/php-markdown/extra/>)
31         - Michel Fortin
32
33
34 Requirement
35 -----------
36
37 This library package requires PHP 5.3 or later.
38
39 Note: The older plugin/library hybrid package for PHP Markdown and
40 PHP Markdown Extra is still maintained and will work with PHP 4.0.5 and later.
41
42 Before PHP 5.3.7, pcre.backtrack_limit defaults to 100 000, which is too small
43 in many situations. You might need to set it to higher values. Later PHP 
44 releases defaults to 1 000 000, which is usually fine.
45
46
47 Usage
48 -----
49
50 This library package is meant to be used with class autoloading. For autoloading 
51 to work, your project needs have setup a PSR-0-compatible autoloader. See the 
52 included Readme.php file for a minimal autoloader setup. (If you cannot use 
53 autoloading, see below.)
54
55 With class autoloading in place, putting the 'Michelf' folder in your 
56 include path should be enough for this to work:
57
58         use \Michelf\Markdown;
59         $my_html = Markdown::defaultTransform($my_text);
60
61 Markdown Extra syntax is also available the same way:
62
63         use \Michelf\MarkdownExtra;
64         $my_html = MarkdownExtra::defaultTransform($my_text);
65
66 If you wish to use PHP Markdown with another text filter function 
67 built to parse HTML, you should filter the text *after* the `transform`
68 function call. This is an example with [PHP SmartyPants][psp]:
69
70         use \Michelf\Markdown, \Michelf\SmartyPants;
71         $my_html = Markdown::defaultTransform($my_text);
72         $my_html = SmartyPants::defaultTransform($my_html);
73
74 All these examples are using the static `defaultTransform` static function 
75 found inside the parser class. If you want to customize the parser 
76 configuration, you can also instantiate it directly and change some 
77 configuration variables:
78
79         use \Michelf\MarkdownExtra;
80         $parser = new MarkdownExtra;
81         $parser->fn_id_prefix = "post22-";
82         $my_html = $parser->transform($my_text);
83
84 To learn more, see the full list of [configuration variables].
85
86  [configuration variables]: http://michelf.ca/projects/php-markdown/configuration/
87
88
89 ### Usage without an autoloader
90
91 If you cannot use class autoloading, you can still use `include` or `require` 
92 to access the parser. To load the `\Michelf\Markdown` parser, do it this way:
93
94         require_once 'Michelf/Markdown.inc.php';
95
96 Or, if you need the `\Michelf\MarkdownExtra` parser:
97
98         require_once 'Michelf/MarkdownExtra.inc.php';
99
100 While the plain `.php` files depend on autoloading to work correctly, using the
101 `.inc.php` files instead will eagerly load the dependencies that would be 
102 loaded on demand if you were using autoloading.
103
104
105 Public API and Versioning Policy
106 ---------------------------------
107
108 Version numbers are of the form *major*.*minor*.*patch*.
109
110 The public API of PHP Markdown consist of the two parser classes `Markdown`
111 and `MarkdownExtra`, their constructors, the `transform` and `defaultTransform`
112 functions and their configuration variables. The public API is stable for
113 a given major version number. It might get additions when the minor version
114 number increments.
115
116 **Protected members are not considered public API.** This is unconventional 
117 and deserves an explanation. Incrementing the major version number every time 
118 the underlying implementation of something changes is going to give
119 nonessential version numbers for the vast majority of people who just use the
120 parser.  Protected members are meant to create parser subclasses that behave in
121 different ways. Very few people create parser subclasses. I don't want to 
122 discourage it by making everything private, but at the same time I can't 
123 guarantee any stable hook between versions if you use protected members.
124
125 **Syntax changes** will increment the minor number for new features, and the 
126 patch number for small corrections. A *new feature* is something that needs a 
127 change in the syntax documentation. Note that since PHP Markdown Lib includes
128 two parsers, a syntax change for either of them will increment the minor 
129 number. Also note that there is nothing perfectly backward-compatible with the
130 Markdown syntax: all inputs are always valid, so new features always replace
131 something that was previously legal, although generally nonsensical to do.
132
133
134 Bugs
135 ----
136
137 To file bug reports please send email to:
138 <michel.fortin@michelf.ca>
139
140 Please include with your report: (1) the example input; (2) the output you
141 expected; (3) the output PHP Markdown actually produced.
142
143 If you have a problem where Markdown gives you an empty result, first check 
144 that the backtrack limit is not too low by running `php --info | grep pcre`.
145 See Installation and Requirement above for details.
146
147
148 Development and Testing
149 -----------------------
150
151 Pull requests for fixing bugs are welcome. Proposed new features are
152 going meticulously reviewed -- taking into account backward compatibility, 
153 potential side effects, and future extensibility -- before deciding on
154 acceptance or rejection.
155
156 If you make a pull request that includes changes to the parser please add 
157 tests for what is being changed to [MDTest][] and make a pull request there 
158 too.
159
160  [MDTest]: https://github.com/michelf/mdtest/
161
162
163 Donations
164 ---------
165
166 If you wish to make a donation that will help me devote more time to 
167 PHP Markdown, please visit [michelf.ca/donate] or send Bitcoin to
168 [1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH].
169
170  [michelf.ca/donate]: https://michelf.ca/donate/#!Thanks%20for%20PHP%20Markdown
171  [1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH]: bitcoin:1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH
172
173
174 Version History
175 ---------------
176
177 Unreleased
178
179 *       Added the ability to insert custom HTML attributes everywhere an extra
180         attribute block is allowed (links, images, headers). Credits to
181         Peter Droogmans for providing the implementation.
182
183 *       Added a `url_filter_func` configuration variable which takes a function
184         that can rewrite any link or image URL to something different.
185
186
187 PHP Markdown Lib 1.4.1 (4 May 2014)
188
189 *       The HTML block parser will now treat `<figure>` as a block-level element
190         (as it should) and no longer wrap it in `<p>` or parse it's content with 
191         the as Markdown syntax (although with Extra you can use `markdown="1"`
192         if you wish to use the Markdown syntax inside it).
193
194 *       The content of `<style>` elements will now be left alone, its content
195         won't be interpreted as Markdown.
196
197 *       Corrected an bug where some inline links with spaces in them would not
198         work even when surounded with angle brackets:
199         
200                 [link](<s p a c e s>)
201
202 *       Fixed an issue where email addresses with quotes in them would not always
203         have the quotes escaped in the link attribute, causing broken links (and
204         invalid HTML).
205
206 *       Fixed the case were a link definition following a footnote definition would
207         be swallowed by the footnote unless it was separated by a blank line.
208
209
210 PHP Markdown Lib 1.4.0 (29 Nov 2013)
211
212 *       Added support for the `tel:` URL scheme in automatic links.
213
214                 <tel:+1-111-111-1111>
215         
216         It gets converted to this (note the `tel:` prefix becomes invisible):
217         
218                 <a href="tel:+1-111-111-1111">+1-111-111-1111</a>
219
220 *       Added backtick fenced code blocks to MarkdownExtra, originally from
221         Github-Flavored Markdown.
222
223 *       Added an interface called MarkdownInterface implemented by both
224         the Markdown and MarkdownExtra parsers. You can use the interface if
225         you want to create a mockup parser object for unit testing.
226
227 *       For those of you who cannot use class autoloading, you can now
228         include `Michelf/Markdown.inc.php` or `Michelf/MarkdownExtra.inc.php` (note 
229         the     `.inc.php` extension) to automatically include other files required
230         by the parser.
231
232
233 PHP Markdown Lib 1.3 (11 Apr 2013)
234
235 This is the first release of PHP Markdown Lib. This package requires PHP 
236 version 5.3 or later and is designed to work with PSR-0 autoloading and, 
237 optionally with Composer. Here is a list of the changes since 
238 PHP Markdown Extra 1.2.6:
239
240 *       Plugin interface for WordPress and other systems is no longer present in
241         the Lib package. The classic package is still available if you need it:
242         <http://michelf.ca/projects/php-markdown/classic/>
243
244 *       Added `public` and `protected` protection attributes, plus a section about
245         what is "public API" and what isn't in the Readme file.
246
247 *       Changed HTML output for footnotes: now instead of adding `rel` and `rev`
248         attributes, footnotes links have the class name `footnote-ref` and
249         backlinks `footnote-backref`.
250
251 *       Fixed some regular expressions to make PCRE not shout warnings about POSIX
252         collation classes (dependent on your version of PCRE).
253
254 *       Added optional class and id attributes to images and links using the same
255         syntax as for headers:
256
257                 [link](url){#id .class}  
258                 ![img](url){#id .class}
259         
260         It work too for reference-style links and images. In this case you need
261         to put those attributes at the reference definition:
262
263                 [link][linkref] or [linkref]  
264                 ![img][linkref]
265                 
266                 [linkref]: url "optional title" {#id .class}
267
268 *       Fixed a PHP notice message triggered when some table column separator 
269         markers are missing on the separator line below column headers.
270
271 *       Fixed a small mistake that could cause the parser to retain an invalid
272         state related to parsing links across multiple runs. This was never 
273         observed (that I know of), but it's still worth fixing.
274
275
276 Copyright and License
277 ---------------------
278
279 PHP Markdown Lib
280 Copyright (c) 2004-2014 Michel Fortin
281 <http://michelf.ca/>  
282 All rights reserved.
283
284 Based on Markdown  
285 Copyright (c) 2003-2005 John Gruber   
286 <http://daringfireball.net/>   
287 All rights reserved.
288
289 Redistribution and use in source and binary forms, with or without
290 modification, are permitted provided that the following conditions are
291 met:
292
293 *   Redistributions of source code must retain the above copyright 
294     notice, this list of conditions and the following disclaimer.
295
296 *   Redistributions in binary form must reproduce the above copyright
297     notice, this list of conditions and the following disclaimer in the
298     documentation and/or other materials provided with the 
299     distribution.
300
301 *   Neither the name "Markdown" nor the names of its contributors may
302     be used to endorse or promote products derived from this software
303     without specific prior written permission.
304
305 This software is provided by the copyright holders and contributors "as
306 is" and any express or implied warranties, including, but not limited
307 to, the implied warranties of merchantability and fitness for a
308 particular purpose are disclaimed. In no event shall the copyright owner
309 or contributors be liable for any direct, indirect, incidental, special,
310 exemplary, or consequential damages (including, but not limited to,
311 procurement of substitute goods or services; loss of use, data, or
312 profits; or business interruption) however caused and on any theory of
313 liability, whether in contract, strict liability, or tort (including
314 negligence or otherwise) arising in any way out of the use of this
315 software, even if advised of the possibility of such damage.