Yesterday I finally got down to it and made a few additions to the
customFormat formatter, specifically the class ("{{") case.

   - Very often I will want to have a div with a class and an ID, and the
   only way I know to do it by default is to use the HTML tag, which means I
   can't use markup.
   - I changed the lookahead regex in the "{{" select case to recognize
   periods and pound signs as well. Before it only recognized spaces and
   letters.
   - Before (I just now discovered) multiple classes could be included by
   adding spaces. I don't know if that takes away some of the need for this as
   core functionality. This is also retained as default.
   - The default behaviour is retained, and since my code only changes the
   handler, not the match regex, it shouldn't change what markup gets snagged.
   - Currently if periods or pound signs are included the result looks like
   this:  .hi.there{hi too}}} I don't think that is considered correct
   functionality, but rather a syntax error.
   - The one change to the default behaviour is the addition of a null
   (HTML: no '="") id attribute in Chrome. I haven't checked Firefox. I don't
   know if this matters or not.
   - Once I've thought about it some more, I'm not sure if this is even
   needed since you can include more than one class, which as I said I just
   discovered. But, oh well, here it is in case anyone wants it.

So, without further ado, here is the code -- as a plugin.
--Arlen

for (var i = 0; i < config.formatters.length; i++){
if(config.formatters[i].name == "customFormat"){ //look for the
customFormat formatter.
config.formatters[i].handler = function(w)
{
    switch(w.matchText) {
    case "@@":
        var e = createTiddlyElement(w.output,"span");
        var styles = config.formatterHelpers.inlineCssHelper(w);
        if(styles.length == 0)
            e.className = "marked";
        else
            config.formatterHelpers.applyCssHelper(e,styles);
        w.subWikifyTerm(e,/(@@)/mg);
        break;
    case "{{":
        var lookaheadRegExp =
/\{\{[\s]*([#\.\w]+[\s\w\.#]*)[\s]*\{(\n?)/mg; //changed this to
include . and #
        lookaheadRegExp.lastIndex = w.matchStart;
        var lookaheadMatch = lookaheadRegExp.exec(w.source);
        if(lookaheadMatch) {
            w.nextMatch = lookaheadRegExp.lastIndex;
            var lam = String(lookaheadMatch[1]);
            var cl = "";
            var id = "";
            if(lam.indexOf('.') != -1 || lam.indexOf('#') != -1){
                //lam = lam.replace(/ /g, "");
                var i = lam.length;
                var cur = "";
                while (i--) {
                    if (lam[i] == '.' && cur.length > 0) {
                        cl = cl + " " + cur
                        cur = "";
                    } else if (lam[i] == '#' && cur.length > 0) {
                        id = id + " " + cur;
                        cur = "";
                    } else if ((lam[i] == '#' || lam[i] == '.') &&
cur.length == 0) {
                        continue;
                    } else cur = lam[i] +  cur;
                }
                if(id == "" && cl == "") cl = lam; //this shouldn't get hit
            } else cl = lam;
            //the trim removes extra spaces from the beginning and end
            e = createTiddlyElement(w.output,lookaheadMatch[2] == "\n"
? "div" : "span",id.trim(),cl.trim());
            w.subWikifyTerm(e,/(\}\}\})/mg);
        }
        break;
    }
}
}
}

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywikidev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to