git: 9front

Download patch

ref: 71e906d032b5d0fa35577d8b3add539b22b8226f
parent: dcc64deff7391453e02551f673e8e82580b22e96
author: stanley lieber <stanley.lieber@gmail.com>
date: Mon Sep 19 15:21:54 EDT 2011

html2ms: underline links

--- a/sys/src/cmd/html2ms.c
+++ b/sys/src/cmd/html2ms.c
@@ -28,11 +28,12 @@
 };
 
 struct Text {
-	char	font;
+	char*	font;
 	int	pre;
 	int	pos;
 	int	space;
 	int	output;
+	int	underline;
 };
 
 void eatwhite(void);
@@ -122,8 +123,8 @@
 void
 restorefont(Text *text, Tag *tag)
 {
-	text->font = tag->restore;
-	text->pos += Bprint(&out, "\\f%c", text->font);
+	text->font = tag->aux;
+	text->pos += Bprint(&out, "\\f%s", text->font);
 }
 
 void
@@ -130,20 +131,27 @@
 onfont(Text *text, Tag *tag)
 {
 	if(text->font == 0)
-		text->font = 'R';
-	tag->restore = text->font;
+		text->font = "R";
+	tag->aux = text->font;
 	tag->close = restorefont;
 	if(cistrcmp(tag->tag, "i") == 0)
-		text->font = 'I';
+		text->font = "I";
 	else if(cistrcmp(tag->tag, "b") == 0)
-		text->font = 'B';
-	text->pos += Bprint(&out, "\\f%c", text->font);
+		text->font = "B";
+	text->pos += Bprint(&out, "\\f%s", text->font);
 }
 
+void
+ona(Text *text, Tag *)
+{
+	text->underline = 1;
+}
+
 struct {
 	char	*tag;
 	void	(*open)(Text *, Tag *);
 } ontag[] = {
+	"a",		ona,
 	"br",		onbr,
 	"hr",		onbr,
 	"b",		onfont,
@@ -154,6 +162,7 @@
 	"h3",		onh,
 	"h4",		onh,
 	"h5",		onh,
+	"h6",		onh,
 	"li",		onli,
 	"pre",		onpre,
 	"head",		ongarbage,
@@ -300,7 +309,7 @@
 parserune(int c)
 {
 	char buf[10];
-	int i, n;
+	int n;
 	Rune r;
 
 	n = 0;
@@ -425,7 +434,10 @@
 					text->pos = 0;
 				if(text->space){
 					text->space = 0;
-					if(text->pos >= 70){
+					if(text->underline){
+						emit(text, "");
+						text->pos = Bprint(&out, ".UL ");
+					} else if(text->pos >= 70){
 						text->pos = 0;
 						Bputc(&out, '\n');
 					} else if(text->pos > 0){
--