]> git.lizzy.rs Git - plan9front.git/commitdiff
html2ms: handle subscripts and superscripts
authorcinap_lenrek <cinap_lenrek@felloff.net>
Thu, 3 Sep 2015 19:24:00 +0000 (21:24 +0200)
committercinap_lenrek <cinap_lenrek@felloff.net>
Thu, 3 Sep 2015 19:24:00 +0000 (21:24 +0200)
sys/src/cmd/html2ms.c

index 6ecbeef372f681d82f9556a713b168423acc9244..751a46d013d927e7302af649abad1914045d2199 100644 (file)
@@ -217,6 +217,71 @@ onb(Text *text, Tag *tag)
        fontstyle(text, "B");
 }
 
+void onsmall(Text *text, Tag *tag);
+void onsup(Text *text, Tag *tag);
+
+void
+onsub(Text *text, Tag *tag)
+{
+       emit(text, "\\v\'0.5\'");
+       if(cistrcmp(tag->tag, "sub") == 0){
+               emit(text, "\\x\'0.5\'");
+               onsmall(text, tag);
+       } else
+               restorefontsize(text, tag);
+       tag->close = onsup;
+}
+
+void
+onsup(Text *text, Tag *tag)
+{
+       emit(text, "\\v\'-0.5\'");
+       if(cistrcmp(tag->tag, "sup") == 0){
+               emit(text, "\\x\'-0.5\'");
+               onsmall(text, tag);
+       }else
+               restorefontsize(text, tag);
+       tag->close = onsub;
+}
+
+/*
+ * this is poor mans CSS handler.
+ */
+void
+onspan(Text *text, Tag *tag)
+{
+       Attr *a;
+
+       if(!tag->opening)
+               return;
+
+       for(a=tag->attr; a < tag->attr+tag->nattr; a++){
+               if(cistrcmp(a->attr, "class") != 0)
+                       continue;
+
+               if(cistrcmp(a->val, "bold") == 0){
+                       onb(text, tag);
+                       return;
+               }
+               if(cistrcmp(a->val, "italic") == 0){
+                       oni(text, tag);
+                       return;
+               }
+               if(cistrcmp(a->val, "subscript") == 0){
+                       strcpy(tag->tag, "sub");
+                       onsub(text, tag);
+                       strcpy(tag->tag, "span");
+                       return;
+               }
+               if(cistrcmp(a->val, "superscript") == 0){
+                       strcpy(tag->tag, "sup");
+                       onsup(text, tag);
+                       strcpy(tag->tag, "span");
+                       return;
+               }
+       }
+}
+
 void
 ontt(Text *text, Tag *tag)
 {
@@ -510,6 +575,9 @@ struct {
        "td",           oncell,
        "th",           oncell,
        "tr",           oncell,
+       "sub",          onsub,
+       "sup",          onsup,
+       "span",         onspan,
        "tt",           ontt,
        "var",          oni,
 };