|
Last change
on this file since 3 was
2,
checked in by peter, 14 years ago
|
|
Added initial recipecard scripts and configuration files
|
-
Property svn:executable set to
*
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | #!/usr/bin/perl -w |
|---|
| 2 | use strict; |
|---|
| 3 | |
|---|
| 4 | $/ = ''; |
|---|
| 5 | |
|---|
| 6 | print "<recipe>\n"; |
|---|
| 7 | while (<>) { |
|---|
| 8 | chomp; |
|---|
| 9 | s/^\s+//g; |
|---|
| 10 | s/\s+$//g; |
|---|
| 11 | if (/^##\s+(.*)/) { |
|---|
| 12 | # title |
|---|
| 13 | print "<title>$1</title>"; |
|---|
| 14 | } elsif (/^\d/) { |
|---|
| 15 | # ingredient list |
|---|
| 16 | print '<ingredients>'; |
|---|
| 17 | foreach (split /\n/, $_) { |
|---|
| 18 | /^\s+/ ? print '<note>' . apply_symbols($_) . '</note>' |
|---|
| 19 | : print '<ingredient>' . apply_symbols($_) . '</ingredient>'; |
|---|
| 20 | } |
|---|
| 21 | print '</ingredients>'; |
|---|
| 22 | } else { |
|---|
| 23 | # TODO: catch special body paragraphs, like "Note:", "Serves", "Yields", etc. |
|---|
| 24 | # body |
|---|
| 25 | # fold the lines together |
|---|
| 26 | s/\n/ /; |
|---|
| 27 | print '<para>' . apply_symbols($_) . '</para>'; |
|---|
| 28 | } |
|---|
| 29 | } |
|---|
| 30 | print '</recipe>'; |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | sub apply_symbols { |
|---|
| 34 | my $string = shift; |
|---|
| 35 | for ($string) { |
|---|
| 36 | # numeric dimensions |
|---|
| 37 | s/(\d)x/$1⨯/g; |
|---|
| 38 | # temperature |
|---|
| 39 | s/(\d)\s*deg.(\s*F)?/$1℉/g; |
|---|
| 40 | # fractions |
|---|
| 41 | s{1/3}{⅓}g; |
|---|
| 42 | s{2/3}{⅔}g; |
|---|
| 43 | s{1/4}{¼}g; |
|---|
| 44 | s{1/2}{½}g; |
|---|
| 45 | s{3/4}{¾}g; |
|---|
| 46 | s{1/8}{⅛}g; |
|---|
| 47 | # inches |
|---|
| 48 | s/(\d)[ -]?(in\.|in\b|inch)/$1″/g; |
|---|
| 49 | # numeric range en dashes |
|---|
| 50 | s/(\d)-(\d)/$1–$2/g; |
|---|
| 51 | # remove dash before vulgar fractions |
|---|
| 52 | s/(\d)-([¼½¾⅓⅔])/$1$2/g; |
|---|
| 53 | } |
|---|
| 54 | return $string; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.