Changes in the bbcode to markdown converter to make it more compatible with Diaspora

This commit is contained in:
Michael Vogel 2012-07-15 12:47:24 +02:00
parent 8d7d46ae7a
commit 4e9086f9b0
3 changed files with 22 additions and 1 deletions

View File

@ -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);

View File

@ -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?

View File

@ -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 <code> tags
@ -1181,4 +1189,4 @@ class Markdownify {
function parent() {
return end($this->parser->openTags);
}
}
}