]> git.mxchange.org Git - friendica.git/blob - vendor/michelf/php-markdown/Readme.md
044407106e1770fdb0e0152ff899db584215cfa4
[friendica.git] / vendor / michelf / php-markdown / Readme.md
1 PHP Markdown
2 ============
3
4 PHP Markdown Lib 1.7.0 - 29 Oct 2016
5
6 by Michel Fortin  
7 <https://michelf.ca/>
8
9 based on Markdown by John Gruber  
10 <https://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](<https://daringfireball.net/projects/markdown/>)  
29         — Daring Fireball (John Gruber)
30 *       [Markdown Extra syntax additions](<https://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]: https://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 to be 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 PHP Markdown Lib 1.7.0 (29 Oct 2016)
178
179 *       Added a `hard_wrap` configuration variable to make all newline characters 
180         in the text become `<br>` tags in the HTML output. By default, according 
181         to the standard Markdown syntax these newlines are ignored unless they a 
182         preceded by two spaces. Thanks to Jonathan Cohlmeyer for the implementation.
183
184 *       Improved the parsing of list items to fix problematic cases that came to 
185         light with the addition of `hard_wrap`. This should have no effect on the 
186         output except span-level list items that ended with two spaces (and thus 
187         ended with a line break).
188
189 *       Added a `code_span_content_func` configuration variable which takes a 
190         function that will convert the content of the code span to HTML. This can
191         be useful to implement syntax highlighting. Although contrary to its 
192         code block equivalent, there is no syntax for specifying a language. 
193         Credits to styxit for the implementation.
194
195 *       Fixed a Markdwon Extra issue where two-space-at-end-of-line hard breaks 
196         wouldn't work inside of HTML block elements such as `<p markdown="1">` 
197         where the element expects only span-level content.
198
199 *       In the parser code, switched to PHPDoc comment format. Thanks to 
200         Robbie Averill for the help.
201
202
203 PHP Markdown Lib 1.6.0 (23 Dec 2015)  
204
205 Note: this version was incorrectly released as 1.5.1 on Dec 22, a number 
206 that contradicted the versioning policy.
207
208 *       For fenced code blocks in Markdown Extra, can now set a class name for the 
209         code block's language before the special attribute block. Previously, this 
210         class name was only allowed in the absence of the special attribute block.
211
212 *       Added a `code_block_content_func` configuration variable which takes a 
213         function that will convert the content of the code block to HTML. This is 
214         most useful for syntax highlighting. For fenced code blocks in Markdown 
215         Extra, the function has access to the language class name (the one outside 
216         of the special attribute block). Credits to Mario Konrad for providing the 
217         implementation.
218
219 *       The curled arrow character for the backlink in footnotes is now followed
220         by a Unicode variant selector to prevent it from being displayed in emoji
221         form on iOS.
222
223         Note that in older browsers the variant selector is often interpreted as a 
224         separate character, making it visible after the arrow. So there is now a 
225         also a `fn_backlink_html` configuration variable that can be used to set 
226         the link text to something else. Credits to Dana for providing the 
227         implementation.
228
229 *       Fixed an issue in MarkdownExtra where long header lines followed by a
230         special attribute block would hit the backtrack limit an cause an empty
231         string to be returned.
232
233
234 PHP Markdown Lib 1.5.0 (1 Mar 2015)
235
236 *       Added the ability start ordered lists with a number different from 1 and
237         and have that reflected in the HTML output. This can be enabled with
238         the `enhanced_ordered_lists` configuration variable for the Markdown 
239         parser; it is enabled by default for Markdown Extra.
240         Credits to Matt Gorle for providing the implementation.
241
242 *       Added the ability to insert custom HTML attributes with simple values 
243         everywhere an extra attribute block is allowed (links, images, headers).
244         The value must be unquoted, cannot contains spaces and is limited to 
245         alphanumeric ASCII characters.
246         Credits to Peter Droogmans for providing the implementation.
247
248 *       Added a `header_id_func` configuration variable which takes a function
249         that can generate an `id` attribute value from the header text.
250         Credits to Evert Pot for providing the implementation.
251
252 *       Added a `url_filter_func` configuration variable which takes a function
253         that can rewrite any link or image URL to something different.
254
255
256 PHP Markdown Lib 1.4.1 (4 May 2014)
257
258 *       The HTML block parser will now treat `<figure>` as a block-level element
259         (as it should) and no longer wrap it in `<p>` or parse it's content with 
260         the as Markdown syntax (although with Extra you can use `markdown="1"`
261         if you wish to use the Markdown syntax inside it).
262
263 *       The content of `<style>` elements will now be left alone, its content
264         won't be interpreted as Markdown.
265
266 *       Corrected an bug where some inline links with spaces in them would not
267         work even when surounded with angle brackets:
268         
269                 [link](<s p a c e s>)
270
271 *       Fixed an issue where email addresses with quotes in them would not always
272         have the quotes escaped in the link attribute, causing broken links (and
273         invalid HTML).
274
275 *       Fixed the case were a link definition following a footnote definition would
276         be swallowed by the footnote unless it was separated by a blank line.
277
278
279 PHP Markdown Lib 1.4.0 (29 Nov 2013)
280
281 *       Added support for the `tel:` URL scheme in automatic links.
282
283                 <tel:+1-111-111-1111>
284         
285         It gets converted to this (note the `tel:` prefix becomes invisible):
286         
287                 <a href="tel:+1-111-111-1111">+1-111-111-1111</a>
288
289 *       Added backtick fenced code blocks to MarkdownExtra, originally from
290         Github-Flavored Markdown.
291
292 *       Added an interface called MarkdownInterface implemented by both
293         the Markdown and MarkdownExtra parsers. You can use the interface if
294         you want to create a mockup parser object for unit testing.
295
296 *       For those of you who cannot use class autoloading, you can now
297         include `Michelf/Markdown.inc.php` or `Michelf/MarkdownExtra.inc.php` (note 
298         the     `.inc.php` extension) to automatically include other files required
299         by the parser.
300
301
302 PHP Markdown Lib 1.3 (11 Apr 2013)
303
304 This is the first release of PHP Markdown Lib. This package requires PHP 
305 version 5.3 or later and is designed to work with PSR-0 autoloading and, 
306 optionally with Composer. Here is a list of the changes since 
307 PHP Markdown Extra 1.2.6:
308
309 *       Plugin interface for WordPress and other systems is no longer present in
310         the Lib package. The classic package is still available if you need it:
311         <https://michelf.ca/projects/php-markdown/classic/>
312
313 *       Added `public` and `protected` protection attributes, plus a section about
314         what is "public API" and what isn't in the Readme file.
315
316 *       Changed HTML output for footnotes: now instead of adding `rel` and `rev`
317         attributes, footnotes links have the class name `footnote-ref` and
318         backlinks `footnote-backref`.
319
320 *       Fixed some regular expressions to make PCRE not shout warnings about POSIX
321         collation classes (dependent on your version of PCRE).
322
323 *       Added optional class and id attributes to images and links using the same
324         syntax as for headers:
325
326                 [link](url){#id .class}  
327                 ![img](url){#id .class}
328         
329         It work too for reference-style links and images. In this case you need
330         to put those attributes at the reference definition:
331
332                 [link][linkref] or [linkref]  
333                 ![img][linkref]
334                 
335                 [linkref]: url "optional title" {#id .class}
336
337 *       Fixed a PHP notice message triggered when some table column separator 
338         markers are missing on the separator line below column headers.
339
340 *       Fixed a small mistake that could cause the parser to retain an invalid
341         state related to parsing links across multiple runs. This was never 
342         observed (that I know of), but it's still worth fixing.
343
344
345 Copyright and License
346 ---------------------
347
348 PHP Markdown Lib
349 Copyright (c) 2004-2016 Michel Fortin
350 <https://michelf.ca/>  
351 All rights reserved.
352
353 Based on Markdown  
354 Copyright (c) 2003-2005 John Gruber   
355 <https://daringfireball.net/>   
356 All rights reserved.
357
358 Redistribution and use in source and binary forms, with or without
359 modification, are permitted provided that the following conditions are
360 met:
361
362 *   Redistributions of source code must retain the above copyright 
363     notice, this list of conditions and the following disclaimer.
364
365 *   Redistributions in binary form must reproduce the above copyright
366     notice, this list of conditions and the following disclaimer in the
367     documentation and/or other materials provided with the 
368     distribution.
369
370 *   Neither the name "Markdown" nor the names of its contributors may
371     be used to endorse or promote products derived from this software
372     without specific prior written permission.
373
374 This software is provided by the copyright holders and contributors "as
375 is" and any express or implied warranties, including, but not limited
376 to, the implied warranties of merchantability and fitness for a
377 particular purpose are disclaimed. In no event shall the copyright owner
378 or contributors be liable for any direct, indirect, incidental, special,
379 exemplary, or consequential damages (including, but not limited to,
380 procurement of substitute goods or services; loss of use, data, or
381 profits; or business interruption) however caused and on any theory of
382 liability, whether in contract, strict liability, or tort (including
383 negligence or otherwise) arising in any way out of the use of this
384 software, even if advised of the possibility of such damage.