|
| 1 | +#encoding: utf-8 |
1 | 2 | # This script automatically converts the HTML pages |
2 | 3 | # of the Ruby Hacking Guide to the textile-based text |
3 | 4 | # format used for the translation. |
|
31 | 32 | end |
32 | 33 | end |
33 | 34 | end |
34 | | - |
| 35 | + |
35 | 36 | # different types of list |
36 | 37 | list_type = nil |
37 | 38 | data.gsub!(/<(ul|ol|li)>/) do |m| |
|
44 | 45 | end |
45 | 46 |
|
46 | 47 | [ |
47 | | - [ /.*?<body>(.*?)<\/body>.*/m, '\1' ], # we only want the body |
48 | | - [ /<\/?(table|p( class=".+?")?)>|<\/(li|h\d|ol|ul)>/, '' ], # remove useless tags |
49 | | - [ /▼/, '▼ ' ], # just add a space after the arrow |
50 | | - [ /<h(\d)>/, 'h\1. ' ], # headers |
51 | | - [ /<a href="(.+?)">(.+?)<\/a>/m, '"\2":\1' ], # images |
52 | | - [ /<tr><td>|<td><td>|<td><\/tr>/, '|' ], # tables |
53 | | - [ /<img src="(.+?)" alt=".+?"><br>\n図\d+: (.*)/, '!\1(\2)!' ], # images and captions |
54 | | - [ /[ \t]+$/, '' ], # trims line ends |
55 | | - [ /\A\n+|\n+\Z/, '' ], # remove beginning and ending empty lines |
56 | | - [ /\n\n+/, "\n\n" ], # succession of empty lines |
57 | | - ].each { |re, str| data.gsub!(re, str) } |
58 | | - |
| 48 | + [ /.*?<body>(.*?)<\/body>.*/m , '\1' ] , # we only want the body |
| 49 | + [ /<\/?(table|p( class=".+?")?)>|<\/(li|h\d|ol|ul)>/ , '' ] , # remove useless tags |
| 50 | + [ /▼/ , '▼ ' ] , # just add a space after the arrow |
| 51 | + [ /<h(\d)>/ , 'h\1. ' ] , # headers |
| 52 | + [ /<a href="(.+?)">(.+?)<\/a>/m , '"\2":\1' ] , # images |
| 53 | + [ /<tr><td>|<td><td>|<td><\/tr>/ , '|' ] , # tables |
| 54 | + [ /<img src="(.+?)" alt=".+?"><br>\n図\d+: (.*)/ , '!\1(\2)!' ] , # images and captions |
| 55 | + [ /[ \t]+$/ , '' ] , # trims line ends |
| 56 | + [ /\A\n+|\n+\Z/ , '' ] , # remove beginning and ending empty lines |
| 57 | + [ /\n\n+/ , "\n\n" ] , # succession of empty lines |
| 58 | + ].each { |re, str| data.gsub!(re , str) } |
| 59 | + |
59 | 60 | output.puts(data) |
60 | 61 | end |
0 commit comments