xml.awkView |
---|
| 1 … | +function escape_html(text) { |
| 2 … | + gsub(/&/, "\\&", text) |
| 3 … | + gsub(/</, "\\<", text) |
| 4 … | + gsub(/>/, "\\>", text) |
| 5 … | + gsub(/"/, "\\"", text) |
| 6 … | + return text |
| 7 … | +} |
| 8 … | + |
| 9 … | +function get_value() { |
| 10 … | + sub(/^[^ ]* */, "") |
| 11 … | + return $0 |
| 12 … | +} |
| 13 … | + |
| 14 … | +function end() { |
| 15 … | + print "</pre></content>" |
| 16 … | + print "</entry>" |
| 17 … | +} |
| 18 … | + |
| 19 … | +$1 == "entry" { |
| 20 … | + if (in_content && $2 == end_of_content) { |
| 21 … | + in_content = 0 |
| 22 … | + in_stat = 0 |
| 23 … | + end() |
| 24 … | + } |
| 25 … | + |
| 26 … | + title = "" |
| 27 … | + id = "" |
| 28 … | + name = "" |
| 29 … | + email = "" |
| 30 … | + updated = "" |
| 31 … | + |
| 32 … | + next |
| 33 … | +} |
| 34 … | + |
| 35 … | +$1 == "stat" && $2 == end_of_content { |
| 36 … | + in_stat = 1 |
| 37 … | + next |
| 38 … | +} |
| 39 … | + |
| 40 … | +$1 == "content" { |
| 41 … | + end_of_content = $2 |
| 42 … | + print "<entry>" |
| 43 … | + print " <title>" escape_html(title) "</title>" |
| 44 … | + print " <id>" id "</id>" |
| 45 … | + print " <author>" |
| 46 … | + print " <name>" escape_html(name) "</name>" |
| 47 … | + print " <email>" escape_html(email) "</email>" |
| 48 … | + print " </author>" |
| 49 … | + print " <updated>" escape_html(updated) "</updated>" |
| 50 … | + printf " <content type=\"html\"><pre>" |
| 51 … | + in_content = 1 |
| 52 … | + next |
| 53 … | +} |
| 54 … | + |
| 55 … | +in_stat && /^ [^ ]* *\|/ { |
| 56 … | + sub(/[^ ][^ ]*/, "<a href=\"" site "&\">&</a>") |
| 57 … | +} |
| 58 … | + |
| 59 … | +in_stat && / \+*-*$/ { |
| 60 … | + sub(/ \++/, "<span style=\"color:green\">&</span>") |
| 61 … | + sub(/-+$/, "<span style=\"color:red\">&</span>") |
| 62 … | +} |
| 63 … | + |
| 64 … | +in_content { |
| 65 … | + print escape_html($0) |
| 66 … | + next |
| 67 … | +} |
| 68 … | + |
| 69 … | +$1 == "title" { title = get_value() } |
| 70 … | +$1 == "name" { name = get_value() } |
| 71 … | +$1 == "email" { email = get_value() } |
| 72 … | +$1 == "id" { |
| 73 … | + id = get_value() |
| 74 … | + id = site ".git/objects/" substr(id, 1, 2) "/" substr(id, 3) |
| 75 … | +} |
| 76 … | +$1 == "updated" { |
| 77 … | + updated = $2 "T" $3 substr($4, 1, 3) ":" substr($4, 3, 2) |
| 78 … | +} |
| 79 … | + |
| 80 … | +END { |
| 81 … | + if (in_content) |
| 82 … | + end() |
| 83 … | +} |