From: Michael Vogel Date: Sun, 15 Jul 2012 10:47:24 +0000 (+0200) Subject: Changes in the bbcode to markdown converter to make it more compatible with Diaspora X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4e9086f9b0a07672821c1d2dd72d01fcf639c45d;p=friendica.git Changes in the bbcode to markdown converter to make it more compatible with Diaspora --- diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 436412dbd4..25e4640b3a 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -196,6 +196,15 @@ function bb2diaspora($Text,$preserve_nl = false) { // The bbcode parser now handles youtube-links (and the other stuff) correctly. // Additionally the html code is now fixed so that lists are now working. + // Converting images with size parameters to simple images. Markdown doesn't know it. + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $Text); + + // the following was added on 10-January-2012 due to an inability of Diaspora's + // new javascript markdown processor to handle links with images as the link "text" + // It is not optimal and may be removed if this ability is restored in the future + $Text = preg_replace("/\[url\=([^\[\]]*)\]\[img\](.*?)\[\/img\]\[\/url\]/ism", + "[img]$2[/img]\n[url]$1[/url]", $Text); + // Convert it to HTML - don't try oembed $Text = bbcode($Text, $preserve_nl, false); diff --git a/include/bbcode.php b/include/bbcode.php index a90be5de70..b5f2ec5697 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -115,6 +115,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $a = get_app(); + // Move all spaces out of the tags + $Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text); + $Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text); + // Hide all [noparse] contained bbtags by spacefying them // POSSIBLE BUG --> Will the 'preg' functions crash if there's an embedded image? diff --git a/include/markdownify/markdownify.php b/include/markdownify/markdownify.php index 43730cb77f..7bbf1cbbed 100644 --- a/include/markdownify/markdownify.php +++ b/include/markdownify/markdownify.php @@ -735,6 +735,13 @@ class Markdownify { $this->parser->tagAttributes['src'] = $this->decode($this->parser->tagAttributes['src']); } +// ![Alt text](/path/to/img.jpg "Optional title") + if ($this->parser->tagAttributes['title'] != "") + $this->out('!['.$this->parser->tagAttributes['alt'].']('.$this->parser->tagAttributes['src'].'"'.$this->parser->tagAttributes['title'].'")', true); + else + $this->out('!['.$this->parser->tagAttributes['alt'].']('.$this->parser->tagAttributes['src'].')', true); + +/* # [This link][id] $link_id = false; if (!empty($this->stack['a'])) { @@ -759,6 +766,7 @@ class Markdownify { } $this->out('!['.$this->parser->tagAttributes['alt'].']['.$link_id.']', true); +*/ } /** * handle tags @@ -1181,4 +1189,4 @@ class Markdownify { function parent() { return end($this->parser->openTags); } -} \ No newline at end of file +}