#!/usr/bin/awk -f # # Take the blog-avatars collection page. # Pass anchor tags through. # Turn images into images and HTML to include the images # into blog entries. # # Image SRC/ALT/HREF must all be on one line in the input file. # # This does only the middle of the resultant new web page. # The head and tail are handled by another script. # Input lines that are not anchors or images have been filtered out. # # Brent Chivers 2005 July 8 # # For the images that need to be tables with artists' BDC 2005/07/11 # names, put the HTML in the 2nd column of a table. # (Trying to make it easier to highlight/copy the HTML. It worked.) # # Put them ALL in 2-column tables -- they format better for grabbing. # # Add support for tags. BDC 2005/11/12 # If there was no <ALT> attribute in the source, make an empty one. # # <ALT> and <TITLE> strings can be delimited by `` BDC 2005/11/13 # (backticks) as well as "" or '' -- adding support for this. # # Was creating output file with "" as the string delimiter always. # Note and preserve the original delimiter characters -- there may # have been a reason for using something other than "". # (That got ugly fast.) # # Look for (by) strings if there is ALT or TITLE (not just ALT). # # Stop generating output after reading "</HTML>". BDC 2005/11/24 # (Doesn't work, but stopping at '<A NAME="bottom">' does work.) # # Add BORDER="0" to copy/paste output. BDC 2006/12/16 # # Didn't handle nested (by) strings with nested parens BDC 2009/04/30 # properly. So far, all end with "))", so look for those. # # Creating the pasteable links, ALIGN=RIGHT instead of BDC 2018/Mar/17 # LEFT. (I put more icons on the right in my journal entries. # I sHould have changed this LONG ago.) /<\/[Hh][Tt][Mm][Ll]>/ {exit} /<[Aa] [Nn][Aa][Mm][Ee]="bottom">/ {print ; exit} /<[Aa] [Nn][Aa][Mm][Ee]="+.*"+>/ {print ; next} # All else are images { # Look for IMG SRC tags.... src1 = index ( $0, "<IMG SRC=\"" ) if (src1) { src1 += 10 src2 = index ( substr ($0, src1), "\"" ) src2 -= 1 src = substr ($0, src1, src2) src_delim = "\"" } if (src1 == 0) { src1 = index ( $0, "<img src=\"" ) if (src1) { src1 += 10 src2 = index ( substr ($0, src1), "\"" ) src2 -= 1 src = substr ($0, src1, src2) src_delim = "\"" } } if (src1 == 0) { src1 = index ( $0, "<IMG SRC='" ) if (src1) { src1 += 10 src2 = index ( substr ($0, src1), "'" ) src2 -= 1 src = substr ($0, src1, src2) src_delim = "'" } } if (src1 == 0) { src1 = index ( $0, "<img src='" ) if (src1) { src1 += 10 src2 = index ( substr ($0, src1), "'" ) src2 -= 1 src = substr ($0, src1, src2) src_delim = "'" } } if (src1 == 0) { src1 = index ( $0, "<IMG SRC=`" ) if (src1) { src1 += 10 src2 = index ( substr ($0, src1), "`" ) src2 -= 1 src = substr ($0, src1, src2) src_delim = "`" } } if (src1 == 0) { src1 = index ( $0, "<img src=`" ) if (src1) { src1 += 10 src2 = index ( substr ($0, src1), "`" ) src2 -= 1 src = substr ($0, src1, src2) src_delim = "`" } } # Look for ALT tags.... alt1 = index ( $0, "ALT=\"" ) if (alt1) { alt1 += 5 alt2 = index ( substr ($0, alt1), "\"" ) alt2 -= 1 alt = substr ($0, alt1, alt2) alt_delim = "\"" } if (alt1 == 0) { alt1 = index ( $0, "alt=\"" ) if (alt1) { alt1 += 5 alt2 = index ( substr ($0, alt1), "\"" ) alt2 -= 1 alt = substr ($0, alt1, alt2) alt_delim = "\"" } } if (alt1 == 0) { alt1 = index ( $0, "ALT='" ) if (alt1) { alt1 += 5 alt2 = index ( substr ($0, alt1), "'" ) alt2 -= 1 alt = substr ($0, alt1, alt2) alt_delim = "'" } } if (alt1 == 0) { alt1 = index ( $0, "alt='" ) if (alt1) { alt1 += 5 alt2 = index ( substr ($0, alt1), "'" ) alt2 -= 1 alt = substr ($0, alt1, alt2) alt_delim = "'" } } if (alt1 == 0) { alt1 = index ( $0, "ALT=`" ) if (alt1) { alt1 += 5 alt2 = index ( substr ($0, alt1), "`" ) alt2 -= 1 alt = substr ($0, alt1, alt2) alt_delim = "`" } } if (alt1 == 0) { alt1 = index ( $0, "alt=`" ) if (alt1) { alt1 += 5 alt2 = index ( substr ($0, alt1), "`" ) alt2 -= 1 alt = substr ($0, alt1, alt2) alt_delim = "`" } } # Look for TITLE tags.... title1 = index ( $0, "TITLE=\"" ) if (title1) { title1 += 7 title2 = index ( substr ($0, title1), "\"" ) title2 -= 1 title = substr ($0, title1, title2) title_delim = "\"" } if (title1 == 0) { title1 = index ( $0, "title=\"" ) if (title1) { title1 += 7 title2 = index ( substr ($0, title1), "\"" ) title2 -= 1 title = substr ($0, title1, title2) title_delim = "\"" } } if (title1 == 0) { title1 = index ( $0, "TITLE='" ) if (title1) { title1 += 7 title2 = index ( substr ($0, title1), "'" ) title2 -= 1 title = substr ($0, title1, title2) title_delim = "'" } } if (title1 == 0) { title1 = index ( $0, "title='" ) if (title1) { title1 += 7 title2 = index ( substr ($0, title1), "'" ) title2 -= 1 title = substr ($0, title1, title2) title_delim = "'" } } if (title1 == 0) { title1 = index ( $0, "TITLE=`" ) if (title1) { title1 += 7 title2 = index ( substr ($0, title1), "`" ) title2 -= 1 title = substr ($0, title1, title2) title_delim = "`" } } if (title1 == 0) { title1 = index ( $0, "title=`" ) if (title1) { title1 += 7 title2 = index ( substr ($0, title1), "`" ) title2 -= 1 title = substr ($0, title1, title2) title_delim = "`" } } # Look for (by artist content) if ((alt1) || (title1)) { by1 = index ( $0, " (by " ) if (by1) { by1 += 5 by2 = index ( substr ($0, by1), "))" ) if (by2 == 0) { by2 = index ( substr ($0, by1), ")" ) by2 -= 1 } by = substr ($0, by1, by2) } } else { by1 = 0 } # Look for Anchor Link tags.... href1 = index ( $0, "<A HREF=\"" ) if (href1) { href1 += 9 href2 = index ( substr ($0, href1), "\"" ) href2 -= 1 href = substr ($0, href1, href2) href_delim = "\"" } if (href1 == 0) { href1 = index ( $0, "<a href=\"" ) if (href1) { href1 += 9 href2 = index ( substr ($0, href1), "\"" ) href2 -= 1 href = substr ($0, href1, href2) href_delim = "\"" } } if (href1 == 0) { href1 = index ( $0, "<A HREF='" ) if (href1) { href1 += 9 href2 = index ( substr ($0, href1), "'" ) href2 -= 1 href = substr ($0, href1, href2) href_delim = "'" } } if (href1 == 0) { href1 = index ( $0, "<a href='" ) if (href1) { href1 += 9 href2 = index ( substr ($0, href1), "'" ) href2 -= 1 href = substr ($0, href1, href2) href_delim = "'" } } if (href1 == 0) { href1 = index ( $0, "<A HREF=`" ) if (href1) { href1 += 9 href2 = index ( substr ($0, href1), "`" ) href2 -= 1 href = substr ($0, href1, href2) href_delim = "`" } } if (href1 == 0) { href1 = index ( $0, "<a href=`" ) if (href1) { href1 += 9 href2 = index ( substr ($0, href1), "`" ) href2 -= 1 href = substr ($0, href1, href2) href_delim = "`" } } if (src1) { if (by1) { printf ("<table align=left><tr><td>") if (href1) { printf ("<a href=%s%s%s>", href_delim, href, href_delim) } printf ("<img src=%s%s%s alt=%s%s%s", src_delim, src, src_delim, alt_delim, alt, alt_delim) if (title1) { printf (" title=%s%s%s", title_delim, title, title_delim) } printf (">") if (href1) { printf ("</a>") } printf ("</td><td rowspan=2>") if (href1) { printf ("<A HREF=%s%s%s>", href_delim, href, href_delim) } printf ("<TABLE ALIGN=RIGHT>") printf ("<TR><TD><IMG SRC=%s%s%s BORDER=\"0\"", src_delim, src, src_delim) if (alt1) { printf (" ALT=%s%s%s", alt_delim, alt, alt_delim) } else { printf (" ALT=\"\"") } if (title1) { printf (" TITLE=%s%s%s", title_delim, title, title_delim) } printf ("></TD></TR>") printf ("<TR><TD><SMALL><SMALL><SMALL>%s</SMALL></SMALL></SMALL>", by) printf ("</TD></TR></TABLE>") if (href1) { printf ("</A>") } printf ("</td></tr><tr><td>") if (href1) { printf ("<a href=%s%s%s>", href_delim, href, href_delim) } printf ("<small><small><small>%s</small></small></small>", by) if (href1) { printf ("</a>") } printf ("</td></tr></table><br clear=all>\n") } else { printf ("<table align=left><tr><td>") if (href1) { printf ("<a href=%s%s%s>", href_delim, href, href_delim) } printf ("<img src=%s%s%s", src_delim, src, src_delim) if (alt1) { printf (" alt=%s%s%s", alt_delim, alt, alt_delim) } if (title1) { printf (" title=%s%s%s", title_delim, title, title_delim) } printf (" align=left>") if (href1) { printf ("</a>") } printf ("</td>\n<td>") if (href1) { printf ("<A HREF=%s%s%s>", href_delim, href, href_delim) } printf ("<IMG SRC=%s%s%s BORDER=\"0\"", src_delim, src, src_delim) if (alt1) { printf (" ALT=%s%s%s", alt_delim, alt, alt_delim) } else { printf (" ALT=\"\"") } if (title1) { printf (" TITLE=%s%s%s", title_delim, title, title_delim) } printf (" ALIGN=RIGHT>") if (href1) { printf ("</A>") } printf ("</td></tr></table><br clear=all>\n") } } # else { printf ("SKIPPING: %s\n", $0) } # print # printf ("%d %d %s\n", src1, src2, src) # printf ("%d %d %s\n", alt1, alt2, alt) # printf ("%d %d %s\n", title1, title2, title) # printf ("%d %d %s\n", href1, href2, href) }