From 684f91f90aa0e090f3b7b9d1064066a90bc3a035 Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 29 Mar 2021 17:02:45 -0700 Subject: [PATCH] add markdown documentation --- doc/markdown.mc | 145 +++++++++++++++++++++++++++++++++++++++++++++ include/bbcode.php | 4 +- 2 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 doc/markdown.mc diff --git a/doc/markdown.mc b/doc/markdown.mc new file mode 100644 index 000000000..6e0ae3389 --- /dev/null +++ b/doc/markdown.mc @@ -0,0 +1,145 @@ +Markdown +======== + +This software application recognises only a limited set of markdown constructs in order to avoid surprises. These usually occur if you enclude computer code or extraneous punctuation in your posts. Usage of the ***preview*** function before submitting a post or comment is encouraged. + +[h3]Bold and italic[/h3] + +Bold and italic are only recognised at the beginning of a line or after white space. +If you wish to include the special characters ( \* or \_ ) without interpreting them as markdown, precede them with a backslash '\' character or wrap the desired text in [nobb][nomd]*text to be escaped*[/nomd][/nobb] tags. + +[table] +[tr][td]Markdown[/td][td]Result[/td][/tr] +[tr][td][nomd] *italic text* [/nomd][/td][td] *italic text* [/td][/tr] +[tr][td][nomd] _italic text_ [/nomd][/td][td] _italic text_ [/td][/tr] +[tr][td][nomd] **bold text** [/nomd][/td][td] **bold text** [/td][/tr] +[tr][td][nomd] __bold text__ [/nomd][/td][td] __bold text__ [/td][/tr] +[tr][td][nomd] ***bold and italic text*** [/nomd][/td][td] ***bold and italic text*** [/td][/tr] +[tr][td][nomd] ___bold and italic text___ [/nomd][/td][td] ___bold and italic text___ [/td][/tr] + +[/table] + +[h3]Headers[/h3] + +Level headers must occur at the beginning of a line and be separated from the header text by at least one whitescape character. The exact rendering is dependent on the installed theme used and some different level headers may appear to be the same size and may include underlines or other text decoration. + +[table] +[tr][td]Markdown[/td][td]Result[/td][/tr] +[tr][td][nomd]Headline text
===========[/nomd][/td][td]

Headline text

[/td][/tr] +[tr][td][nomd]# level 1 header[/nomd][/td][td] +# level 1 header[/td][/tr] +[tr][td][nomd]## level 2 header[/nomd][/td][td] +## level 2 header[/td][/tr] +[tr][td][nomd]### level 3 header[/nomd][/td][td] +### level 3 header[/td][/tr] +[tr][td][nomd]#### level 4 header[/nomd][/td][td] +#### level 4 header[/td][/tr] +[tr][td][nomd]##### level 5 header[/nomd][/td][td] +##### level 5 header[/td][/tr] + +[/table] + + +[h3]Code and quotes[/h3] + +The markdown specification allows code blocks to be any line beginning with 4 spaces or a tab. This particular syntax rule may produce undesirable results with normal text that wasn't intended to be part of a code block and is not supported in this application. Additionally, inline code must be preceded by at least one space character and may not occur at the beginning of a line. + +[table] +[tr][td]Markdown[/td][td]Result[/td][/tr] +[tr][td][nomd] +```
+This is a code block
+spanning multiple lines
+```
+[/nomd][/td][td] +``` +This is a code block +spanning multiple lines +``` +[/td][/tr] +[tr][td][nomd] +This is an example of `inline code`. +[/nomd][/td][td] +This is an example of `inline code`. +[/td][/tr] +[tr][td][nomd] +> This is quoted text which may
+> span multiple lines.
+[/nomd][/td][td] +> This is quoted text which may +> span multiple lines. +[/td][/tr] + +[/table] + + +[h3]Links and images[/h3] + +[table] +[tr][td]Markdown[/td][td]Result[/td][/tr] +[tr][td][nomd] +[This is a hyperlink]([baseurl]) +[/nomd][/td][td] +[This is a hyperlink]([baseurl]) +[/td][/tr] +[tr][td][nomd] +![This is an image]([baseurl]/images/zot-300.png) +[/nomd][/td][td] +![This is an image]([baseurl]/images/zot-300.png) +[/td][/tr] +[/table] + + +[h3]Lists[/h3] + +As with bold and italic, the first character of an unordered list may be preceded by a backslash or wrapped in [nobb][nomd][/nomd][/nobb] tags to prevent normal text lines beginning with these characters from being interpreted as a list. + + +[table] +[tr][td]Markdown[/td][td]Result[/td][/tr] +[tr][td][nomd] +* list item 1
+* list item 2
+* list item 3
+[/nomd][/td][td] +* list item 1 +* list item 2 +* list item 3 +[/td][/tr] +[tr][td][nomd] +- list item 1
+- list item 2
+- list item 3
+[/nomd][/td][td] +- list item 1 +- list item 2 +- list item 3 +[/td][/tr] +[tr][td][nomd] ++ list item 1
++ list item 2
++ list item 3
+[/nomd][/td][td] ++ list item 1 ++ list item 2 ++ list item 3 +[/td][/tr] +[tr][td][nomd] +1. list item 1
+2. list item 2
+3. list item 3
+[/nomd][/td][td] +1. list item 1 +2. list item 2 +3. list item 3 +[/td][/tr] +[tr][td][nomd] +1) list item 1
+2) list item 2
+3) list item 3
+[/nomd][/td][td] +1) list item 1 +2) list item 2 +3) list item 3 +[/td][/tr] +[/table] diff --git a/include/bbcode.php b/include/bbcode.php index 734b5f566..caf4d3f4c 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1523,7 +1523,7 @@ function bbcode($Text, $options = []) { // do not use the "indent by tab or 4 spaces" markdown codeblock trigger - this produces way too many false positives // $Text = preg_replace('#^(?:\0(.*?)\0\n)?( {4}|\t)(.*?)$#m','
$3
',$Text); // markdown inline code blocks must be preceded by space or linebreak - $Text = preg_replace('#(^|\n| )(?$2', $Text); + $Text = preg_replace('# (?$1', $Text); // strip backslash escape for inline code $Text = preg_replace('#(\\\)`#','`',$Text); $Text = preg_replace('#<\/code><\/pre>\n
| .*?>)#','
',$Text); @@ -1542,7 +1542,7 @@ function bbcode($Text, $options = []) { // strip the backslash escape if present $Text = preg_replace('#^(\\\)([*\-+]) #m','$2',$Text); // order lists - $Text = preg_replace('#^\d+[\.] +(.*?)$#m','
  1. $1
',$Text); + $Text = preg_replace('#^\d+[\.\)] +(.*?)$#m','
  1. $1
',$Text); $Text = preg_replace('/\s*<\/(ol|ul)>\n+<\1>\s*/',"\n",$Text);