c05cd93d4759ae33b929cf17d4fb334a63a2bc7a
[yaffs-website] / vendor / michelf / php-markdown / Readme.md
1 PHP Markdown
2 ============
3
4 PHP Markdown Lib 1.8.0 - 14 Jan 2018
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 no longer maintained but will work with PHP 4.0.5 and
41 later.
42
43 Before PHP 5.3.7, pcre.backtrack_limit defaults to 100 000, which is too small
44 in many situations. You might need to set it to higher values. Later PHP
45 releases defaults to 1 000 000, which is usually fine.
46
47
48 Usage
49 -----
50
51 To use this library with Composer, first install it with:
52
53         $ composer require michelf/php-markdown
54
55 Then include Composer's generated vendor/autoload.php to [enable autoloading]:
56
57         require 'vendor/autoload.php';
58
59 Without Composer, for autoloading to work, your project needs an autoloader
60 compatible with PSR-4 or PSR-0. See the included Readme.php file for a minimal
61 autoloader setup. (If you cannot use autoloading, see below.)
62
63 With class autoloading in place:
64
65         use Michelf\Markdown;
66         $my_html = Markdown::defaultTransform($my_text);
67
68 Markdown Extra syntax is also available the same way:
69
70         use Michelf\MarkdownExtra;
71         $my_html = MarkdownExtra::defaultTransform($my_text);
72
73 If you wish to use PHP Markdown with another text filter function
74 built to parse HTML, you should filter the text *after* the `transform`
75 function call. This is an example with [PHP SmartyPants]:
76
77         use Michelf\Markdown, Michelf\SmartyPants;
78         $my_html = Markdown::defaultTransform($my_text);
79         $my_html = SmartyPants::defaultTransform($my_html);
80
81 All these examples are using the static `defaultTransform` static function
82 found inside the parser class. If you want to customize the parser
83 configuration, you can also instantiate it directly and change some
84 configuration variables:
85
86         use Michelf\MarkdownExtra;
87         $parser = new MarkdownExtra;
88         $parser->fn_id_prefix = "post22-";
89         $my_html = $parser->transform($my_text);
90
91 To learn more, see the full list of [configuration variables].
92
93  [enable autoloading]: https://getcomposer.org/doc/01-basic-usage.md#autoloading
94  [PHP SmartyPants]: https://michelf.ca/projects/php-smartypants/
95  [configuration variables]: https://michelf.ca/projects/php-markdown/configuration/
96
97
98 ### Usage without an autoloader
99
100 If you cannot use class autoloading, you can still use `include` or `require`
101 to access the parser. To load the `Michelf\Markdown` parser, do it this way:
102
103         require_once 'Michelf/Markdown.inc.php';
104
105 Or, if you need the `Michelf\MarkdownExtra` parser:
106
107         require_once 'Michelf/MarkdownExtra.inc.php';
108
109 While the plain `.php` files depend on autoloading to work correctly, using the
110 `.inc.php` files instead will eagerly load the dependencies that would be
111 loaded on demand if you were using autoloading.
112
113
114 Public API and Versioning Policy
115 ---------------------------------
116
117 Version numbers are of the form *major*.*minor*.*patch*.
118
119 The public API of PHP Markdown consist of the two parser classes `Markdown`
120 and `MarkdownExtra`, their constructors, the `transform` and `defaultTransform`
121 functions and their configuration variables. The public API is stable for
122 a given major version number. It might get additions when the minor version
123 number increments.
124
125 **Protected members are not considered public API.** This is unconventional
126 and deserves an explanation. Incrementing the major version number every time
127 the underlying implementation of something changes is going to give
128 nonessential version numbers for the vast majority of people who just use the
129 parser.  Protected members are meant to create parser subclasses that behave in
130 different ways. Very few people create parser subclasses. I don't want to
131 discourage it by making everything private, but at the same time I can't
132 guarantee any stable hook between versions if you use protected members.
133
134 **Syntax changes** will increment the minor number for new features, and the
135 patch number for small corrections. A *new feature* is something that needs a
136 change in the syntax documentation. Note that since PHP Markdown Lib includes
137 two parsers, a syntax change for either of them will increment the minor
138 number. Also note that there is nothing perfectly backward-compatible with the
139 Markdown syntax: all inputs are always valid, so new features always replace
140 something that was previously legal, although generally nonsensical to do.
141
142
143 Bugs
144 ----
145
146 To file bug reports please send email to:
147 <michel.fortin@michelf.ca>
148
149 Please include with your report: (1) the example input; (2) the output you
150 expected; (3) the output PHP Markdown actually produced.
151
152 If you have a problem where Markdown gives you an empty result, first check
153 that the backtrack limit is not too low by running `php --info | grep pcre`.
154 See Installation and Requirement above for details.
155
156
157 Development and Testing
158 -----------------------
159
160 Pull requests for fixing bugs are welcome. Proposed new features are
161 going to be meticulously reviewed -- taking into account backward compatibility,
162 potential side effects, and future extensibility -- before deciding on
163 acceptance or rejection.
164
165 If you make a pull request that includes changes to the parser please add
166 tests for what is being changed to [MDTest][] and make a pull request there
167 too.
168
169  [MDTest]: https://github.com/michelf/mdtest/
170
171
172 Donations
173 ---------
174
175 If you wish to make a donation that will help me devote more time to
176 PHP Markdown, please visit [michelf.ca/donate] or send Bitcoin to
177 [1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH].
178
179  [michelf.ca/donate]: https://michelf.ca/donate/#!Thanks%20for%20PHP%20Markdown
180  [1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH]: bitcoin:1HiuX34czvVPPdhXbUAsAu7pZcesniDCGH
181
182
183 Version History
184 ---------------
185
186 PHP Markdown Lib 1.8.0 (14 Jan 2018)
187
188 *       Autoloading with Composer now uses PSR-4.
189
190 *       HTML output for Markdown Extra footnotes now include `role` attributes
191         with values from [WAI-ARIA](https://www.w3.org/TR/dpub-aria/) to
192         make them more accessible.
193         (Thanks to Tobias Bengfort)
194
195 *       In Markdown Extra, added the `hashtag_protection` configuration variable.
196         When set to `true` it prevents ATX-style headers with no space after the initial
197         hash from being interpreted as headers. This way your precious hashtags
198         are preserved.
199         (Thanks to Jaussoin Timothée for the implementation.)
200
201
202 PHP Markdown Lib 1.7.0 (29 Oct 2016)
203
204 *       Added a `hard_wrap` configuration variable to make all newline characters
205         in the text become `<br>` tags in the HTML output. By default, according
206         to the standard Markdown syntax these newlines are ignored unless they a
207         preceded by two spaces. Thanks to Jonathan Cohlmeyer for the implementation.
208
209 *       Improved the parsing of list items to fix problematic cases that came to
210         light with the addition of `hard_wrap`. This should have no effect on the
211         output except span-level list items that ended with two spaces (and thus
212         ended with a line break).
213
214 *       Added a `code_span_content_func` configuration variable which takes a
215         function that will convert the content of the code span to HTML. This can
216         be useful to implement syntax highlighting. Although contrary to its
217         code block equivalent, there is no syntax for specifying a language.
218         Credits to styxit for the implementation.
219
220 *       Fixed a Markdown Extra issue where two-space-at-end-of-line hard breaks
221         wouldn't work inside of HTML block elements such as `<p markdown="1">`
222         where the element expects only span-level content.
223
224 *       In the parser code, switched to PHPDoc comment format. Thanks to
225         Robbie Averill for the help.
226
227
228 PHP Markdown Lib 1.6.0 (23 Dec 2015)
229
230 Note: this version was incorrectly released as 1.5.1 on Dec 22, a number
231 that contradicted the versioning policy.
232
233 *       For fenced code blocks in Markdown Extra, can now set a class name for the
234         code block's language before the special attribute block. Previously, this
235         class name was only allowed in the absence of the special attribute block.
236
237 *       Added a `code_block_content_func` configuration variable which takes a
238         function that will convert the content of the code block to HTML. This is
239         most useful for syntax highlighting. For fenced code blocks in Markdown
240         Extra, the function has access to the language class name (the one outside
241         of the special attribute block). Credits to Mario Konrad for providing the
242         implementation.
243
244 *       The curled arrow character for the backlink in footnotes is now followed
245         by a Unicode variant selector to prevent it from being displayed in emoji
246         form on iOS.
247
248         Note that in older browsers the variant selector is often interpreted as a
249         separate character, making it visible after the arrow. So there is now a
250         also a `fn_backlink_html` configuration variable that can be used to set
251         the link text to something else. Credits to Dana for providing the
252         implementation.
253
254 *       Fixed an issue in MarkdownExtra where long header lines followed by a
255         special attribute block would hit the backtrack limit an cause an empty
256         string to be returned.
257
258
259 PHP Markdown Lib 1.5.0 (1 Mar 2015)
260
261 *       Added the ability start ordered lists with a number different from 1 and
262         and have that reflected in the HTML output. This can be enabled with
263         the `enhanced_ordered_lists` configuration variable for the Markdown
264         parser; it is enabled by default for Markdown Extra.
265         Credits to Matt Gorle for providing the implementation.
266
267 *       Added the ability to insert custom HTML attributes with simple values
268         everywhere an extra attribute block is allowed (links, images, headers).
269         The value must be unquoted, cannot contains spaces and is limited to
270         alphanumeric ASCII characters.
271         Credits to Peter Droogmans for providing the implementation.
272
273 *       Added a `header_id_func` configuration variable which takes a function
274         that can generate an `id` attribute value from the header text.
275         Credits to Evert Pot for providing the implementation.
276
277 *       Added a `url_filter_func` configuration variable which takes a function
278         that can rewrite any link or image URL to something different.
279
280
281 PHP Markdown Lib 1.4.1 (4 May 2014)
282
283 *       The HTML block parser will now treat `<figure>` as a block-level element
284         (as it should) and no longer wrap it in `<p>` or parse it's content with
285         the as Markdown syntax (although with Extra you can use `markdown="1"`
286         if you wish to use the Markdown syntax inside it).
287
288 *       The content of `<style>` elements will now be left alone, its content
289         won't be interpreted as Markdown.
290
291 *       Corrected an bug where some inline links with spaces in them would not
292         work even when surounded with angle brackets:
293
294                 [link](<s p a c e s>)
295
296 *       Fixed an issue where email addresses with quotes in them would not always
297         have the quotes escaped in the link attribute, causing broken links (and
298         invalid HTML).
299
300 *       Fixed the case were a link definition following a footnote definition would
301         be swallowed by the footnote unless it was separated by a blank line.
302
303
304 PHP Markdown Lib 1.4.0 (29 Nov 2013)
305
306 *       Added support for the `tel:` URL scheme in automatic links.
307
308                 <tel:+1-111-111-1111>
309
310         It gets converted to this (note the `tel:` prefix becomes invisible):
311
312                 <a href="tel:+1-111-111-1111">+1-111-111-1111</a>
313
314 *       Added backtick fenced code blocks to MarkdownExtra, originally from
315         Github-Flavored Markdown.
316
317 *       Added an interface called MarkdownInterface implemented by both
318         the Markdown and MarkdownExtra parsers. You can use the interface if
319         you want to create a mockup parser object for unit testing.
320
321 *       For those of you who cannot use class autoloading, you can now
322         include `Michelf/Markdown.inc.php` or `Michelf/MarkdownExtra.inc.php` (note
323         the     `.inc.php` extension) to automatically include other files required
324         by the parser.
325
326
327 PHP Markdown Lib 1.3 (11 Apr 2013)
328
329 This is the first release of PHP Markdown Lib. This package requires PHP
330 version 5.3 or later and is designed to work with PSR-0 autoloading and,
331 optionally with Composer. Here is a list of the changes since
332 PHP Markdown Extra 1.2.6:
333
334 *       Plugin interface for WordPress and other systems is no longer present in
335         the Lib package. The classic package is still available if you need it:
336         <https://michelf.ca/projects/php-markdown/classic/>
337
338 *       Added `public` and `protected` protection attributes, plus a section about
339         what is "public API" and what isn't in the Readme file.
340
341 *       Changed HTML output for footnotes: now instead of adding `rel` and `rev`
342         attributes, footnotes links have the class name `footnote-ref` and
343         backlinks `footnote-backref`.
344
345 *       Fixed some regular expressions to make PCRE not shout warnings about POSIX
346         collation classes (dependent on your version of PCRE).
347
348 *       Added optional class and id attributes to images and links using the same
349         syntax as for headers:
350
351                 [link](url){#id .class}
352                 ![img](url){#id .class}
353
354         It work too for reference-style links and images. In this case you need
355         to put those attributes at the reference definition:
356
357                 [link][linkref] or [linkref]
358                 ![img][linkref]
359
360                 [linkref]: url "optional title" {#id .class}
361
362 *       Fixed a PHP notice message triggered when some table column separator
363         markers are missing on the separator line below column headers.
364
365 *       Fixed a small mistake that could cause the parser to retain an invalid
366         state related to parsing links across multiple runs. This was never
367         observed (that I know of), but it's still worth fixing.
368
369
370 Copyright and License
371 ---------------------
372
373 PHP Markdown Lib
374 Copyright (c) 2004-2016 Michel Fortin
375 <https://michelf.ca/>  
376 All rights reserved.
377
378 Based on Markdown  
379 Copyright (c) 2003-2005 John Gruber  
380 <https://daringfireball.net/>  
381 All rights reserved.
382
383 Redistribution and use in source and binary forms, with or without
384 modification, are permitted provided that the following conditions are
385 met:
386
387 *   Redistributions of source code must retain the above copyright
388     notice, this list of conditions and the following disclaimer.
389
390 *   Redistributions in binary form must reproduce the above copyright
391     notice, this list of conditions and the following disclaimer in the
392     documentation and/or other materials provided with the
393     distribution.
394
395 *   Neither the name "Markdown" nor the names of its contributors may
396     be used to endorse or promote products derived from this software
397     without specific prior written permission.
398
399 This software is provided by the copyright holders and contributors "as
400 is" and any express or implied warranties, including, but not limited
401 to, the implied warranties of merchantability and fitness for a
402 particular purpose are disclaimed. In no event shall the copyright owner
403 or contributors be liable for any direct, indirect, incidental, special,
404 exemplary, or consequential damages (including, but not limited to,
405 procurement of substitute goods or services; loss of use, data, or
406 profits; or business interruption) however caused and on any theory of
407 liability, whether in contract, strict liability, or tort (including
408 negligence or otherwise) arising in any way out of the use of this
409 software, even if advised of the possibility of such damage.