Last change
on this file since 4 was
4,
checked in by peter, 11 years ago
|
- put the recipe XML into a namespace (http://xmlns.grim.ath.cx/recipe)
- match "degrees" and turn it into a degree symbol
- added a recipe.html.xsl stylesheet that transforms recipe XML into HTML marked up with the hRecipe microformat
|
-
Property svn:executable set to
*
|
File size:
1.3 KB
|
Rev | Line | |
---|
[2] | 1 | #!/usr/bin/perl -w |
---|
| 2 | use strict; |
---|
| 3 | |
---|
[4] | 4 | #TODO: look at this existing XML format: http://www.happy-monkey.net/recipebook/doc/author-tutorial.html |
---|
| 5 | |
---|
[2] | 6 | $/ = ''; |
---|
| 7 | |
---|
[4] | 8 | print qq{<recipe xmlns="http://xmlns.grim.ath.cx/recipe">\n}; |
---|
[2] | 9 | while (<>) { |
---|
| 10 | chomp; |
---|
| 11 | s/^\s+//g; |
---|
| 12 | s/\s+$//g; |
---|
| 13 | if (/^##\s+(.*)/) { |
---|
| 14 | # title |
---|
| 15 | print "<title>$1</title>"; |
---|
| 16 | } elsif (/^\d/) { |
---|
| 17 | # ingredient list |
---|
| 18 | print '<ingredients>'; |
---|
| 19 | foreach (split /\n/, $_) { |
---|
| 20 | /^\s+/ ? print '<note>' . apply_symbols($_) . '</note>' |
---|
| 21 | : print '<ingredient>' . apply_symbols($_) . '</ingredient>'; |
---|
| 22 | } |
---|
| 23 | print '</ingredients>'; |
---|
| 24 | } else { |
---|
| 25 | # TODO: catch special body paragraphs, like "Note:", "Serves", "Yields", etc. |
---|
| 26 | # body |
---|
| 27 | # fold the lines together |
---|
| 28 | s/\n/ /; |
---|
| 29 | print '<para>' . apply_symbols($_) . '</para>'; |
---|
| 30 | } |
---|
| 31 | } |
---|
| 32 | print '</recipe>'; |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | sub apply_symbols { |
---|
| 36 | my $string = shift; |
---|
| 37 | for ($string) { |
---|
| 38 | # numeric dimensions |
---|
| 39 | s/(\d)x/$1⨯/g; |
---|
| 40 | # temperature |
---|
[4] | 41 | s/(\d)\s*deg(\.|rees)(\s*F)?/$1℉/g; |
---|
[2] | 42 | # fractions |
---|
| 43 | s{1/3}{⅓}g; |
---|
| 44 | s{2/3}{⅔}g; |
---|
| 45 | s{1/4}{¼}g; |
---|
| 46 | s{1/2}{½}g; |
---|
| 47 | s{3/4}{¾}g; |
---|
| 48 | s{1/8}{⅛}g; |
---|
| 49 | # inches |
---|
| 50 | s/(\d)[ -]?(in\.|in\b|inch)/$1″/g; |
---|
| 51 | # numeric range en dashes |
---|
| 52 | s/(\d)-(\d)/$1–$2/g; |
---|
| 53 | # remove dash before vulgar fractions |
---|
| 54 | s/(\d)-([¼½¾⅓⅔])/$1$2/g; |
---|
| 55 | } |
---|
| 56 | return $string; |
---|
| 57 | } |
---|
| 58 | |
---|
Note: See
TracBrowser
for help on using the repository browser.