OSDN Git Service

wiki table attribute fix.
[hmh/hhml.git] / wiki / wikiattrib.cc
index b6621f4..99fa229 100644 (file)
@@ -19,7 +19,7 @@ bool  WikiAttrib1::readAttrib1 (WikiMotorObjVec* cell, bool& rc) {
        if (paramID (key, vval, ferr)) {
        } else if (paramClass (key, vval, ferr)) {
 #ifdef BOOTSTRAPHACK
-       } else if (paramDataPrefix (key, vval, dataprefix, ferr)) {
+       } else if (paramDataPrefix (key, vval, ferr)) {
 #endif
        } else if (paramOnClickCheck (key)) {
            if (! checkScript (vval, onclick, ferr)) {
@@ -235,13 +235,16 @@ void  WikiAttrib1::output (MotorOutput* out) {
     wiki->outputID (out, id);
     wiki->outputClass (out, classlist);
 #ifdef BOOTSTRAPHACK
-    std::pair<ustring,ustring>::const_iterator  b, e;
+//    std::pair<ustring,ustring>::const_iterator  b, e;
+    std::vector<datapre_t>::const_iterator  b, e;
     b = datapre.begin ();
     e = datapre.end ();
     for (; b < e; b ++) {
-       wiki->outputName (out, b.first, b.second);
+       wiki->outputName (out, (*b).first.c_str (), (*b).first.size (), (*b).second);
     }
 #endif
+    if (start >= 0)
+       wiki->outputNum (out, CharConst ("start"), start);
     wiki->outputSubmitScript (out, CharConst ("onclick"), onclick, scriptcut);
     wiki->outputSubmitScript (out, CharConst ("onfocus"), onfocus, scriptcut);
     wiki->outputSubmitScript (out, CharConst ("onblur"), onblur, scriptcut);
@@ -263,7 +266,7 @@ bool  WikiAttrib1::paramID (const ustring& key, WikiMotorObjVec& vval, bool& fer
 
 void  WikiAttrib1::paramIDValue (const ustring& key, WikiMotorObjVec& vval, ustring& var, bool& ferr) {
     ustring  value (vval.textOut (wiki));
-    if (checkWikiID (value)) {
+    if (matchWikiID (value)) {
        var = value;
        ferr = false;
     } else {
@@ -288,7 +291,9 @@ void  WikiAttrib1::paramClassValue (WikiMotorObjVec& vval, std::vector<ustring>&
     for (int i = 0; i < args.size (); i ++) {
        ustring  value (args[i]->textOut (wiki));
        if (value.length () > 0) {
-           if (checkWikiID (value)) {
+           if ((selector & SEL_DIRECT) && value[0] == '#' && matchWikiID (ustring (value.begin () + 1, value.end ()))) {
+               directlist.push_back (value);           // SEL_DIRECTが指定してある場合のみ有効
+           } else if (matchWikiID (value)) {
                var.push_back (value);
            } else {
                wiki->errorMsg.append (value).append (CharConst (": bad class name\n"));
@@ -318,10 +323,8 @@ bool  WikiAttrib1::paramHeight (const ustring& key, WikiMotorObjVec& vval, ustri
 
 void  WikiAttrib1::paramWidthValue (const ustring& key, WikiMotorObjVec& vval, ustring& var, bool& ferr) {
     ustring  value (vval.textOut (wiki));
-    if (checkWidth (value)) {
+    if (matchWidth (value)) {
        var = value;
-//         if (checkNum (value))
-//             var.append (CharConst ("px"));
        ferr = false;
     } else {
        wiki->errorMsg.append (key).append (uEq).append (value).append (CharConst (": bad value\n"));
@@ -332,7 +335,7 @@ void  WikiAttrib1::paramWidthValue (const ustring& key, WikiMotorObjVec& vval, u
 bool  WikiAttrib1::paramSize (const char* name, size_t namelen, const ustring& key, WikiMotorObjVec& vval, ustring& var, bool& ferr) {
     if (match (key, name, namelen)) {
        ustring  value (vval.textOut (wiki));
-       if (checkNum (value)) {
+       if (matchNum (value)) {
            var = value;
            ferr = false;
        } else {
@@ -344,7 +347,7 @@ bool  WikiAttrib1::paramSize (const char* name, size_t namelen, const ustring& k
 }
 
 void  WikiAttrib1::paramUNum (const ustring& value, int& var, const ustring& name) {
-    if (checkNum (value)) {
+    if (matchNum (value)) {
        var = strtoul (value);
     } else {
        wiki->errorMsg.append (name).append (uEq).append (value).append (uErrorBadValue).append (uLF);
@@ -364,7 +367,7 @@ bool  WikiAttrib1::paramTargetCheck (const ustring& key) {
 }
 
 void  WikiAttrib1::paramTargetBody (const ustring& key, const ustring& value, ustring& var, bool& ferr) {
-    if (value.length () == 0 || checkWikiID (value)) {
+    if (value.length () == 0 || matchWikiID (value)) {
        var = value;
     } else {
        if (key.length () > 0)
@@ -393,10 +396,10 @@ bool  WikiAttrib1::paramOnChangeCheck (const ustring& name) {
 
 #ifdef BOOTSTRAPHACK
 bool  WikiAttrib1::paramDataPrefix (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
-    if (match (CharConst ("data-"), key) && checkWikiID (key)) {
+    if (matchHead (key, CharConst ("data-")) && matchWikiID (key)) {
        ustring  value (vval.textOut (wiki));
-       if (checkWikiID (value)) {
-           datapre.push_back (std::pair (key, value));
+       if (matchWikiID (value)) {
+           datapre.push_back (std::pair<ustring,ustring> (key, value));
            ferr = false;
        } else {
            wiki->errorMsg.append (key).append (uEq).append (value).append (CharConst (": bad value\n"));
@@ -404,7 +407,7 @@ bool  WikiAttrib1::paramDataPrefix (const ustring& key, WikiMotorObjVec& vval, b
        }
        return true;
     } else {
-       return flase;
+       return false;
     }
 }
 #endif
@@ -532,7 +535,7 @@ bool  WikiAttribTable::readAttribMore2 (const ustring& key, WikiMotorObjVec& cel
     return true;
 }
 
-void  WikiAttribTable::outputMore (MotorOutput* out) {
+void  WikiAttribTable::outputMore (MotorOutput* out, bool foutputwidth) {
     switch (halign) {
     case HAlignLeft:
        out->out_raw (CharConst (" align=\"left\""));
@@ -543,8 +546,10 @@ void  WikiAttribTable::outputMore (MotorOutput* out) {
     case HAlignRight:
        out->out_raw (CharConst (" align=\"right\""));
        break;
+    default:;
     }
-    wiki->outputName (out, CharConst ("width"), width);
+    if (foutputwidth)
+       wiki->outputName (out, CharConst ("width"), width);
     wiki->outputName (out, CharConst ("height"), height);
     wiki->outputName (out, CharConst ("bgcolor"), bgcolor);
 
@@ -568,6 +573,7 @@ void  WikiAttribTable::outputMore (MotorOutput* out) {
        case VAlignBottom:
            out->out_raw (CharConst (" valign=\"bottom\""));
            break;
+       default:;
        }
        wiki->outputFlag (out, CharConst ("nowrap"), fnowrap);
        break;
@@ -579,7 +585,11 @@ void  WikiAttribTable::outputMore (MotorOutput* out) {
 /* ============================================================ */
 bool  WikiAttribImg::readAttribMore (const ustring& key, WikiMotorObjVec& vval, bool& ferr) {
     if (paramWidth (key, vval, width, ferr)) {
+       if (matchNum (width))
+           width.append (CharConst ("px"));
     } else if (paramHeight (key, vval, height, ferr)) {
+       if (matchNum (height))
+           height.append (CharConst ("px"));
     } else if (match (key, CharConst ("alt"))) {
        alt = vval.textOut (wiki);
     } else {
@@ -589,8 +599,16 @@ bool  WikiAttribImg::readAttribMore (const ustring& key, WikiMotorObjVec& vval,
 }
 
 void  WikiAttribImg::outputMore (MotorOutput* out) {
-    wiki->outputName (out, CharConst ("width"), width);
-    wiki->outputName (out, CharConst ("height"), height);
+//    wiki->outputName (out, CharConst ("width"), width);
+//    wiki->outputName (out, CharConst ("height"), height);
+    if (width.length () > 0 || height.length () > 0) {
+       out->out_raw (CharConst (" style=\""));
+       if (width.length () > 0)
+           out->out_raw (CharConst ("width:"))->out_toHTML_noCtrl (width)->out_raw (CharConst (";"));
+       if (height.length () > 0)
+           out->out_raw (CharConst ("height:"))->out_toHTML_noCtrl (height)->out_raw (CharConst (";"));
+       out->out_raw (CharConst ("\""));
+    }
     // longdesc
 }
 
@@ -601,7 +619,7 @@ bool  WikiAttribInput::readAttribMore (const ustring& key, WikiMotorObjVec& vval
        ustring  v = vval.textOut (wiki);
        if (match (v, CharConst ("*"))) {
            elsize = 1;
-       } else if (checkNum (v)) {
+       } else if (matchNum (v)) {
            elsize = to_int32 (v);
            if (elsize < 0 || elsize > 999) {
                elsize = 1;
@@ -620,12 +638,27 @@ bool  WikiAttribInput::readAttribMore (const ustring& key, WikiMotorObjVec& vval
            pwrap = W_SOFT;
        } else if (match (value, CharConst ("hard"))) {
            pwrap = W_HARD;
-       } else if (paramWidth (key, vval, pwidth, ferr)) {
        } else {
            wiki->errorMsg.append (key).append (CharConst ("=")).append (vval.dump ()).append (CharConst (": link script error.\n"));
            ferr = true;
            return false;
        }
+    } else if (match (key, CharConst ("accept"))) {
+       ustring  value (vval.textOut (wiki));
+       if (match (value, CharConst ("camera"))) {
+           paccept.assign (CharConst ("image/*;capture=camera"));
+       } else {
+           static  uregex re ("^"
+                              "(" "[a-z_0-9-]+/[a-z_0-9.+*-]+" ")"
+                              "(" "," "(" "[a-z_0-9-]+/[a-z_0-9.+*-]+" ")" ")*"
+                              "(" ";" "[a-z_0-9-]+=[a-zA-Z_0-9.+*-]+" ")*"
+                              "$");
+           if (checkRe (value, re)) {
+               paccept = value;
+           } else {
+               return false;
+           }
+       }
     } else {
        return false;
     }
@@ -637,8 +670,10 @@ bool  WikiAttribInput::readAttribMore2 (const ustring& key, WikiMotorObjVec& cel
        pdefault = true;
     } else if ((selector2 & SEL_CHECK) && match (key, CharConst ("checked"))) {
        pchecked = true;
+#ifdef INSERTTABHACK
     } else if ((selector2 & SEL_TEXTAREA) && match (key, CharConst ("tab"))) {
        ftab = true;
+#endif
     } else {
        return false;
     }
@@ -649,7 +684,7 @@ void  WikiAttribInput::outputMore (MotorOutput* out) {
     wiki->outputName (out, CharConst ("size"), psize);
     wiki->outputName (out, CharConst ("size"), elsize);
     if (pwidth.size () > 0) {
-       if (checkNum (pwidth)) {
+       if (matchNum (pwidth)) {
            out->out_raw (CharConst (" style=\"width:"))->out_toHTML_noCtrl (pwidth)->out_raw (CharConst ("px;\""));
        } else {
            out->out_raw (CharConst (" style=\"width:"))->out_toHTML_noCtrl (pwidth)->out_raw (CharConst (";\""));
@@ -674,6 +709,7 @@ void  WikiAttribInput::outputMore (MotorOutput* out) {
            //  out->out_raw (CharConst (" wrap=\"physical\""));
            break;
        }
+#ifdef INSERTTABHACK
        if (ftab) {
            out->out_raw (uSPC)
                ->out_raw (CharConst ("onkeypress"))
@@ -684,13 +720,19 @@ void  WikiAttribInput::outputMore (MotorOutput* out) {
                ->out_raw (CharConst ("onkeydown"))
                ->out_raw (CharConst ("=\""))
                ->out_toHTML (ustring (CharConst ("return insertTab(event,this);")))
-               ->out_raw ("\"");
+               ->out_raw (uQ2);
            out->out_raw (uSPC)
                ->out_raw (CharConst ("onkeyup"))
                ->out_raw (CharConst ("=\""))
                ->out_toHTML (ustring (CharConst ("return insertTab(event,this);")))
-               ->out_raw ("\"");
+               ->out_raw (uQ2);
        }
+#endif
+    }
+    if (paccept.length () > 0) {
+       out->out_raw (CharConst (" accept=\""))
+           ->out_toHTML (paccept)
+           ->out_raw (uQ2);
     }
 }
 
@@ -728,6 +770,8 @@ bool  WikiAttribItem::readAttribMore (const ustring& key, WikiMotorObjVec& vval,
        if (owner && owner->parent && owner->parent->attrib.id.size () == 0) {
            paramIDValue (key, vval, owner->parent->attrib.id, ferr);
        }
+    } else if (owner && owner->parent && (owner->parent->attrib.selector & SEL_START) && match (key, CharConst ("start"))) {
+       paramUNum (vval.textOut (wiki), owner->parent->attrib.start, key);
     } else {
        return false;
     }