[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-kdoc
Subject:    [Patch] Markup for HTML
From:       Wolfgang Bangerth <Wolfgang.Bangerth () IWR ! Uni-Heidelberg ! De>
Date:       2000-03-17 13:23:31
[Download RAW message or body]


OK, in a spare minute, I have hacked something for mark-up in HTML. It
presently supports @p, @em, @ref, and @sect[1-4]. Other tags
are simple to add. All tags accept the next word (up to the next space) as
argument, or what is given in braces directly after the tag's name.
Could anyone review it and tell me whether that's ok, and I can copy
this over to DocBook as well?

Two final notes:
1/ The true patch is at the very end. I added some \n's to make the HTML
   output more readable.
2/ Taj, you talked briefly about that @sect should behave like @param. I
   don't recall what @param should do, and I couldn't find @param by a
   quick glance. Did you mean that @sect should be right to the 
   next line end? I have objections to this, but would be willing to
   discuss them if I knew what was the intention.

Regards
  Wolfgang

-------------------------------------------------------------------------
Wolfgang Bangerth          email: wolfgang.bangerth@iwr.uni-heidelberg.de
                             www: http://gaia.iwr.uni-heidelberg.de/~wolf

--- kdocHTMLutil.pm.1	Tue Mar 14 17:33:34 2000
+++ kdocHTMLutil.pm	Fri Mar 17 14:15:18 2000
@@ -393,15 +393,15 @@
 				if !defined $type;
 
 			if( $lasttype eq "ListItem" && $type ne $lasttype ) {
-				print CLASS "</ul><p>\n";
+				print CLASS "</ul>\n\n<p>\n";
 			}
 
                         if( $type eq "DocText" ) {
                                 print CLASS "", deref( $name, $rootnode );
                         }
                         elsif ( $type eq "Pre" ) {
-                                print CLASS "</p><pre>\n",
-					esc( $name ), "\n</pre><p>";
+                                print CLASS "</p>\n\n<pre>\n",
+					esc( $name ), "\n</pre>\n\n<p>\n";
                         }
 			elsif( $type eq "Ref" ) {
 				my $ref = $node->{Ref};
@@ -414,19 +414,19 @@
 				}
 			}
 			elsif ( $type eq "DocSection" ) {
-				print CLASS "</p><H3>",
-					deref( $name, $rootnode),"</H3><p>";
+				print CLASS "</p>\n\n<H3>",
+					deref( $name, $rootnode),"</H3>\n<p>\n";
 			}
 			elsif ( $type eq "Image" ) {
-				print CLASS "</p><img url=\"",
-					$node->{Path}, "\"><p>";		
+				print CLASS "</p>\n<img url=\"",
+					$node->{Path}, "\">\n<p>\n";
 			}
                         elsif ( $type eq "ParaBreak" ) {
-                                print CLASS "</p><p>";
+                                print CLASS "</p>\n\n<p>";
                         }
 			elsif ( $type eq "ListItem" ) {
 				if ( $lasttype ne "ListItem" ) {
-					print CLASS "</p><ul>\n";
+					print CLASS "</p>\n\n<ul>\n";
 				}
 				print CLASS "<li>", 
 					deref( $name, $rootnode ), "</li>\n";
@@ -436,10 +436,10 @@
                 }
 
 		if( $type eq "ListItem" ) {
-			print CLASS "</ul><p>\n";
+			print CLASS "</ul>\n\n<p>\n";
 		}
 
-                print CLASS "</p>";
+                print CLASS "</p>\n";
 
         }
 
@@ -602,18 +602,43 @@
 	my $out = "";
 	my $text;
 
-	foreach $text ( split (/(\@\w+\s+[\w:#]+)/, $str ) ) {
-		if ( $text =~ /\@ref\s+([\w:#]+)/ ) {
-			my $name = $1;
-			$name =~ s/^\s*#//g;
-			$out .= wordRef( $name, $rootnode );
-		}
-		elsif ( $text =~ /\@p\s+([\w:#]+)/ ) {
-			$out .= "<code>".esc($1)."</code>";
-		}
-		elsif ( $text =~/\@em\s+(\w+)/ ) {       # emphasized
-			$out .= "<em>".esc($1)."</em>";
+	# escape @x commands
+	foreach $text ( split (/(\@\w+(?:\s+.+?(?=\s)|\{.*?\}))/, $str ) ) {
+
+	        # check whether $text is an @command or the text between
+	        # @commands
+		if (  $text =~ /\@(\w+)(?:\s+(.+?)(?:\s|$)|\{(.*?)\})/ )   {
+                        my $command = $1;
+			my $content = $2 . $3;
+
+			# @ref -- cross reference
+			if ( $command eq "ref" ) {
+			    $content =~ s/^\s*#//g;
+			    $out .= wordRef( $content, $rootnode );
+			}
+
+			# @p  -- typewriter
+			elsif ( $command eq "p" ) {
+			    $out .= "<code>".esc($content)."</code>";
+			}
+
+			# @em -- emphasized
+			elsif ( $command eq "em" ) {
+			    $out .= "<em>".esc($content)."</em>";
+			}
+
+			# @sect1-4 -- section header
+			elsif ( $command =~ /^sect([1-4])$/ ) {
+			    $out .= "<h$1>".esc($content)."</h$1>";
+			}
+
+			# unknown command. warn and copy command
+			else {
+			    print "Unknown command @", $command, "\n";
+			    $out .= esc($text);
+			}
 		}
+		# no @x command, thus regular text
 		else {
 			$out .= esc($text);
 		}

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic