]>
pere.pagekite.me Git - text-madewithcc.git/blob - fixup.rb
211bd26b558e89a4084b99251ee44b947aee933c
4 raise ArgumentError
, 'Source/destination files not specified' if ARGV.size !
= 2
8 data=File
.open(srcfile
).readlines
.map
{|l
| l
.chomp!
}
10 data.map
{|lin
| lin
.gsub!
(/\[\]{#anchor-?\d*}/, '')}
13 indicators
= %w(! •
# -)
15 print indicators
[level
]
17 print
"\n%s %s\n" % ['*' * (level+
1), what
]
21 # There are several titles that are spread in more than one line. Make
22 # them into translatable sentences.
23 log
0, 'Merging multiline sentences '
24 [ ['Made', '', 'with', '', 'Creative', '', 'Commons'],
25 ['The New','', 'World of', '', 'Digital', '', 'Commons'],
26 ['How', '', 'to Be', '', 'Made with', '', 'Creative', '', 'Commons'],
27 ['Providing a custom service to consumers of your work *', '\[MARKET-BASED\]*'],
28 ['Memberships and individual donations', '*\[RECIPROCITY-BASED\]*'],
29 ['The', '', 'Creative', '', 'Commons', '', 'Licenses'],
30 ['jonathanmann.net and', '', 'jonathanmann.bandcamp.com'],
31 ['PLOS','', '(Public Library of Science)']
33 # This should be done more generic, more robust... But before
34 # burning brain cells, verify if it's needed!
37 data.each_with_index
do |lin
, idx
|
43 raise RuntimeError
, 'Anchor string («%s» for «%s») not found' %
44 [str
[0], str
.reject
{|word
| word
==''}.join(' ')]
45 elsif matches
.size
> 1
46 raise RuntimeError
, 'Anchor string (%s) appears multiple times: %s' %
47 [str
[0], matches
.map
{|i
| i
.to_s
}.join(', ')]
49 log
2, 'Matches %s: %d - %s' % [str
.join(' '), matches
.size
, matches
.join(',')]
52 at
= data.index(str
[0])
53 joined
= str
.reject
{|word
| word
==''}.join(' ')
55 if str
[offset
] !
= data[at+offset
]
57 'Warning: String does not match ("%s" of "%s", offset %d, book at %d)' %
58 [str
[offset
], joined
, offset
, at+offset
]
63 (str
.size
- 1).times
{ data.delete_at(at+
1) }
66 log
0, 'correct emphesis in some titles'
67 data.map
{|lin
| lin
.gsub!
(/ *\* \\\[/, ' *\[')}
69 log
0, 'tag title and author'
70 data.delete_at(1) # Remove unwanted blank line between title and authors
71 data[0].sub!
(/^/, '% ') # title
72 data[1].sub!
(/^/, '% ') # authors
73 data[1].sub!
(/ and /, ';') # authors
75 # Mark up headings: Very artisanal and suboptimal, but should do the
78 # For every heading, put here the full string and its heading level,
86 # Try to keep this ordered as it appears within the book, as it will
87 # help us spot omissions and mistakes!
88 log
0, 'Mark up headings'
92 [1, 'The Big Picture'],
93 [2, 'The New World of Digital Commons'],
94 [3, 'The Commons, the Market, and the State'],
95 [3, 'The Four Aspects of a Resource'],
96 [4, 'Characteristics'],
97 [4, 'People and processes'],
98 [4, 'Norms and rules'],
100 [3, 'A Short History of the Commons'],
101 [3, 'The Digital Revolution'],
102 [3, 'The Birth of Creative Commons'],
103 [3, 'The Changing Market'],
104 [3, 'Benefits of the Digital Commons'],
105 [3, 'Our Case Studies'],
107 [2, 'How to Be Made with Creative Commons'],
108 [3, 'Problem Zero: Getting Discovered'],
109 [4, 'Use CC to grow a larger audience'],
110 [4, 'Use CC to get attribution and name recognition'],
111 [4, 'Use CC-licensed content as a marketing tool'],
112 [4, 'Use CC to enable hands-on engagement with your work'],
113 [4, 'Use CC to differentiate yourself'],
115 [4, 'Market-based revenue streams'],
116 [4, 'Providing a custom service to consumers of your work *\[MARKET-BASED\]*'],
117 [4, 'Charging for the physical copy *\[MARKET-BASED\]*'],
118 [4, 'Charging for the in-person version *\[MARKET-BASED\]*'],
119 [4, 'Selling merchandise *\[MARKET-BASED\]*'],
120 [4, 'Charging advertisers or sponsors *\[MARKET-BASED\]*'],
121 [4, 'Charging your content creators *\[MARKET-BASED\]*'],
122 [4, 'Charging a transaction fee *\[MARKET-BASED\]*'],
123 [4, 'Providing a service to your creators *\[MARKET-BASED\]*'],
124 [4, 'Licensing a trademark *\[MARKET-BASED\]*'],
125 [4, 'Reciprocity-based revenue streams'],
126 [4, 'Memberships and individual donations *\[RECIPROCITY-BASED\]*'],
127 [4, 'The pay-what-you-want model *\[RECIPROCITY-BASED\]*'],
128 [4, 'Crowdfunding *\[RECIPROCITY-BASED\]*'],
129 [3, 'Making Human Connections'],
131 [4, 'Be open and accountable'],
132 [4, 'Design for the good actors'],
133 [4, 'Treat humans like, well, humans'],
134 [4, 'State your principles and stick to them'],
135 [4, 'Build a community'],
136 [4, 'Give more to the commons than you take'],
137 [4, 'Involve people in what you do'],
139 [2, 'The Creative Commons Licenses'],
141 [1, 'The Case Studies'],
144 [2, 'Blender Institute'],
145 [2, 'Cards Against Humanity'],
146 [2, 'The Conversation'],
147 [2, 'Cory Doctorow'],
150 [2, 'Knowledge Unlatched'],
151 [2, 'Lumen Learning'],
152 [2, 'Jonathan Mann'],
154 [2, 'Open Data Institute'],
157 [2, 'Amanda Palmer'],
158 [2, 'PLOS (Public Library of Science)'],
164 [2, 'Tribe of Noise'],
165 [2, 'Wikimedia Foundation'],
167 [1, 'Acknowledgments'],
170 log
1, item
.join(' -> ')
171 at
= data.index
{|i
| i
== item
[1]}
173 raise RuntimeError
, 'Heading string (level %d) not found: «%s»' % item
175 data[at
] = '%s %s' % ['#' * item
[0], data[at
]]
178 # We have the explicit strings "Part 1" and "Part 2" as structural
179 # elements — They are to be generated upon book compilation. Nuke
181 data.delete("# Part 1")
182 data.delete("# Part 2")
184 log
0, 'add heading to colophon page'
185 data.insert(data.index('Made With Creative Commons'), '## Colophon {-}')
187 log
0, 'add dedication as separeate chapter'
188 data.insert(data.index('“I don’t know a whole lot about nonfiction journalism. . .'), '## Dedication {-}')
190 # Join erroneously split paragraphs: Write the contents of the line
191 # _preceding_ the unneeded break, the break will be removed.
193 # I'm noting the line number for each _after_ corrections so it's
194 # easier to find them; please keep them sorted! :-P
195 log
0, 'Join erroneously split paragraphs'
196 ['content and, in turn, spend money and', # 1595
197 'still other', # 1662
198 'content functions as a marketing tool for the paid product or', # 1724
199 'lowest-common-denominator solutions and', #2035
200 'to the values symbolized by', # 2145
201 'the kinds of participative communities that drive open', # 2157
203 'At a minimum, a CC-', # 2375
204 'easier to trust a', # 2580
205 'free download, the', # 3086
206 'openness to fans remixing the game—give', # 3087
207 'Attribution-', # 3307
208 'both journal publishers and researchers. Figshare now provides', # 3672
209 'get the “network effect”—', # 4002
210 'access to scholarly books. For Frances, the current scholarly-', # 4033
213 'contributing to the open', # 4438
214 'doesn’t seem like it should be sung about', # 4616
215 'songwriter, and he has found a way to keep it interesting for', # 4624
216 'building trust is the top', # 4793
219 'authors and Shuttleworth; Mark remains incredibly proud of this', # 6452
220 'BY-SA and opting in others with collecting societies like', # 7218
221 'Cecilie Maria, Cedric Howe, Cefn Hoile,', # 7796
222 'Braddlee, Drew Spencer, Duncan', # 7839
223 'Elizabeth Holloway, Ellen Buecher, Ellen Kaye-', # 7844
227 at
= data.index
{|i
| i
== line
}
228 if !at
.nil? and data[at+
1] == ''
233 log
0, 'Mark quote in dedication as quote with attribute in markdown'
234 start
= "“I don’t know a whole lot about nonfiction journalism. . ."
235 stop
= "- David Foster Wallace"
237 data.each_with_index
do |lin
, idx
|
239 lin
.sub!
(/^- /, "> — ")
240 lin
.sub!
("David Foster Wallace", "*David Foster Wallace*")
252 log
0, 'Identify and mark footnotes/endnodes'
255 data.each_with_index
do |lin
, idx
|
256 if lin
=~
/^## (.+)$/
257 scope
=$1.gsub(" ", "-")
259 # First, mark note reference
260 lin
.sub!
(/([a-z]\.["”]?)(\d+)(\s)/, "\\1[^" + scope +
"-\\2]\\3")
261 lin
.sub!
(/([a-z]\.["”]?)(\d+)$/, "\\1[^" + scope +
"-\\2]")
262 # Next, mark note content, only between /Web Links?|Notes/ and next heading
264 lin
.sub!
(/^(\d+)\. /, "[^" + scope +
"-\\1]: ")
269 if lin
=~
/^(### Notes|Web links?)/
274 log
0, 'Turn indented block after use cases into block quotes'
277 data.each_with_index
do |lin
, idx
|
281 if lin
=~
/^> Profile written by/
285 if lin
=~
/^## Bibliography/
289 if lin
=~
/^## Arduino/
292 if inscope
and lin
=~
/^## /
298 log
0, 'Writing processed file'
299 File
.open(dstfile
, 'w') {|f
| f
.puts
data.join("\n")}