It seems that all the simplified syntaxes for writing html out there fail to consider eficiency. They seem to consider blindly only usability. One of the relevant syntax example is the link. Both markdown and creoele (the syntax for wikipedia like wiki), fail to provide the simplest form for link that is [this is a link] or [http://mobiphil.com]. One of the mos frequent syntax elements on html pages are the links itself, so why should we not allocate that syntax element ([this is i link]) for that. Creole wants to force me to use double “[", that is [[this is a link]], markdown even more complicated syntax [name][http://this is a link].
Again I would preffer the creole way, but with one “[”. There were excuses that “[” is used alone. My answer is do it as it is done in computing for ages. Invent an escape character, that can be easily “\” and use “\[” if you want a “[”
I found some complicated implementations for a bbcode, but I needed a special one where I can give a list of addresses and some comments.
Usage:
[map]
Address (mandatory);name (optional); comment (optional); link (optional) |
Address (mandatory);name (optional); comment; (optional); link (optional) |
[/map]
entries are separated by a vertical bar (”|”). The separator has to be at the end of the entry.
Here is the implementation:
1. first you need to include a piece of javascript to your …/forum/styles/XXX/template/overall_header.html
<script type=“text/javascript”>
function showAddress(thediv, addresses) {
var geocodur = null;
if( $(thediv).attr(”id”) != “” )
return;
var thedivid = “d” + Math.floor(Math.random() * 100000000) ;
$(thediv).attr(”id”, thedivid );
var msgid = Math.floor(Math.random() * 100000000) ;
$(thediv).parent().append(”<div id=’” + msgid + “‘></div>”); //used for tracing
if (GBrowserIsCompatible()) {
map = new GMap2(thediv);
map.setCenter(new GLatLng(33.823841, 8.2392), 13);
geocoder = new GClientGeocoder();
}
function createMarker(point, address, name, comment, link)
{
var html = address + “<br/>”;
if(name!=”) {
html = html + name;
}
if(comment !=”) {
html = html + comment + “<br/>” ;
}
if(link!=”)
html = html + “<a href=’” + link + “‘>” + link + “‘</a>’”
var marker = new GMarker(point);
GEvent.addListener(marker, “click”, function() {
map.openInfoWindowHtml(point, html);
});
return marker;
}
var bounds = new GLatLngBounds();
if (geocoder) {
jQuery.each(addresses.split(”|”), function() {
var addresssplit = this.split(”;”);
var address = addresssplit[0];
var name = “”;
if(addresssplit.length > 1)
name = addresssplit[1];
var comment = “”;
if(addresssplit.length > 2)
comment = addresssplit[2];
var link = “”;
if(addresssplit.length > 3)
link = addresssplit[3];
//each address string contains the address followed by ; and optional text
geocoder.getLocations(
address,
function(response) {
var delay = 0;
if(response.Status.code == 620) {
//Too fast try again with a small pause
delay = 500;
}
else {
if( response.Status.code == 200){
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
map.addOverlay(createMarker(point, address, name, comment, link));
bounds.extend(point);
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
}
}
}) ;
});
}
}
</script>
Then your BBCode:
BBCode usage:
[map]{TEXT}[/map]
HTML replacement:
<div style=”border: 2px solid; width: 700px; height: 700px” onclick=”showAddress(this,’{TEXT}’)”><span style=”font-weight: bold; font-size:20pt; margin:5pt;
“> Click inside the box to show the map </span></div>