├── .editorconfig ├── .gitignore ├── LICENSE ├── README.md ├── Setup.hs ├── rundoc.cabal ├── src ├── Metropolis │ ├── Types.hs │ └── Worker.hs └── Text │ └── Rundoc.hs ├── tests ├── Metropolis │ └── Worker │ │ └── Tests.hs └── rundoc-tests.hs └── utils └── RundocFilter.hs /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | dist/* 3 | .cabal-sandbox 4 | cabal.sandbox.config 5 | *.diff 6 | *.o 7 | *.hi 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies of this license 6 | document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure cooperation 12 | with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed to 15 | take away your freedom to share and change the works. By contrast, our 16 | General Public Licenses are intended to guarantee your freedom to share and 17 | change all versions of a program--to make sure it remains free software for 18 | all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not price. Our 21 | General Public Licenses are designed to make sure that you have the freedom to 22 | distribute copies of free software (and charge for them if you wish), that you 23 | receive source code or can get it if you want it, that you can change the 24 | software or use pieces of it in new free programs, and that you know you can 25 | do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights with two 28 | steps: (1) assert copyright on the software, and (2) offer you this License 29 | which gives you legal permission to copy, distribute and/or modify the 30 | software. 31 | 32 | A secondary benefit of defending all users' freedom is that improvements 33 | made in alternate versions of the program, if they receive widespread use, 34 | become available for other developers to incorporate. Many developers of free 35 | software are heartened and encouraged by the resulting cooperation. However, 36 | in the case of software used on network servers, this result may fail to come 37 | about. The GNU General Public License permits making a modified version and 38 | letting the public access it on a server without ever releasing its source 39 | code to the public. 40 | 41 | The GNU Affero General Public License is designed specifically to ensure 42 | that, in such cases, the modified source code becomes available to the 43 | community. It requires the operator of a network server to provide the source 44 | code of the modified version running there to the users of that server. 45 | Therefore, public use of a modified version, on a publicly accessible server, 46 | gives the public access to the source code of the modified version. 47 | 48 | An older license, called the Affero General Public License and published by 49 | Affero, was designed to accomplish similar goals. This is a different 50 | license, not a version of the Affero GPL, but Affero has released a new 51 | version of the Affero GPL which permits relicensing under this license. 52 | 53 | The precise terms and conditions for copying, distribution and modification 54 | follow. 55 | 56 | TERMS AND CONDITIONS 57 | 58 | 0. Definitions. 59 | 60 | "This License" refers to version 3 of the GNU Affero General Public License. 61 | 62 | "Copyright" also means copyright-like laws that apply to other kinds of 63 | works, such as semiconductor masks. 64 | 65 | "The Program" refers to any copyrightable work licensed under this License. 66 | Each licensee is addressed as "you". "Licensees" and "recipients" may be 67 | individuals or organizations. 68 | 69 | To "modify" a work means to copy from or adapt all or part of the work in a 70 | fashion requiring copyright permission, other than the making of an exact 71 | copy. The resulting work is called a "modified version" of the earlier work 72 | or a work "based on" the earlier work. 73 | 74 | A "covered work" means either the unmodified Program or a work based on the 75 | Program. 76 | 77 | To "propagate" a work means to do anything with it that, without permission, 78 | would make you directly or secondarily liable for infringement under 79 | applicable copyright law, except executing it on a computer or modifying a 80 | private copy. Propagation includes copying, distribution (with or without 81 | modification), making available to the public, and in some countries other 82 | activities as well. 83 | 84 | To "convey" a work means any kind of propagation that enables other parties 85 | to make or receive copies. Mere interaction with a user through a computer 86 | network, with no transfer of a copy, is not conveying. 87 | 88 | An interactive user interface displays "Appropriate Legal Notices" to the 89 | extent that it includes a convenient and prominently visible feature that (1) 90 | displays an appropriate copyright notice, and (2) tells the user that there is 91 | no warranty for the work (except to the extent that warranties are provided), 92 | that licensees may convey the work under this License, and how to view a copy 93 | of this License. If the interface presents a list of user commands or 94 | options, such as a menu, a prominent item in the list meets this criterion. 95 | 96 | 1. Source Code. 97 | 98 | The "source code" for a work means the preferred form of the work for making 99 | modifications to it. "Object code" means any non-source form of a work. 100 | 101 | A "Standard Interface" means an interface that either is an official 102 | standard defined by a recognized standards body, or, in the case of interfaces 103 | specified for a particular programming language, one that is widely used among 104 | developers working in that language. 105 | 106 | The "System Libraries" of an executable work include anything, other than 107 | the work as a whole, that (a) is included in the normal form of packaging a 108 | Major Component, but which is not part of that Major Component, and (b) serves 109 | only to enable use of the work with that Major Component, or to implement a 110 | Standard Interface for which an implementation is available to the public in 111 | source code form. A "Major Component", in this context, means a major 112 | essential component (kernel, window system, and so on) of the specific 113 | operating system (if any) on which the executable work runs, or a compiler 114 | used to produce the work, or an object code interpreter used to run it. 115 | 116 | The "Corresponding Source" for a work in object code form means all the 117 | source code needed to generate, install, and (for an executable work) run the 118 | object code and to modify the work, including scripts to control those 119 | activities. However, it does not include the work's System Libraries, or 120 | general-purpose tools or generally available free programs which are used 121 | unmodified in performing those activities but which are not part of the work. 122 | For example, Corresponding Source includes interface definition files 123 | associated with source files for the work, and the source code for shared 124 | libraries and dynamically linked subprograms that the work is specifically 125 | designed to require, such as by intimate data communication or control flow 126 | between those subprograms and other parts of the work. 127 | 128 | The Corresponding Source need not include anything that users can regenerate 129 | automatically from other parts of the Corresponding Source. 130 | 131 | The Corresponding Source for a work in source code form is that same work. 132 | 133 | 2. Basic Permissions. 134 | 135 | All rights granted under this License are granted for the term of copyright 136 | on the Program, and are irrevocable provided the stated conditions are met. 137 | This License explicitly affirms your unlimited permission to run the 138 | unmodified Program. The output from running a covered work is covered by this 139 | License only if the output, given its content, constitutes a covered work. 140 | This License acknowledges your rights of fair use or other equivalent, as 141 | provided by copyright law. 142 | 143 | You may make, run and propagate covered works that you do not convey, 144 | without conditions so long as your license otherwise remains in force. You 145 | may convey covered works to others for the sole purpose of having them make 146 | modifications exclusively for you, or provide you with facilities for running 147 | those works, provided that you comply with the terms of this License in 148 | conveying all material for which you do not control copyright. Those thus 149 | making or running the covered works for you must do so exclusively on your 150 | behalf, under your direction and control, on terms that prohibit them from 151 | making any copies of your copyrighted material outside their relationship with 152 | you. 153 | 154 | Conveying under any other circumstances is permitted solely under the 155 | conditions stated below. Sublicensing is not allowed; section 10 makes it 156 | unnecessary. 157 | 158 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 159 | 160 | No covered work shall be deemed part of an effective technological measure 161 | under any applicable law fulfilling obligations under article 11 of the WIPO 162 | copyright treaty adopted on 20 December 1996, or similar laws prohibiting or 163 | restricting circumvention of such measures. 164 | 165 | When you convey a covered work, you waive any legal power to forbid 166 | circumvention of technological measures to the extent such circumvention is 167 | effected by exercising rights under this License with respect to the covered 168 | work, and you disclaim any intention to limit operation or modification of the 169 | work as a means of enforcing, against the work's users, your or third parties' 170 | legal rights to forbid circumvention of technological measures. 171 | 172 | 4. Conveying Verbatim Copies. 173 | 174 | You may convey verbatim copies of the Program's source code as you receive 175 | it, in any medium, provided that you conspicuously and appropriately publish 176 | on each copy an appropriate copyright notice; keep intact all notices stating 177 | that this License and any non-permissive terms added in accord with section 7 178 | apply to the code; keep intact all notices of the absence of any warranty; and 179 | give all recipients a copy of this License along with the Program. 180 | 181 | You may charge any price or no price for each copy that you convey, and you 182 | may offer support or warranty protection for a fee. 183 | 184 | 5. Conveying Modified Source Versions. 185 | 186 | You may convey a work based on the Program, or the modifications to produce 187 | it from the Program, in the form of source code under the terms of section 4, 188 | provided that you also meet all of these conditions: 189 | 190 | a) The work must carry prominent notices stating that you modified it, and 191 | giving a relevant date. 192 | 193 | b) The work must carry prominent notices stating that it is released under 194 | this License and any conditions added under section 7. This requirement 195 | modifies the requirement in section 4 to "keep intact all notices". 196 | 197 | c) You must license the entire work, as a whole, under this License to 198 | anyone who comes into possession of a copy. This License will therefore 199 | apply, along with any applicable section 7 additional terms, to the whole 200 | of the work, and all its parts, regardless of how they are packaged. This 201 | License gives no permission to license the work in any other way, but it 202 | does not invalidate such permission if you have separately received it. 203 | 204 | d) If the work has interactive user interfaces, each must display 205 | Appropriate Legal Notices; however, if the Program has interactive 206 | interfaces that do not display Appropriate Legal Notices, your work need 207 | not make them do so. 208 | 209 | A compilation of a covered work with other separate and independent works, 210 | which are not by their nature extensions of the covered work, and which are 211 | not combined with it such as to form a larger program, in or on a volume of a 212 | storage or distribution medium, is called an "aggregate" if the compilation 213 | and its resulting copyright are not used to limit the access or legal rights 214 | of the compilation's users beyond what the individual works permit. Inclusion 215 | of a covered work in an aggregate does not cause this License to apply to the 216 | other parts of the aggregate. 217 | 218 | 6. Conveying Non-Source Forms. 219 | 220 | You may convey a covered work in object code form under the terms of 221 | sections 4 and 5, provided that you also convey the machine-readable 222 | Corresponding Source under the terms of this License, in one of these ways: 223 | 224 | a) Convey the object code in, or embodied in, a physical product 225 | (including a physical distribution medium), accompanied by the 226 | Corresponding Source fixed on a durable physical medium customarily used 227 | for software interchange. 228 | 229 | b) Convey the object code in, or embodied in, a physical product 230 | (including a physical distribution medium), accompanied by a written 231 | offer, valid for at least three years and valid for as long as you offer 232 | spare parts or customer support for that product model, to give anyone who 233 | possesses the object code either (1) a copy of the Corresponding Source 234 | for all the software in the product that is covered by this License, on a 235 | durable physical medium customarily used for software interchange, for a 236 | price no more than your reasonable cost of physically performing this 237 | conveying of source, or (2) access to copy the Corresponding Source from a 238 | network server at no charge. 239 | 240 | c) Convey individual copies of the object code with a copy of the written 241 | offer to provide the Corresponding Source. This alternative is allowed 242 | only occasionally and noncommercially, and only if you received the object 243 | code with such an offer, in accord with subsection 6b. 244 | 245 | d) Convey the object code by offering access from a designated place 246 | (gratis or for a charge), and offer equivalent access to the Corresponding 247 | Source in the same way through the same place at no further charge. You 248 | need not require recipients to copy the Corresponding Source along with 249 | the object code. If the place to copy the object code is a network 250 | server, the Corresponding Source may be on a different server (operated by 251 | you or a third party) that supports equivalent copying facilities, 252 | provided you maintain clear directions next to the object code saying 253 | where to find the Corresponding Source. Regardless of what server hosts 254 | the Corresponding Source, you remain obligated to ensure that it is 255 | available for as long as needed to satisfy these requirements. 256 | 257 | e) Convey the object code using peer-to-peer transmission, provided you 258 | inform other peers where the object code and Corresponding Source of the 259 | work are being offered to the general public at no charge under subsection 260 | 6d. 261 | 262 | A separable portion of the object code, whose source code is excluded from 263 | the Corresponding Source as a System Library, need not be included in 264 | conveying the object code work. 265 | 266 | A "User Product" is either (1) a "consumer product", which means any 267 | tangible personal property which is normally used for personal, family, or 268 | household purposes, or (2) anything designed or sold for incorporation into a 269 | dwelling. In determining whether a product is a consumer product, doubtful 270 | cases shall be resolved in favor of coverage. For a particular product 271 | received by a particular user, "normally used" refers to a typical or common 272 | use of that class of product, regardless of the status of the particular user 273 | or of the way in which the particular user actually uses, or expects or is 274 | expected to use, the product. A product is a consumer product regardless of 275 | whether the product has substantial commercial, industrial or non-consumer 276 | uses, unless such uses represent the only significant mode of use of the 277 | product. 278 | 279 | "Installation Information" for a User Product means any methods, procedures, 280 | authorization keys, or other information required to install and execute 281 | modified versions of a covered work in that User Product from a modified 282 | version of its Corresponding Source. The information must suffice to ensure 283 | that the continued functioning of the modified object code is in no case 284 | prevented or interfered with solely because modification has been made. 285 | 286 | If you convey an object code work under this section in, or with, or 287 | specifically for use in, a User Product, and the conveying occurs as part of a 288 | transaction in which the right of possession and use of the User Product is 289 | transferred to the recipient in perpetuity or for a fixed term (regardless of 290 | how the transaction is characterized), the Corresponding Source conveyed under 291 | this section must be accompanied by the Installation Information. But this 292 | requirement does not apply if neither you nor any third party retains the 293 | ability to install modified object code on the User Product (for example, the 294 | work has been installed in ROM). 295 | 296 | The requirement to provide Installation Information does not include a 297 | requirement to continue to provide support service, warranty, or updates for a 298 | work that has been modified or installed by the recipient, or for the User 299 | Product in which it has been modified or installed. Access to a network may 300 | be denied when the modification itself materially and adversely affects the 301 | operation of the network or violates the rules and protocols for communication 302 | across the network. 303 | 304 | Corresponding Source conveyed, and Installation Information provided, in 305 | accord with this section must be in a format that is publicly documented (and 306 | with an implementation available to the public in source code form), and must 307 | require no special password or key for unpacking, reading or copying. 308 | 309 | 7. Additional Terms. 310 | 311 | "Additional permissions" are terms that supplement the terms of this License 312 | by making exceptions from one or more of its conditions. Additional 313 | permissions that are applicable to the entire Program shall be treated as 314 | though they were included in this License, to the extent that they are valid 315 | under applicable law. If additional permissions apply only to part of the 316 | Program, that part may be used separately under those permissions, but the 317 | entire Program remains governed by this License without regard to the 318 | additional permissions. 319 | 320 | When you convey a copy of a covered work, you may at your option remove any 321 | additional permissions from that copy, or from any part of it. (Additional 322 | permissions may be written to require their own removal in certain cases when 323 | you modify the work.) You may place additional permissions on material, added 324 | by you to a covered work, for which you have or can give appropriate copyright 325 | permission. 326 | 327 | Notwithstanding any other provision of this License, for material you add to 328 | a covered work, you may (if authorized by the copyright holders of that 329 | material) supplement the terms of this License with terms: 330 | 331 | a) Disclaiming warranty or limiting liability differently from the terms 332 | of sections 15 and 16 of this License; or 333 | 334 | b) Requiring preservation of specified reasonable legal notices or author 335 | attributions in that material or in the Appropriate Legal Notices 336 | displayed by works containing it; or 337 | 338 | c) Prohibiting misrepresentation of the origin of that material, or 339 | requiring that modified versions of such material be marked in reasonable 340 | ways as different from the original version; or 341 | 342 | d) Limiting the use for publicity purposes of names of licensors or 343 | authors of the material; or 344 | 345 | e) Declining to grant rights under trademark law for use of some trade 346 | names, trademarks, or service marks; or 347 | 348 | f) Requiring indemnification of licensors and authors of that material by 349 | anyone who conveys the material (or modified versions of it) with 350 | contractual assumptions of liability to the recipient, for any liability 351 | that these contractual assumptions directly impose on those licensors and 352 | authors. 353 | 354 | All other non-permissive additional terms are considered "further 355 | restrictions" within the meaning of section 10. If the Program as you 356 | received it, or any part of it, contains a notice stating that it is governed 357 | by this License along with a term that is a further restriction, you may 358 | remove that term. If a license document contains a further restriction but 359 | permits relicensing or conveying under this License, you may add to a covered 360 | work material governed by the terms of that license document, provided that 361 | the further restriction does not survive such relicensing or conveying. 362 | 363 | If you add terms to a covered work in accord with this section, you must 364 | place, in the relevant source files, a statement of the additional terms that 365 | apply to those files, or a notice indicating where to find the applicable 366 | terms. 367 | 368 | Additional terms, permissive or non-permissive, may be stated in the form of 369 | a separately written license, or stated as exceptions; the above requirements 370 | apply either way. 371 | 372 | 8. Termination. 373 | 374 | You may not propagate or modify a covered work except as expressly provided 375 | under this License. Any attempt otherwise to propagate or modify it is void, 376 | and will automatically terminate your rights under this License (including any 377 | patent licenses granted under the third paragraph of section 11). 378 | 379 | However, if you cease all violation of this License, then your license from 380 | a particular copyright holder is reinstated (a) provisionally, unless and 381 | until the copyright holder explicitly and finally terminates your license, and 382 | (b) permanently, if the copyright holder fails to notify you of the violation 383 | by some reasonable means prior to 60 days after the cessation. 384 | 385 | Moreover, your license from a particular copyright holder is reinstated 386 | permanently if the copyright holder notifies you of the violation by some 387 | reasonable means, this is the first time you have received notice of violation 388 | of this License (for any work) from that copyright holder, and you cure the 389 | violation prior to 30 days after your receipt of the notice. 390 | 391 | Termination of your rights under this section does not terminate the 392 | licenses of parties who have received copies or rights from you under this 393 | License. If your rights have been terminated and not permanently reinstated, 394 | you do not qualify to receive new licenses for the same material under section 395 | 10. 396 | 397 | 9. Acceptance Not Required for Having Copies. 398 | 399 | You are not required to accept this License in order to receive or run a 400 | copy of the Program. Ancillary propagation of a covered work occurring solely 401 | as a consequence of using peer-to-peer transmission to receive a copy likewise 402 | does not require acceptance. However, nothing other than this License grants 403 | you permission to propagate or modify any covered work. These actions 404 | infringe copyright if you do not accept this License. Therefore, by modifying 405 | or propagating a covered work, you indicate your acceptance of this License to 406 | do so. 407 | 408 | 10. Automatic Licensing of Downstream Recipients. 409 | 410 | Each time you convey a covered work, the recipient automatically receives a 411 | license from the original licensors, to run, modify and propagate that work, 412 | subject to this License. You are not responsible for enforcing compliance by 413 | third parties with this License. 414 | 415 | An "entity transaction" is a transaction transferring control of an 416 | organization, or substantially all assets of one, or subdividing an 417 | organization, or merging organizations. If propagation of a covered work 418 | results from an entity transaction, each party to that transaction who 419 | receives a copy of the work also receives whatever licenses to the work the 420 | party's predecessor in interest had or could give under the previous 421 | paragraph, plus a right to possession of the Corresponding Source of the work 422 | from the predecessor in interest, if the predecessor has it or can get it with 423 | reasonable efforts. 424 | 425 | You may not impose any further restrictions on the exercise of the rights 426 | granted or affirmed under this License. For example, you may not impose a 427 | license fee, royalty, or other charge for exercise of rights granted under 428 | this License, and you may not initiate litigation (including a cross-claim or 429 | counterclaim in a lawsuit) alleging that any patent claim is infringed by 430 | making, using, selling, offering for sale, or importing the Program or any 431 | portion of it. 432 | 433 | 11. Patents. 434 | 435 | A "contributor" is a copyright holder who authorizes use under this License 436 | of the Program or a work on which the Program is based. The work thus 437 | licensed is called the contributor's "contributor version". 438 | 439 | A contributor's "essential patent claims" are all patent claims owned or 440 | controlled by the contributor, whether already acquired or hereafter acquired, 441 | that would be infringed by some manner, permitted by this License, of making, 442 | using, or selling its contributor version, but do not include claims that 443 | would be infringed only as a consequence of further modification of the 444 | contributor version. For purposes of this definition, "control" includes the 445 | right to grant patent sublicenses in a manner consistent with the requirements 446 | of this License. 447 | 448 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent 449 | license under the contributor's essential patent claims, to make, use, sell, 450 | offer for sale, import and otherwise run, modify and propagate the contents of 451 | its contributor version. 452 | 453 | In the following three paragraphs, a "patent license" is any express 454 | agreement or commitment, however denominated, not to enforce a patent (such as 455 | an express permission to practice a patent or covenant not to sue for patent 456 | infringement). To "grant" such a patent license to a party means to make such 457 | an agreement or commitment not to enforce a patent against the party. 458 | 459 | If you convey a covered work, knowingly relying on a patent license, and the 460 | Corresponding Source of the work is not available for anyone to copy, free of 461 | charge and under the terms of this License, through a publicly available 462 | network server or other readily accessible means, then you must either (1) 463 | cause the Corresponding Source to be so available, or (2) arrange to deprive 464 | yourself of the benefit of the patent license for this particular work, or (3) 465 | arrange, in a manner consistent with the requirements of this License, to 466 | extend the patent license to downstream recipients. "Knowingly relying" means 467 | you have actual knowledge that, but for the patent license, your conveying the 468 | covered work in a country, or your recipient's use of the covered work in a 469 | country, would infringe one or more identifiable patents in that country that 470 | you have reason to believe are valid. 471 | 472 | If, pursuant to or in connection with a single transaction or arrangement, 473 | you convey, or propagate by procuring conveyance of, a covered work, and grant 474 | a patent license to some of the parties receiving the covered work authorizing 475 | them to use, propagate, modify or convey a specific copy of the covered work, 476 | then the patent license you grant is automatically extended to all recipients 477 | of the covered work and works based on it. 478 | 479 | A patent license is "discriminatory" if it does not include within the scope 480 | of its coverage, prohibits the exercise of, or is conditioned on the 481 | non-exercise of one or more of the rights that are specifically granted under 482 | this License. You may not convey a covered work if you are a party to an 483 | arrangement with a third party that is in the business of distributing 484 | software, under which you make payment to the third party based on the extent 485 | of your activity of conveying the work, and under which the third party 486 | grants, to any of the parties who would receive the covered work from you, a 487 | discriminatory patent license (a) in connection with copies of the covered 488 | work conveyed by you (or copies made from those copies), or (b) primarily for 489 | and in connection with specific products or compilations that contain the 490 | covered work, unless you entered into that arrangement, or that patent license 491 | was granted, prior to 28 March 2007. 492 | 493 | Nothing in this License shall be construed as excluding or limiting any 494 | implied license or other defenses to infringement that may otherwise be 495 | available to you under applicable patent law. 496 | 497 | 12. No Surrender of Others' Freedom. 498 | 499 | If conditions are imposed on you (whether by court order, agreement or 500 | otherwise) that contradict the conditions of this License, they do not excuse 501 | you from the conditions of this License. If you cannot convey a covered work 502 | so as to satisfy simultaneously your obligations under this License and any 503 | other pertinent obligations, then as a consequence you may not convey it at 504 | all. For example, if you agree to terms that obligate you to collect a 505 | royalty for further conveying from those to whom you convey the Program, the 506 | only way you could satisfy both those terms and this License would be to 507 | refrain entirely from conveying the Program. 508 | 509 | 13. Remote Network Interaction; Use with the GNU General Public License. 510 | 511 | Notwithstanding any other provision of this License, if you modify the 512 | Program, your modified version must prominently offer all users interacting 513 | with it remotely through a computer network (if your version supports such 514 | interaction) an opportunity to receive the Corresponding Source of your 515 | version by providing access to the Corresponding Source from a network server 516 | at no charge, through some standard or customary means of facilitating copying 517 | of software. This Corresponding Source shall include the Corresponding Source 518 | for any work covered by version 3 of the GNU General Public License that is 519 | incorporated pursuant to the following paragraph. 520 | 521 | Notwithstanding any other provision of this License, you have permission to 522 | link or combine any covered work with a work licensed under version 3 of the 523 | GNU General Public License into a single combined work, and to convey the 524 | resulting work. The terms of this License will continue to apply to the part 525 | which is the covered work, but the work with which it is combined will remain 526 | governed by version 3 of the GNU General Public License. 527 | 528 | 14. Revised Versions of this License. 529 | 530 | The Free Software Foundation may publish revised and/or new versions of the 531 | GNU Affero General Public License from time to time. Such new versions will 532 | be similar in spirit to the present version, but may differ in detail to 533 | address new problems or concerns. 534 | 535 | Each version is given a distinguishing version number. If the Program 536 | specifies that a certain numbered version of the GNU Affero General Public 537 | License "or any later version" applies to it, you have the option of following 538 | the terms and conditions either of that numbered version or of any later 539 | version published by the Free Software Foundation. If the Program does not 540 | specify a version number of the GNU Affero General Public License, you may 541 | choose any version ever published by the Free Software Foundation. 542 | 543 | If the Program specifies that a proxy can decide which future versions of 544 | the GNU Affero General Public License can be used, that proxy's public 545 | statement of acceptance of a version permanently authorizes you to choose that 546 | version for the Program. 547 | 548 | Later license versions may give you additional or different permissions. 549 | However, no additional obligations are imposed on any author or copyright 550 | holder as a result of your choosing to follow a later version. 551 | 552 | 15. Disclaimer of Warranty. 553 | 554 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE 555 | LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 556 | OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 557 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 558 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO 559 | THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM 560 | PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR 561 | CORRECTION. 562 | 563 | 16. Limitation of Liability. 564 | 565 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL 566 | ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE 567 | PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 568 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE 569 | OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR 570 | DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR 571 | A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH 572 | HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 573 | 574 | 17. Interpretation of Sections 15 and 16. 575 | 576 | If the disclaimer of warranty and limitation of liability provided above 577 | cannot be given local legal effect according to their terms, reviewing courts 578 | shall apply local law that most closely approximates an absolute waiver of all 579 | civil liability in connection with the Program, unless a warranty or 580 | assumption of liability accompanies a copy of the Program in return for a fee. 581 | 582 | END OF TERMS AND CONDITIONS 583 | 584 | How to Apply These Terms to Your New Programs 585 | 586 | If you develop a new program, and you want it to be of the greatest possible 587 | use to the public, the best way to achieve this is to make it free software 588 | which everyone can redistribute and change under these terms. 589 | 590 | To do so, attach the following notices to the program. It is safest to 591 | attach them to the start of each source file to most effectively state the 592 | exclusion of warranty; and each file should have at least the "copyright" line 593 | and a pointer to where the full notice is found. 594 | 595 | 596 | Copyright (C) 597 | 598 | This program is free software: you can redistribute it and/or modify it 599 | under the terms of the GNU Affero General Public License as published by 600 | the Free Software Foundation, either version 3 of the License, or (at your 601 | option) any later version. 602 | 603 | This program is distributed in the hope that it will be useful, but 604 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 605 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public 606 | License for more details. 607 | 608 | You should have received a copy of the GNU Affero General Public License 609 | along with this program. If not, see . 610 | 611 | Also add information on how to contact you by electronic and paper mail. 612 | 613 | If your software can interact with users remotely through a computer 614 | network, you should also make sure that it provides a way for users to get its 615 | source. For example, if your program is a web application, its interface 616 | could display a "Source" link that leads users to an archive of the code. 617 | There are many ways you could offer source, and different solutions will be 618 | better for different programs; see section 13 for the specific requirements. 619 | 620 | You should also get your employer (if you work as a programmer) or school, 621 | if any, to sign a "copyright disclaimer" for the program, if necessary. 622 | For more information on this, and how to apply and follow the GNU AGPL, see 623 | . 624 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rundoc 2 | 3 | Rundoc is a tool to run code from Pandoc's code blocks and to insert the 4 | results back into the document. It aims to provide functionality similar to 5 | Emacs' Org-Babel library. 6 | 7 | ## Basics 8 | 9 | Rundoc is intended to be used as a filter for 10 | [Pandoc](http://johnmacfarlane.net/pandoc). It recognizes code blocks marked 11 | as runable, evaluates them and re-inserts the result into the document. 12 | Blocks are marked as runable with the special class `rundoc-block`, the 13 | interpreter for the block is chosen via an `rundoc-language` option. The 14 | following is a simple example in markdown: 15 | 16 | ```{.rundoc-block rundoc-language=sh rundoc-exports=result} 17 | printf 'The answer to the Ultimate Question is %d.' $((6 * 7)) 18 | ``` 19 | 20 | Assuming the above snippet is safed in `rundoc-example.md`, then running 21 | 22 | pandoc --filter rundoc --from markdown --to html rundoc-example.md 23 | 24 | will produce 25 | 26 | ```html 27 |

The answer to the Ultimate Question is 42.

28 | ``` 29 | 30 | Rundoc has multiple options as to what is inserted back into the document. 31 | This can be controlled via the `rundoc-exports` option. Recognized options 32 | are `code`, `result`, `both` or `none`. Changing the respective setting in 33 | above example to `rundoc-exports=both` will result in 34 | 35 | ```html 36 |
37 |

printf 'The answer to the Ultimate Question is %d.' $((6 * 7))

38 |

The answer to the Ultimate Question is 42.

39 |
40 | ``` 41 | 42 | 43 | ## License 44 | 45 | Rundoc is free software: you can redistribute it and/or modify it under the 46 | terms of the GNU Affero General Public License as published by the Free 47 | Software Foundation, either version 3 of the License, or (at your option) any 48 | later version. 49 | 50 | 51 | Rundoc is distributed in the hope that it will be useful, but WITHOUT ANY 52 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 53 | A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 54 | details. 55 | 56 | You should have received a copy of the GNU Affero General Public License 57 | along with this program. If not, see . 58 | -------------------------------------------------------------------------------- /Setup.hs: -------------------------------------------------------------------------------- 1 | import Distribution.Simple 2 | main = defaultMain 3 | -------------------------------------------------------------------------------- /rundoc.cabal: -------------------------------------------------------------------------------- 1 | name: rundoc 2 | version: 0.2.0.0 3 | synopsis: An Org-babel like library for Pandoc documents. 4 | license: AGPL-3 5 | license-file: LICENSE 6 | author: Albert Krewinkel 7 | maintainer: Albert Krewinkel 8 | copyright: © 2014 Albert Krewinkel 9 | category: Text 10 | build-type: Simple 11 | cabal-version: >= 1.10 12 | description: Rundoc is a library to run code from specifically 13 | marked Pandoc code blocks. 14 | 15 | data-files: README.md 16 | 17 | source-repository head 18 | type: git 19 | location: git://github.com/tarleb/rundoc 20 | 21 | library 22 | build-depends: 23 | base >= 4.6 && < 5 24 | , bifunctors == 4.1.* 25 | , containers == 0.5.* 26 | , data-default == 0.5.* 27 | , directory == 1.2.* 28 | , filepath == 1.3.* 29 | , pandoc >= 1.12.4 && < 1.13 30 | , pandoc-types >= 1.12.3 && < 1.13 31 | , process == 1.2.* 32 | , temporary == 1.2.* 33 | 34 | default-language: Haskell2010 35 | ghc-options: -rtsopts -Wall -fno-warn-unused-do-bind 36 | hs-source-dirs: src 37 | 38 | exposed-modules: 39 | Text.Rundoc 40 | , Metropolis.Types 41 | , Metropolis.Worker 42 | 43 | test-suite rundoc-tests 44 | type: exitcode-stdio-1.0 45 | default-language: Haskell2010 46 | ghc-options: -Wall 47 | main-is: rundoc-tests.hs 48 | hs-source-dirs: tests 49 | other-modules: 50 | Metropolis.Worker.Tests 51 | 52 | build-depends: 53 | base 54 | , rundoc 55 | , HUnit == 1.2.* 56 | , QuickCheck == 2.7.* 57 | , tasty == 0.8.* 58 | , tasty-hunit == 0.8.* 59 | , tasty-quickcheck == 0.8.* 60 | 61 | executable rundoc 62 | main-is: RundocFilter.hs 63 | hs-source-dirs: utils 64 | default-language: Haskell2010 65 | build-depends: 66 | base >= 4.6 && < 5 67 | , pandoc-types >= 1.12.3 && < 1.13 68 | , rundoc == 0.2.* 69 | -------------------------------------------------------------------------------- /src/Metropolis/Types.hs: -------------------------------------------------------------------------------- 1 | {- 2 | Copyright (C) 2014 Albert Krewinkel 3 | 4 | This program is free software: you can redistribute it and/or modify it 5 | under the terms of the GNU Affero General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or (at your 7 | option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public 12 | License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see . 16 | -} 17 | 18 | {- | 19 | Module : Metropolis.Types 20 | Copyright : © 2014 Albert Krewinkel 21 | License : GNU AGPL, version 3 or above 22 | 23 | Types for Metropolis, a library for universal code execution. 24 | -} 25 | module Metropolis.Types ( Language(..) 26 | , MetropolisResult(..) 27 | , MetropolisParameter(..) 28 | , Worker(..) 29 | , CodeString 30 | , ExitCode(..) 31 | , Default(def) 32 | , emptyResult 33 | ) where 34 | 35 | import System.Exit ( ExitCode(..) ) 36 | 37 | import Data.Default (Default(def)) 38 | import Data.Monoid (mempty) 39 | 40 | type CodeString = String 41 | 42 | -- | Metropolis parameters 43 | data MetropolisParameter = 44 | MetropolisParameter 45 | { parameterVariables :: [(String, String)] 46 | , parameterOutfile :: Maybe FilePath 47 | , parameterLanguage :: Language 48 | } deriving (Eq, Show) 49 | 50 | instance Default MetropolisParameter where 51 | def = MetropolisParameter 52 | { parameterVariables = [] 53 | , parameterOutfile = Nothing 54 | , parameterLanguage = UnknownLanguage "unspecified" 55 | } 56 | 57 | -- | Results of a computation. 58 | data MetropolisResult = MetropolisResult 59 | { resultOutput :: String 60 | , resultError :: String 61 | , resultFile :: Maybe FilePath 62 | , resultExitCode :: ExitCode 63 | , resultSource :: String 64 | } deriving (Eq, Show) 65 | 66 | emptyResult :: MetropolisResult 67 | emptyResult = 68 | MetropolisResult 69 | { resultOutput = mempty 70 | , resultError = mempty 71 | , resultFile = mempty 72 | , resultExitCode = ExitSuccess 73 | , resultSource = mempty 74 | } 75 | 76 | data Language = Ditaa 77 | | Haskell 78 | | R 79 | | Shell 80 | | UnknownLanguage String 81 | deriving (Eq, Ord, Show) 82 | 83 | newtype Worker = Worker { unWorker :: MetropolisParameter 84 | -> String 85 | -> MetropolisResult 86 | } 87 | -------------------------------------------------------------------------------- /src/Metropolis/Worker.hs: -------------------------------------------------------------------------------- 1 | {- 2 | Copyright (C) 2014 Albert Krewinkel 3 | 4 | This program is free software: you can redistribute it and/or modify it 5 | under the terms of the GNU Affero General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or (at your 7 | option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public 12 | License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see . 16 | -} 17 | 18 | {- | 19 | Module : Metropolis.Languages 20 | Copyright : © 2014 Albert Krewinkel 21 | License : GNU AGPL, version 3 or above 22 | 23 | Run of different languages, producing a unified result type. 24 | -} 25 | module Metropolis.Worker ( runCode 26 | , cannotRunLanguageResult 27 | ) where 28 | 29 | import Metropolis.Types 30 | import System.Process ( readProcessWithExitCode ) 31 | import System.IO.Temp 32 | import System.FilePath 33 | 34 | import Control.Applicative ((<$>), (<*>), pure) 35 | import Control.Monad (mzero) 36 | 37 | import Data.Map (Map) 38 | import qualified Data.Map as M 39 | import Data.Maybe (fromMaybe) 40 | 41 | runCode :: MetropolisParameter -> CodeString -> IO MetropolisResult 42 | runCode param cmd = 43 | fromMaybe (return $ cannotRunLanguageResult cmd) 44 | (interpretCommand param cmd) 45 | 46 | interpretCommand :: MetropolisParameter 47 | -> CodeString 48 | -> Maybe (IO MetropolisResult) 49 | interpretCommand param cmd = 50 | lookupWorker (parameterLanguage param) <*> pure param <*> pure cmd 51 | 52 | cannotRunLanguageResult :: CodeString -> MetropolisResult 53 | cannotRunLanguageResult code = 54 | emptyResult{ resultSource = code } 55 | 56 | type MetropolisWorker = MetropolisParameter -> CodeString -> IO MetropolisResult 57 | 58 | lookupWorker :: Language -> Maybe MetropolisWorker 59 | lookupWorker lang = M.lookup lang interpreters 60 | 61 | interpreters :: Map Language MetropolisWorker 62 | interpreters = M.fromList 63 | [ (Shell, shellWorker) 64 | , (Haskell, haskellWorker) 65 | , (Ditaa, ditaaWorker) 66 | , (R, rWorker) 67 | ] 68 | 69 | shellWorker :: MetropolisWorker 70 | shellWorker _ src = 71 | setResultSource src <$> runCommand "sh" ["-c", src] 72 | 73 | haskellWorker :: MetropolisWorker 74 | haskellWorker _ src = 75 | setResultSource src <$> runCommand "ghc" ["-e", src] 76 | 77 | setResultSource :: CodeString -> MetropolisResult -> MetropolisResult 78 | setResultSource src res = res{ resultSource = src } 79 | 80 | rWorker :: MetropolisWorker 81 | rWorker _ src = 82 | runCommandWithInput "R" ["--vanilla", "--slave", "--no-readline"] src 83 | 84 | ditaaWorker :: MetropolisWorker 85 | ditaaWorker params src = 86 | flip (maybe mzero) (parameterOutfile params) $ \outfile -> 87 | withSystemTempDirectory "rundocDitaa" $ \tmpdir -> do 88 | let infile = tmpdir "rundoc-input.ditaa" 89 | writeFile infile src 90 | res <- runCommand "ditaa" [ infile, "-o", outfile ] 91 | return $ setResultFile outfile res 92 | where setResultFile file res = res{ resultFile = Just file } 93 | 94 | resultsFromProcess :: (ExitCode, String, String) -> MetropolisResult 95 | resultsFromProcess (exitCode, stdout, stderr) = 96 | emptyResult{ resultOutput = stdout 97 | , resultError = stderr 98 | , resultExitCode = exitCode 99 | } 100 | 101 | runCommand :: FilePath 102 | -> [String] 103 | -> IO MetropolisResult 104 | runCommand exec args = do 105 | resultsFromProcess <$> readProcessWithExitCode exec args "" 106 | 107 | runCommandWithInput :: FilePath 108 | -> [String] 109 | -> String 110 | -> IO MetropolisResult 111 | runCommandWithInput exec args input = do 112 | setResultSource input . resultsFromProcess 113 | <$> readProcessWithExitCode exec args input 114 | -------------------------------------------------------------------------------- /src/Text/Rundoc.hs: -------------------------------------------------------------------------------- 1 | {- 2 | Copyright (C) 2014 Albert Krewinkel 3 | 4 | This program is free software: you can redistribute it and/or modify it 5 | under the terms of the GNU Affero General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or (at your 7 | option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public 12 | License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see . 16 | -} 17 | 18 | {- | 19 | Module : Text.Rundoc 20 | Copyright : © 2014 Albert Krewinkel 21 | License : GNU AGPL, version 3 or above 22 | 23 | Evaluate code in Rundoc code blocks and re-insert the results. 24 | -} 25 | module Text.Rundoc ( rundoc 26 | , runBlocks 27 | , runInlineCode 28 | , rundocBlockClass 29 | ) where 30 | 31 | import Metropolis.Types ( MetropolisResult(..) 32 | , MetropolisParameter(..) 33 | , Language(..) ) 34 | import Metropolis.Worker (runCode) 35 | 36 | import Text.Pandoc ( Attr, Inline( Code, Space, Span ) 37 | , Block ( Para, CodeBlock, Null, Div ) 38 | , nullAttr ) 39 | import Text.Pandoc.Walk (walkM) 40 | import Text.Pandoc.Builder (Inlines, Blocks) 41 | import qualified Text.Pandoc.Builder as B 42 | 43 | import Control.Applicative ((<$>)) 44 | import Data.Bifunctor (bimap) 45 | import Data.Default (Default(..)) 46 | import Data.List (foldl', isPrefixOf) 47 | import Data.Maybe (fromMaybe) 48 | import Data.Monoid (mconcat, mempty) 49 | 50 | -- | Run code and return the result if a rundoc code block is supplied; 51 | -- otherwise return the argument unaltered. 52 | rundoc :: Block -> IO Block 53 | rundoc x = runBlocks x >>= walkM runInlineCode 54 | 55 | -- | Run inline code blocks. 56 | runInlineCode :: Inline -> IO Inline 57 | runInlineCode inline = 58 | case inline of 59 | (Code attr code) | isRundocBlock attr -> evalInlineCode attr code 60 | _ -> return inline 61 | where 62 | evalInlineCode :: Attr -- ^ Old block attributes 63 | -> String -- ^ Code to evaluate 64 | -> IO Inline -- ^ Resulting inline 65 | evalInlineCode attr@(_,_,opts) code = 66 | let attr' = stripRundocAttrs attr 67 | rdOpts = rundocOptions opts 68 | in (setCodeAttr attr' 69 | . singularizeInlines 70 | . resultToInlines rdOpts) 71 | <$> evalCode rdOpts code 72 | 73 | -- | Run code blocks. 74 | runBlocks :: Block -> IO Block 75 | runBlocks block = 76 | case block of 77 | (CodeBlock attr code) | isRundocBlock attr -> evalBlock attr code 78 | _ -> return block 79 | where 80 | evalBlock :: Attr -> String -> IO Block 81 | evalBlock attr@(_,_,opts) code = 82 | let attr' = stripRundocAttrs attr 83 | rdOpts = rundocOptions opts 84 | in (setBlockCodeAttr attr' 85 | . singularizeBlocks 86 | . inlinesToBlocks 87 | . resultToInlines rdOpts) 88 | <$> evalCode rdOpts code 89 | 90 | isRundocBlock :: Attr -> Bool 91 | isRundocBlock (_,cls,_) = rundocBlockClass `elem` cls 92 | 93 | isRundocOption :: (String, String) -> Bool 94 | isRundocOption (key, _) = rundocPrefix `isPrefixOf` key 95 | 96 | -- | Prefix used for rundoc classes and parameters. 97 | rundocPrefix :: String 98 | rundocPrefix = "rundoc-" 99 | 100 | -- | Class-name used to mark rundoc blocks. 101 | rundocBlockClass :: String 102 | rundocBlockClass = rundocPrefix ++ "block" 103 | 104 | -- Options 105 | data RundocOptions = RundocOptions 106 | { rundocLanguage :: Language 107 | , rundocResultType :: RundocResultType 108 | , rundocExports :: RundocExports 109 | , rundocOutfile :: Maybe FilePath 110 | } deriving (Eq, Show) 111 | 112 | instance Default RundocOptions where 113 | def = RundocOptions 114 | { rundocLanguage = UnknownLanguage "" 115 | , rundocResultType = Replace 116 | , rundocExports = [ExportSource] 117 | , rundocOutfile = Nothing 118 | } 119 | 120 | optionsToMetropolisParameters :: RundocOptions -> MetropolisParameter 121 | optionsToMetropolisParameters opts = 122 | MetropolisParameter 123 | { parameterVariables = [] 124 | , parameterOutfile = rundocOutfile opts 125 | , parameterLanguage = rundocLanguage opts 126 | } 127 | 128 | data RundocResultType = Replace 129 | | Silent 130 | deriving (Eq, Show) 131 | 132 | data Export = ExportSource 133 | | ExportOutput 134 | | ExportError 135 | | ExportFile 136 | deriving (Eq, Show) 137 | 138 | type RundocExports = [Export] 139 | 140 | rundocOptions :: [(String, String)] -> RundocOptions 141 | rundocOptions = foldl' parseOption def . map rmPrefix . filter isRundocOption 142 | where rmPrefix (k,v) = (drop (length rundocPrefix) k, v) 143 | 144 | parseOption :: RundocOptions -> (String, String) -> RundocOptions 145 | parseOption opts (key, value) = 146 | case key of 147 | "language" -> opts{ rundocLanguage = parseLanguage value } 148 | "exports" -> opts{ rundocExports = parseExport value } 149 | "results" -> opts{ rundocResultType = parseResult value } 150 | "file" -> opts{ rundocOutfile = Just value } 151 | _ -> opts 152 | 153 | parseLanguage :: String -> Language 154 | parseLanguage lang = 155 | case lang of 156 | "sh" -> Shell 157 | "haskell" -> Haskell 158 | "ditaa" -> Ditaa 159 | "R" -> R 160 | x -> UnknownLanguage x 161 | 162 | parseExport :: String -> RundocExports 163 | parseExport exportType = 164 | case exportType of 165 | "result" -> [ExportOutput] 166 | "output" -> [ExportOutput] 167 | "code" -> [ExportSource] 168 | "both" -> [ExportSource, ExportOutput] 169 | "file" -> [ExportFile] 170 | _ -> [] 171 | 172 | parseResult :: String -> RundocResultType 173 | parseResult "silent" = Silent 174 | parseResult _ = Replace 175 | 176 | setCodeAttr :: Attr -> Inline -> Inline 177 | setCodeAttr attr x = 178 | case x of 179 | Code _ code -> Code attr code 180 | _ -> x 181 | 182 | setBlockCodeAttr :: Attr -> Block -> Block 183 | setBlockCodeAttr attr x = 184 | case x of 185 | CodeBlock _ code -> CodeBlock attr code 186 | _ -> x 187 | 188 | stripRundocAttrs :: Attr -> Attr 189 | stripRundocAttrs = bimap (filter (/= rundocBlockClass)) 190 | (filter (not . isRundocOption)) 191 | 192 | evalCode :: RundocOptions 193 | -> String 194 | -> IO MetropolisResult 195 | evalCode opts = runCode (optionsToMetropolisParameters opts) 196 | 197 | resultToInlines :: RundocOptions -> MetropolisResult -> Inlines 198 | resultToInlines opts res = 199 | if Silent == rundocResultType opts 200 | then mempty 201 | else mconcat . map (`exporter` res) $ rundocExports opts 202 | 203 | singularizeInlines :: Inlines -> Inline 204 | singularizeInlines inlines = 205 | case B.toList inlines of 206 | [] -> Space 207 | (x:[]) -> x 208 | xs -> Span nullAttr xs 209 | 210 | inlinesToBlocks :: Inlines -> Blocks 211 | inlinesToBlocks = fmap inlineToBlock 212 | 213 | inlineToBlock :: Inline -> Block 214 | inlineToBlock = Para . (:[]) 215 | 216 | singularizeBlocks :: Blocks -> Block 217 | singularizeBlocks blocks = 218 | case B.toList blocks of 219 | [] -> Null 220 | (x:[]) -> x 221 | xs -> Div nullAttr xs 222 | 223 | exporter :: Export -> MetropolisResult -> Inlines 224 | exporter e = 225 | case e of 226 | ExportSource -> exportSource 227 | ExportOutput -> exportOutput 228 | ExportFile -> exportFile 229 | _ -> error "Not implemented yet" 230 | 231 | exportOutput :: MetropolisResult -> Inlines 232 | exportOutput = B.codeWith nullAttr . resultOutput 233 | 234 | exportSource :: MetropolisResult -> Inlines 235 | exportSource = B.codeWith nullAttr . resultSource 236 | 237 | exportFile :: MetropolisResult -> Inlines 238 | exportFile = (\url -> B.image url "" mempty) . fromMaybe "" . resultFile 239 | -------------------------------------------------------------------------------- /tests/Metropolis/Worker/Tests.hs: -------------------------------------------------------------------------------- 1 | {- 2 | Copyright (C) 2014 Albert Krewinkel 3 | 4 | This program is free software: you can redistribute it and/or modify it 5 | under the terms of the GNU Affero General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or (at your 7 | option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public 12 | License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see . 16 | -} 17 | 18 | module Metropolis.Worker.Tests ( tests ) where 19 | 20 | import Test.Tasty 21 | import Test.Tasty.HUnit 22 | 23 | import Metropolis.Types 24 | import Metropolis.Worker 25 | 26 | tests :: TestTree 27 | tests = testGroup "Worker Tests" [ shellWorkerTests ] 28 | 29 | shellWorkerTests :: TestTree 30 | shellWorkerTests = testGroup "Shell Worker" 31 | [ testCase "Basic Shell output" $ 32 | let res = emptyResult{ resultOutput = "Hello" 33 | , resultSource = "printf Hello" 34 | } 35 | in fmap (== res) (runCode def{ parameterLanguage = Shell } "printf Hello") 36 | @? "wrong printf result" 37 | 38 | , testCase "Haskell interpreter" $ 39 | let ref = emptyResult{ resultOutput = "42\n" 40 | , resultSource = "print (42::Int)" 41 | } 42 | res = runCode def{ parameterLanguage = Haskell } "print (42::Int)" 43 | resetErr r = r{ resultError = "" } 44 | in fmap (== ref) (fmap resetErr res) 45 | @? "Haskell results differ" 46 | 47 | , testCase "Run unknown language" $ 48 | let (lang, code) = (UnknownLanguage "unknown", "foo") 49 | in fmap (== cannotRunLanguageResult code) 50 | (runCode def{ parameterLanguage = lang } code) 51 | @? "wrong fallback" 52 | ] 53 | -------------------------------------------------------------------------------- /tests/rundoc-tests.hs: -------------------------------------------------------------------------------- 1 | {- 2 | Copyright (C) 2014 Albert Krewinkel 3 | 4 | This program is free software: you can redistribute it and/or modify it 5 | under the terms of the GNU Affero General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or (at your 7 | option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public 12 | License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see . 16 | -} 17 | 18 | -- | Tests for Rundoc and Metropolis 19 | module Main where 20 | 21 | import Test.Tasty 22 | 23 | import qualified Metropolis.Worker.Tests as MW 24 | 25 | main :: IO () 26 | main = defaultMain tests 27 | 28 | tests :: TestTree 29 | tests = testGroup "Metropolis" 30 | [ MW.tests ] 31 | -------------------------------------------------------------------------------- /utils/RundocFilter.hs: -------------------------------------------------------------------------------- 1 | {- 2 | Copyright (C) 2014 Albert Krewinkel 3 | 4 | This program is free software: you can redistribute it and/or modify it 5 | under the terms of the GNU Affero General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or (at your 7 | option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, but 10 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public 12 | License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see . 16 | -} 17 | 18 | {- | 19 | Copyright : Copyright © 2014 Albert Krewinkel 20 | License : GNU AGPL, version 3 or above 21 | 22 | Eval code in Pandoc code blocks and re-insert the results. 23 | -} 24 | module Main where 25 | 26 | import Text.Rundoc (rundoc) 27 | import Text.Pandoc.JSON (toJSONFilter) 28 | 29 | main :: IO () 30 | main = toJSONFilter rundoc 31 | --------------------------------------------------------------------------------