Commit deb20fdfca
Unsigned
Layout: unified · split
.gitignore added +2
| @@ -0,0 +1,2 @@ | ||
| 1 | .DS_Store | |
| 2 | .idea/ | |
| \ No newline at end of file | ||
LICENSE added +674
| @@ -0,0 +1,674 @@ | ||
| 1 | GNU GENERAL PUBLIC LICENSE | |
| 2 | Version 3, 29 June 2007 | |
| 3 | ||
| 4 | Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> | |
| 5 | Everyone is permitted to copy and distribute verbatim copies | |
| 6 | of this license document, but changing it is not allowed. | |
| 7 | ||
| 8 | Preamble | |
| 9 | ||
| 10 | The GNU General Public License is a free, copyleft license for | |
| 11 | software and other kinds of works. | |
| 12 | ||
| 13 | The licenses for most software and other practical works are designed | |
| 14 | to take away your freedom to share and change the works. By contrast, | |
| 15 | the GNU General Public License is intended to guarantee your freedom to | |
| 16 | share and change all versions of a program--to make sure it remains free | |
| 17 | software for all its users. We, the Free Software Foundation, use the | |
| 18 | GNU General Public License for most of our software; it applies also to | |
| 19 | any other work released this way by its authors. You can apply it to | |
| 20 | your programs, too. | |
| 21 | ||
| 22 | When we speak of free software, we are referring to freedom, not | |
| 23 | price. Our General Public Licenses are designed to make sure that you | |
| 24 | have the freedom to distribute copies of free software (and charge for | |
| 25 | them if you wish), that you receive source code or can get it if you | |
| 26 | want it, that you can change the software or use pieces of it in new | |
| 27 | free programs, and that you know you can do these things. | |
| 28 | ||
| 29 | To protect your rights, we need to prevent others from denying you | |
| 30 | these rights or asking you to surrender the rights. Therefore, you have | |
| 31 | certain responsibilities if you distribute copies of the software, or if | |
| 32 | you modify it: responsibilities to respect the freedom of others. | |
| 33 | ||
| 34 | For example, if you distribute copies of such a program, whether | |
| 35 | gratis or for a fee, you must pass on to the recipients the same | |
| 36 | freedoms that you received. You must make sure that they, too, receive | |
| 37 | or can get the source code. And you must show them these terms so they | |
| 38 | know their rights. | |
| 39 | ||
| 40 | Developers that use the GNU GPL protect your rights with two steps: | |
| 41 | (1) assert copyright on the software, and (2) offer you this License | |
| 42 | giving you legal permission to copy, distribute and/or modify it. | |
| 43 | ||
| 44 | For the developers' and authors' protection, the GPL clearly explains | |
| 45 | that there is no warranty for this free software. For both users' and | |
| 46 | authors' sake, the GPL requires that modified versions be marked as | |
| 47 | changed, so that their problems will not be attributed erroneously to | |
| 48 | authors of previous versions. | |
| 49 | ||
| 50 | Some devices are designed to deny users access to install or run | |
| 51 | modified versions of the software inside them, although the manufacturer | |
| 52 | can do so. This is fundamentally incompatible with the aim of | |
| 53 | protecting users' freedom to change the software. The systematic | |
| 54 | pattern of such abuse occurs in the area of products for individuals to | |
| 55 | use, which is precisely where it is most unacceptable. Therefore, we | |
| 56 | have designed this version of the GPL to prohibit the practice for those | |
| 57 | products. If such problems arise substantially in other domains, we | |
| 58 | stand ready to extend this provision to those domains in future versions | |
| 59 | of the GPL, as needed to protect the freedom of users. | |
| 60 | ||
| 61 | Finally, every program is threatened constantly by software patents. | |
| 62 | States should not allow patents to restrict development and use of | |
| 63 | software on general-purpose computers, but in those that do, we wish to | |
| 64 | avoid the special danger that patents applied to a free program could | |
| 65 | make it effectively proprietary. To prevent this, the GPL assures that | |
| 66 | patents cannot be used to render the program non-free. | |
| 67 | ||
| 68 | The precise terms and conditions for copying, distribution and | |
| 69 | modification follow. | |
| 70 | ||
| 71 | TERMS AND CONDITIONS | |
| 72 | ||
| 73 | 0. Definitions. | |
| 74 | ||
| 75 | "This License" refers to version 3 of the GNU General Public License. | |
| 76 | ||
| 77 | "Copyright" also means copyright-like laws that apply to other kinds of | |
| 78 | works, such as semiconductor masks. | |
| 79 | ||
| 80 | "The Program" refers to any copyrightable work licensed under this | |
| 81 | License. Each licensee is addressed as "you". "Licensees" and | |
| 82 | "recipients" may be individuals or organizations. | |
| 83 | ||
| 84 | To "modify" a work means to copy from or adapt all or part of the work | |
| 85 | in a fashion requiring copyright permission, other than the making of an | |
| 86 | exact copy. The resulting work is called a "modified version" of the | |
| 87 | earlier work or a work "based on" the earlier work. | |
| 88 | ||
| 89 | A "covered work" means either the unmodified Program or a work based | |
| 90 | on the Program. | |
| 91 | ||
| 92 | To "propagate" a work means to do anything with it that, without | |
| 93 | permission, would make you directly or secondarily liable for | |
| 94 | infringement under applicable copyright law, except executing it on a | |
| 95 | computer or modifying a private copy. Propagation includes copying, | |
| 96 | distribution (with or without modification), making available to the | |
| 97 | public, and in some countries other activities as well. | |
| 98 | ||
| 99 | To "convey" a work means any kind of propagation that enables other | |
| 100 | parties to make or receive copies. Mere interaction with a user through | |
| 101 | a computer network, with no transfer of a copy, is not conveying. | |
| 102 | ||
| 103 | An interactive user interface displays "Appropriate Legal Notices" | |
| 104 | to the extent that it includes a convenient and prominently visible | |
| 105 | feature that (1) displays an appropriate copyright notice, and (2) | |
| 106 | tells the user that there is no warranty for the work (except to the | |
| 107 | extent that warranties are provided), that licensees may convey the | |
| 108 | work under this License, and how to view a copy of this License. If | |
| 109 | the interface presents a list of user commands or options, such as a | |
| 110 | menu, a prominent item in the list meets this criterion. | |
| 111 | ||
| 112 | 1. Source Code. | |
| 113 | ||
| 114 | The "source code" for a work means the preferred form of the work | |
| 115 | for making modifications to it. "Object code" means any non-source | |
| 116 | form of a work. | |
| 117 | ||
| 118 | A "Standard Interface" means an interface that either is an official | |
| 119 | standard defined by a recognized standards body, or, in the case of | |
| 120 | interfaces specified for a particular programming language, one that | |
| 121 | is widely used among developers working in that language. | |
| 122 | ||
| 123 | The "System Libraries" of an executable work include anything, other | |
| 124 | than the work as a whole, that (a) is included in the normal form of | |
| 125 | packaging a Major Component, but which is not part of that Major | |
| 126 | Component, and (b) serves only to enable use of the work with that | |
| 127 | Major Component, or to implement a Standard Interface for which an | |
| 128 | implementation is available to the public in source code form. A | |
| 129 | "Major Component", in this context, means a major essential component | |
| 130 | (kernel, window system, and so on) of the specific operating system | |
| 131 | (if any) on which the executable work runs, or a compiler used to | |
| 132 | produce the work, or an object code interpreter used to run it. | |
| 133 | ||
| 134 | The "Corresponding Source" for a work in object code form means all | |
| 135 | the source code needed to generate, install, and (for an executable | |
| 136 | work) run the object code and to modify the work, including scripts to | |
| 137 | control those activities. However, it does not include the work's | |
| 138 | System Libraries, or general-purpose tools or generally available free | |
| 139 | programs which are used unmodified in performing those activities but | |
| 140 | which are not part of the work. For example, Corresponding Source | |
| 141 | includes interface definition files associated with source files for | |
| 142 | the work, and the source code for shared libraries and dynamically | |
| 143 | linked subprograms that the work is specifically designed to require, | |
| 144 | such as by intimate data communication or control flow between those | |
| 145 | subprograms and other parts of the work. | |
| 146 | ||
| 147 | The Corresponding Source need not include anything that users | |
| 148 | can regenerate automatically from other parts of the Corresponding | |
| 149 | Source. | |
| 150 | ||
| 151 | The Corresponding Source for a work in source code form is that | |
| 152 | same work. | |
| 153 | ||
| 154 | 2. Basic Permissions. | |
| 155 | ||
| 156 | All rights granted under this License are granted for the term of | |
| 157 | copyright on the Program, and are irrevocable provided the stated | |
| 158 | conditions are met. This License explicitly affirms your unlimited | |
| 159 | permission to run the unmodified Program. The output from running a | |
| 160 | covered work is covered by this License only if the output, given its | |
| 161 | content, constitutes a covered work. This License acknowledges your | |
| 162 | rights of fair use or other equivalent, as provided by copyright law. | |
| 163 | ||
| 164 | You may make, run and propagate covered works that you do not | |
| 165 | convey, without conditions so long as your license otherwise remains | |
| 166 | in force. You may convey covered works to others for the sole purpose | |
| 167 | of having them make modifications exclusively for you, or provide you | |
| 168 | with facilities for running those works, provided that you comply with | |
| 169 | the terms of this License in conveying all material for which you do | |
| 170 | not control copyright. Those thus making or running the covered works | |
| 171 | for you must do so exclusively on your behalf, under your direction | |
| 172 | and control, on terms that prohibit them from making any copies of | |
| 173 | your copyrighted material outside their relationship with you. | |
| 174 | ||
| 175 | Conveying under any other circumstances is permitted solely under | |
| 176 | the conditions stated below. Sublicensing is not allowed; section 10 | |
| 177 | makes it unnecessary. | |
| 178 | ||
| 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. | |
| 180 | ||
| 181 | No covered work shall be deemed part of an effective technological | |
| 182 | measure under any applicable law fulfilling obligations under article | |
| 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or | |
| 184 | similar laws prohibiting or restricting circumvention of such | |
| 185 | measures. | |
| 186 | ||
| 187 | When you convey a covered work, you waive any legal power to forbid | |
| 188 | circumvention of technological measures to the extent such circumvention | |
| 189 | is effected by exercising rights under this License with respect to | |
| 190 | the covered work, and you disclaim any intention to limit operation or | |
| 191 | modification of the work as a means of enforcing, against the work's | |
| 192 | users, your or third parties' legal rights to forbid circumvention of | |
| 193 | technological measures. | |
| 194 | ||
| 195 | 4. Conveying Verbatim Copies. | |
| 196 | ||
| 197 | You may convey verbatim copies of the Program's source code as you | |
| 198 | receive it, in any medium, provided that you conspicuously and | |
| 199 | appropriately publish on each copy an appropriate copyright notice; | |
| 200 | keep intact all notices stating that this License and any | |
| 201 | non-permissive terms added in accord with section 7 apply to the code; | |
| 202 | keep intact all notices of the absence of any warranty; and give all | |
| 203 | recipients a copy of this License along with the Program. | |
| 204 | ||
| 205 | You may charge any price or no price for each copy that you convey, | |
| 206 | and you may offer support or warranty protection for a fee. | |
| 207 | ||
| 208 | 5. Conveying Modified Source Versions. | |
| 209 | ||
| 210 | You may convey a work based on the Program, or the modifications to | |
| 211 | produce it from the Program, in the form of source code under the | |
| 212 | terms of section 4, provided that you also meet all of these conditions: | |
| 213 | ||
| 214 | a) The work must carry prominent notices stating that you modified | |
| 215 | it, and giving a relevant date. | |
| 216 | ||
| 217 | b) The work must carry prominent notices stating that it is | |
| 218 | released under this License and any conditions added under section | |
| 219 | 7. This requirement modifies the requirement in section 4 to | |
| 220 | "keep intact all notices". | |
| 221 | ||
| 222 | c) You must license the entire work, as a whole, under this | |
| 223 | License to anyone who comes into possession of a copy. This | |
| 224 | License will therefore apply, along with any applicable section 7 | |
| 225 | additional terms, to the whole of the work, and all its parts, | |
| 226 | regardless of how they are packaged. This License gives no | |
| 227 | permission to license the work in any other way, but it does not | |
| 228 | invalidate such permission if you have separately received it. | |
| 229 | ||
| 230 | d) If the work has interactive user interfaces, each must display | |
| 231 | Appropriate Legal Notices; however, if the Program has interactive | |
| 232 | interfaces that do not display Appropriate Legal Notices, your | |
| 233 | work need not make them do so. | |
| 234 | ||
| 235 | A compilation of a covered work with other separate and independent | |
| 236 | works, which are not by their nature extensions of the covered work, | |
| 237 | and which are not combined with it such as to form a larger program, | |
| 238 | in or on a volume of a storage or distribution medium, is called an | |
| 239 | "aggregate" if the compilation and its resulting copyright are not | |
| 240 | used to limit the access or legal rights of the compilation's users | |
| 241 | beyond what the individual works permit. Inclusion of a covered work | |
| 242 | in an aggregate does not cause this License to apply to the other | |
| 243 | parts of the aggregate. | |
| 244 | ||
| 245 | 6. Conveying Non-Source Forms. | |
| 246 | ||
| 247 | You may convey a covered work in object code form under the terms | |
| 248 | of sections 4 and 5, provided that you also convey the | |
| 249 | machine-readable Corresponding Source under the terms of this License, | |
| 250 | in one of these ways: | |
| 251 | ||
| 252 | a) Convey the object code in, or embodied in, a physical product | |
| 253 | (including a physical distribution medium), accompanied by the | |
| 254 | Corresponding Source fixed on a durable physical medium | |
| 255 | customarily used for software interchange. | |
| 256 | ||
| 257 | b) Convey the object code in, or embodied in, a physical product | |
| 258 | (including a physical distribution medium), accompanied by a | |
| 259 | written offer, valid for at least three years and valid for as | |
| 260 | long as you offer spare parts or customer support for that product | |
| 261 | model, to give anyone who possesses the object code either (1) a | |
| 262 | copy of the Corresponding Source for all the software in the | |
| 263 | product that is covered by this License, on a durable physical | |
| 264 | medium customarily used for software interchange, for a price no | |
| 265 | more than your reasonable cost of physically performing this | |
| 266 | conveying of source, or (2) access to copy the | |
| 267 | Corresponding Source from a network server at no charge. | |
| 268 | ||
| 269 | c) Convey individual copies of the object code with a copy of the | |
| 270 | written offer to provide the Corresponding Source. This | |
| 271 | alternative is allowed only occasionally and noncommercially, and | |
| 272 | only if you received the object code with such an offer, in accord | |
| 273 | with subsection 6b. | |
| 274 | ||
| 275 | d) Convey the object code by offering access from a designated | |
| 276 | place (gratis or for a charge), and offer equivalent access to the | |
| 277 | Corresponding Source in the same way through the same place at no | |
| 278 | further charge. You need not require recipients to copy the | |
| 279 | Corresponding Source along with the object code. If the place to | |
| 280 | copy the object code is a network server, the Corresponding Source | |
| 281 | may be on a different server (operated by you or a third party) | |
| 282 | that supports equivalent copying facilities, provided you maintain | |
| 283 | clear directions next to the object code saying where to find the | |
| 284 | Corresponding Source. Regardless of what server hosts the | |
| 285 | Corresponding Source, you remain obligated to ensure that it is | |
| 286 | available for as long as needed to satisfy these requirements. | |
| 287 | ||
| 288 | e) Convey the object code using peer-to-peer transmission, provided | |
| 289 | you inform other peers where the object code and Corresponding | |
| 290 | Source of the work are being offered to the general public at no | |
| 291 | charge under subsection 6d. | |
| 292 | ||
| 293 | A separable portion of the object code, whose source code is excluded | |
| 294 | from the Corresponding Source as a System Library, need not be | |
| 295 | included in conveying the object code work. | |
| 296 | ||
| 297 | A "User Product" is either (1) a "consumer product", which means any | |
| 298 | tangible personal property which is normally used for personal, family, | |
| 299 | or household purposes, or (2) anything designed or sold for incorporation | |
| 300 | into a dwelling. In determining whether a product is a consumer product, | |
| 301 | doubtful cases shall be resolved in favor of coverage. For a particular | |
| 302 | product received by a particular user, "normally used" refers to a | |
| 303 | typical or common use of that class of product, regardless of the status | |
| 304 | of the particular user or of the way in which the particular user | |
| 305 | actually uses, or expects or is expected to use, the product. A product | |
| 306 | is a consumer product regardless of whether the product has substantial | |
| 307 | commercial, industrial or non-consumer uses, unless such uses represent | |
| 308 | the only significant mode of use of the product. | |
| 309 | ||
| 310 | "Installation Information" for a User Product means any methods, | |
| 311 | procedures, authorization keys, or other information required to install | |
| 312 | and execute modified versions of a covered work in that User Product from | |
| 313 | a modified version of its Corresponding Source. The information must | |
| 314 | suffice to ensure that the continued functioning of the modified object | |
| 315 | code is in no case prevented or interfered with solely because | |
| 316 | modification has been made. | |
| 317 | ||
| 318 | If you convey an object code work under this section in, or with, or | |
| 319 | specifically for use in, a User Product, and the conveying occurs as | |
| 320 | part of a transaction in which the right of possession and use of the | |
| 321 | User Product is transferred to the recipient in perpetuity or for a | |
| 322 | fixed term (regardless of how the transaction is characterized), the | |
| 323 | Corresponding Source conveyed under this section must be accompanied | |
| 324 | by the Installation Information. But this requirement does not apply | |
| 325 | if neither you nor any third party retains the ability to install | |
| 326 | modified object code on the User Product (for example, the work has | |
| 327 | been installed in ROM). | |
| 328 | ||
| 329 | The requirement to provide Installation Information does not include a | |
| 330 | requirement to continue to provide support service, warranty, or updates | |
| 331 | for a work that has been modified or installed by the recipient, or for | |
| 332 | the User Product in which it has been modified or installed. Access to a | |
| 333 | network may be denied when the modification itself materially and | |
| 334 | adversely affects the operation of the network or violates the rules and | |
| 335 | protocols for communication across the network. | |
| 336 | ||
| 337 | Corresponding Source conveyed, and Installation Information provided, | |
| 338 | in accord with this section must be in a format that is publicly | |
| 339 | documented (and with an implementation available to the public in | |
| 340 | source code form), and must require no special password or key for | |
| 341 | unpacking, reading or copying. | |
| 342 | ||
| 343 | 7. Additional Terms. | |
| 344 | ||
| 345 | "Additional permissions" are terms that supplement the terms of this | |
| 346 | License by making exceptions from one or more of its conditions. | |
| 347 | Additional permissions that are applicable to the entire Program shall | |
| 348 | be treated as though they were included in this License, to the extent | |
| 349 | that they are valid under applicable law. If additional permissions | |
| 350 | apply only to part of the Program, that part may be used separately | |
| 351 | under those permissions, but the entire Program remains governed by | |
| 352 | this License without regard to the additional permissions. | |
| 353 | ||
| 354 | When you convey a copy of a covered work, you may at your option | |
| 355 | remove any additional permissions from that copy, or from any part of | |
| 356 | it. (Additional permissions may be written to require their own | |
| 357 | removal in certain cases when you modify the work.) You may place | |
| 358 | additional permissions on material, added by you to a covered work, | |
| 359 | for which you have or can give appropriate copyright permission. | |
| 360 | ||
| 361 | Notwithstanding any other provision of this License, for material you | |
| 362 | add to a covered work, you may (if authorized by the copyright holders of | |
| 363 | that material) supplement the terms of this License with terms: | |
| 364 | ||
| 365 | a) Disclaiming warranty or limiting liability differently from the | |
| 366 | terms of sections 15 and 16 of this License; or | |
| 367 | ||
| 368 | b) Requiring preservation of specified reasonable legal notices or | |
| 369 | author attributions in that material or in the Appropriate Legal | |
| 370 | Notices displayed by works containing it; or | |
| 371 | ||
| 372 | c) Prohibiting misrepresentation of the origin of that material, or | |
| 373 | requiring that modified versions of such material be marked in | |
| 374 | reasonable ways as different from the original version; or | |
| 375 | ||
| 376 | d) Limiting the use for publicity purposes of names of licensors or | |
| 377 | authors of the material; or | |
| 378 | ||
| 379 | e) Declining to grant rights under trademark law for use of some | |
| 380 | trade names, trademarks, or service marks; or | |
| 381 | ||
| 382 | f) Requiring indemnification of licensors and authors of that | |
| 383 | material by anyone who conveys the material (or modified versions of | |
| 384 | it) with contractual assumptions of liability to the recipient, for | |
| 385 | any liability that these contractual assumptions directly impose on | |
| 386 | those licensors and authors. | |
| 387 | ||
| 388 | All other non-permissive additional terms are considered "further | |
| 389 | restrictions" within the meaning of section 10. If the Program as you | |
| 390 | received it, or any part of it, contains a notice stating that it is | |
| 391 | governed by this License along with a term that is a further | |
| 392 | restriction, you may remove that term. If a license document contains | |
| 393 | a further restriction but permits relicensing or conveying under this | |
| 394 | License, you may add to a covered work material governed by the terms | |
| 395 | of that license document, provided that the further restriction does | |
| 396 | not survive such relicensing or conveying. | |
| 397 | ||
| 398 | If you add terms to a covered work in accord with this section, you | |
| 399 | must place, in the relevant source files, a statement of the | |
| 400 | additional terms that apply to those files, or a notice indicating | |
| 401 | where to find the applicable terms. | |
| 402 | ||
| 403 | Additional terms, permissive or non-permissive, may be stated in the | |
| 404 | form of a separately written license, or stated as exceptions; | |
| 405 | the above requirements apply either way. | |
| 406 | ||
| 407 | 8. Termination. | |
| 408 | ||
| 409 | You may not propagate or modify a covered work except as expressly | |
| 410 | provided under this License. Any attempt otherwise to propagate or | |
| 411 | modify it is void, and will automatically terminate your rights under | |
| 412 | this License (including any patent licenses granted under the third | |
| 413 | paragraph of section 11). | |
| 414 | ||
| 415 | However, if you cease all violation of this License, then your | |
| 416 | license from a particular copyright holder is reinstated (a) | |
| 417 | provisionally, unless and until the copyright holder explicitly and | |
| 418 | finally terminates your license, and (b) permanently, if the copyright | |
| 419 | holder fails to notify you of the violation by some reasonable means | |
| 420 | prior to 60 days after the cessation. | |
| 421 | ||
| 422 | Moreover, your license from a particular copyright holder is | |
| 423 | reinstated permanently if the copyright holder notifies you of the | |
| 424 | violation by some reasonable means, this is the first time you have | |
| 425 | received notice of violation of this License (for any work) from that | |
| 426 | copyright holder, and you cure the violation prior to 30 days after | |
| 427 | your receipt of the notice. | |
| 428 | ||
| 429 | Termination of your rights under this section does not terminate the | |
| 430 | licenses of parties who have received copies or rights from you under | |
| 431 | this License. If your rights have been terminated and not permanently | |
| 432 | reinstated, you do not qualify to receive new licenses for the same | |
| 433 | material under section 10. | |
| 434 | ||
| 435 | 9. Acceptance Not Required for Having Copies. | |
| 436 | ||
| 437 | You are not required to accept this License in order to receive or | |
| 438 | run a copy of the Program. Ancillary propagation of a covered work | |
| 439 | occurring solely as a consequence of using peer-to-peer transmission | |
| 440 | to receive a copy likewise does not require acceptance. However, | |
| 441 | nothing other than this License grants you permission to propagate or | |
| 442 | modify any covered work. These actions infringe copyright if you do | |
| 443 | not accept this License. Therefore, by modifying or propagating a | |
| 444 | covered work, you indicate your acceptance of this License to do so. | |
| 445 | ||
| 446 | 10. Automatic Licensing of Downstream Recipients. | |
| 447 | ||
| 448 | Each time you convey a covered work, the recipient automatically | |
| 449 | receives a license from the original licensors, to run, modify and | |
| 450 | propagate that work, subject to this License. You are not responsible | |
| 451 | for enforcing compliance by third parties with this License. | |
| 452 | ||
| 453 | An "entity transaction" is a transaction transferring control of an | |
| 454 | organization, or substantially all assets of one, or subdividing an | |
| 455 | organization, or merging organizations. If propagation of a covered | |
| 456 | work results from an entity transaction, each party to that | |
| 457 | transaction who receives a copy of the work also receives whatever | |
| 458 | licenses to the work the party's predecessor in interest had or could | |
| 459 | give under the previous paragraph, plus a right to possession of the | |
| 460 | Corresponding Source of the work from the predecessor in interest, if | |
| 461 | the predecessor has it or can get it with reasonable efforts. | |
| 462 | ||
| 463 | You may not impose any further restrictions on the exercise of the | |
| 464 | rights granted or affirmed under this License. For example, you may | |
| 465 | not impose a license fee, royalty, or other charge for exercise of | |
| 466 | rights granted under this License, and you may not initiate litigation | |
| 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that | |
| 468 | any patent claim is infringed by making, using, selling, offering for | |
| 469 | sale, or importing the Program or any portion of it. | |
| 470 | ||
| 471 | 11. Patents. | |
| 472 | ||
| 473 | A "contributor" is a copyright holder who authorizes use under this | |
| 474 | License of the Program or a work on which the Program is based. The | |
| 475 | work thus licensed is called the contributor's "contributor version". | |
| 476 | ||
| 477 | A contributor's "essential patent claims" are all patent claims | |
| 478 | owned or controlled by the contributor, whether already acquired or | |
| 479 | hereafter acquired, that would be infringed by some manner, permitted | |
| 480 | by this License, of making, using, or selling its contributor version, | |
| 481 | but do not include claims that would be infringed only as a | |
| 482 | consequence of further modification of the contributor version. For | |
| 483 | purposes of this definition, "control" includes the right to grant | |
| 484 | patent sublicenses in a manner consistent with the requirements of | |
| 485 | this License. | |
| 486 | ||
| 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free | |
| 488 | patent license under the contributor's essential patent claims, to | |
| 489 | make, use, sell, offer for sale, import and otherwise run, modify and | |
| 490 | propagate the contents of its contributor version. | |
| 491 | ||
| 492 | In the following three paragraphs, a "patent license" is any express | |
| 493 | agreement or commitment, however denominated, not to enforce a patent | |
| 494 | (such as an express permission to practice a patent or covenant not to | |
| 495 | sue for patent infringement). To "grant" such a patent license to a | |
| 496 | party means to make such an agreement or commitment not to enforce a | |
| 497 | patent against the party. | |
| 498 | ||
| 499 | If you convey a covered work, knowingly relying on a patent license, | |
| 500 | and the Corresponding Source of the work is not available for anyone | |
| 501 | to copy, free of charge and under the terms of this License, through a | |
| 502 | publicly available network server or other readily accessible means, | |
| 503 | then you must either (1) cause the Corresponding Source to be so | |
| 504 | available, or (2) arrange to deprive yourself of the benefit of the | |
| 505 | patent license for this particular work, or (3) arrange, in a manner | |
| 506 | consistent with the requirements of this License, to extend the patent | |
| 507 | license to downstream recipients. "Knowingly relying" means you have | |
| 508 | actual knowledge that, but for the patent license, your conveying the | |
| 509 | covered work in a country, or your recipient's use of the covered work | |
| 510 | in a country, would infringe one or more identifiable patents in that | |
| 511 | country that you have reason to believe are valid. | |
| 512 | ||
| 513 | If, pursuant to or in connection with a single transaction or | |
| 514 | arrangement, you convey, or propagate by procuring conveyance of, a | |
| 515 | covered work, and grant a patent license to some of the parties | |
| 516 | receiving the covered work authorizing them to use, propagate, modify | |
| 517 | or convey a specific copy of the covered work, then the patent license | |
| 518 | you grant is automatically extended to all recipients of the covered | |
| 519 | work and works based on it. | |
| 520 | ||
| 521 | A patent license is "discriminatory" if it does not include within | |
| 522 | the scope of its coverage, prohibits the exercise of, or is | |
| 523 | conditioned on the non-exercise of one or more of the rights that are | |
| 524 | specifically granted under this License. You may not convey a covered | |
| 525 | work if you are a party to an arrangement with a third party that is | |
| 526 | in the business of distributing software, under which you make payment | |
| 527 | to the third party based on the extent of your activity of conveying | |
| 528 | the work, and under which the third party grants, to any of the | |
| 529 | parties who would receive the covered work from you, a discriminatory | |
| 530 | patent license (a) in connection with copies of the covered work | |
| 531 | conveyed by you (or copies made from those copies), or (b) primarily | |
| 532 | for and in connection with specific products or compilations that | |
| 533 | contain the covered work, unless you entered into that arrangement, | |
| 534 | or that patent license was granted, prior to 28 March 2007. | |
| 535 | ||
| 536 | Nothing in this License shall be construed as excluding or limiting | |
| 537 | any implied license or other defenses to infringement that may | |
| 538 | otherwise be available to you under applicable patent law. | |
| 539 | ||
| 540 | 12. No Surrender of Others' Freedom. | |
| 541 | ||
| 542 | If conditions are imposed on you (whether by court order, agreement or | |
| 543 | otherwise) that contradict the conditions of this License, they do not | |
| 544 | excuse you from the conditions of this License. If you cannot convey a | |
| 545 | covered work so as to satisfy simultaneously your obligations under this | |
| 546 | License and any other pertinent obligations, then as a consequence you may | |
| 547 | not convey it at all. For example, if you agree to terms that obligate you | |
| 548 | to collect a royalty for further conveying from those to whom you convey | |
| 549 | the Program, the only way you could satisfy both those terms and this | |
| 550 | License would be to refrain entirely from conveying the Program. | |
| 551 | ||
| 552 | 13. Use with the GNU Affero General Public License. | |
| 553 | ||
| 554 | Notwithstanding any other provision of this License, you have | |
| 555 | permission to link or combine any covered work with a work licensed | |
| 556 | under version 3 of the GNU Affero General Public License into a single | |
| 557 | combined work, and to convey the resulting work. The terms of this | |
| 558 | License will continue to apply to the part which is the covered work, | |
| 559 | but the special requirements of the GNU Affero General Public License, | |
| 560 | section 13, concerning interaction through a network will apply to the | |
| 561 | combination as such. | |
| 562 | ||
| 563 | 14. Revised Versions of this License. | |
| 564 | ||
| 565 | The Free Software Foundation may publish revised and/or new versions of | |
| 566 | the GNU General Public License from time to time. Such new versions will | |
| 567 | be similar in spirit to the present version, but may differ in detail to | |
| 568 | address new problems or concerns. | |
| 569 | ||
| 570 | Each version is given a distinguishing version number. If the | |
| 571 | Program specifies that a certain numbered version of the GNU General | |
| 572 | Public License "or any later version" applies to it, you have the | |
| 573 | option of following the terms and conditions either of that numbered | |
| 574 | version or of any later version published by the Free Software | |
| 575 | Foundation. If the Program does not specify a version number of the | |
| 576 | GNU General Public License, you may choose any version ever published | |
| 577 | by the Free Software Foundation. | |
| 578 | ||
| 579 | If the Program specifies that a proxy can decide which future | |
| 580 | versions of the GNU General Public License can be used, that proxy's | |
| 581 | public statement of acceptance of a version permanently authorizes you | |
| 582 | to choose that version for the Program. | |
| 583 | ||
| 584 | Later license versions may give you additional or different | |
| 585 | permissions. However, no additional obligations are imposed on any | |
| 586 | author or copyright holder as a result of your choosing to follow a | |
| 587 | later version. | |
| 588 | ||
| 589 | 15. Disclaimer of Warranty. | |
| 590 | ||
| 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY | |
| 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT | |
| 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY | |
| 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, | |
| 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM | |
| 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF | |
| 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | |
| 599 | ||
| 600 | 16. Limitation of Liability. | |
| 601 | ||
| 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | |
| 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS | |
| 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY | |
| 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE | |
| 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF | |
| 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD | |
| 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), | |
| 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF | |
| 610 | SUCH DAMAGES. | |
| 611 | ||
| 612 | 17. Interpretation of Sections 15 and 16. | |
| 613 | ||
| 614 | If the disclaimer of warranty and limitation of liability provided | |
| 615 | above cannot be given local legal effect according to their terms, | |
| 616 | reviewing courts shall apply local law that most closely approximates | |
| 617 | an absolute waiver of all civil liability in connection with the | |
| 618 | Program, unless a warranty or assumption of liability accompanies a | |
| 619 | copy of the Program in return for a fee. | |
| 620 | ||
| 621 | END OF TERMS AND CONDITIONS | |
| 622 | ||
| 623 | How to Apply These Terms to Your New Programs | |
| 624 | ||
| 625 | If you develop a new program, and you want it to be of the greatest | |
| 626 | possible use to the public, the best way to achieve this is to make it | |
| 627 | free software which everyone can redistribute and change under these terms. | |
| 628 | ||
| 629 | To do so, attach the following notices to the program. It is safest | |
| 630 | to attach them to the start of each source file to most effectively | |
| 631 | state the exclusion of warranty; and each file should have at least | |
| 632 | the "copyright" line and a pointer to where the full notice is found. | |
| 633 | ||
| 634 | <one line to give the program's name and a brief idea of what it does.> | |
| 635 | Copyright (C) <year> <name of author> | |
| 636 | ||
| 637 | This program is free software: you can redistribute it and/or modify | |
| 638 | it under the terms of the GNU General Public License as published by | |
| 639 | the Free Software Foundation, either version 3 of the License, or | |
| 640 | (at your option) any later version. | |
| 641 | ||
| 642 | This program is distributed in the hope that it will be useful, | |
| 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 645 | GNU General Public License for more details. | |
| 646 | ||
| 647 | You should have received a copy of the GNU General Public License | |
| 648 | along with this program. If not, see <https://www.gnu.org/licenses/>. | |
| 649 | ||
| 650 | Also add information on how to contact you by electronic and paper mail. | |
| 651 | ||
| 652 | If the program does terminal interaction, make it output a short | |
| 653 | notice like this when it starts in an interactive mode: | |
| 654 | ||
| 655 | <program> Copyright (C) <year> <name of author> | |
| 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | |
| 657 | This is free software, and you are welcome to redistribute it | |
| 658 | under certain conditions; type `show c' for details. | |
| 659 | ||
| 660 | The hypothetical commands `show w' and `show c' should show the appropriate | |
| 661 | parts of the General Public License. Of course, your program's commands | |
| 662 | might be different; for a GUI interface, you would use an "about box". | |
| 663 | ||
| 664 | You should also get your employer (if you work as a programmer) or school, | |
| 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. | |
| 666 | For more information on this, and how to apply and follow the GNU GPL, see | |
| 667 | <https://www.gnu.org/licenses/>. | |
| 668 | ||
| 669 | The GNU General Public License does not permit incorporating your program | |
| 670 | into proprietary programs. If your program is a subroutine library, you | |
| 671 | may consider it more useful to permit linking proprietary applications with | |
| 672 | the library. If this is what you want to do, use the GNU Lesser General | |
| 673 | Public License instead of this License. But first, please read | |
| 674 | <https://www.gnu.org/licenses/why-not-lgpl.html>. | |
README.md added +244
| @@ -0,0 +1,244 @@ | ||
| 1 | # PHP-Blog | |
| 2 | ||
| 3 | PHP-Blog is a simple, database-free blogging web app written in PHP, with the | |
| 4 | support of Markdown and JSON. | |
| 5 | ||
| 6 | ## Philosophy | |
| 7 | ||
| 8 | Websites, blogs included, should be able to | |
| 9 | [degrade gracefully over time](https://brandur.org/fragments/graceful-degradation-time). | |
| 10 | For blogs, this means open-sourcing your blog and publishing articles and | |
| 11 | metadata straight to the Git repository. | |
| 12 | ||
| 13 | This project allows you to blog and keep your articles, article metadata, and | |
| 14 | user comments within this repo. This is done through the use of JSON files to | |
| 15 | store article metadata and user comments (instead of using a database), and the | |
| 16 | use of Markdown files to store written articles. | |
| 17 | ||
| 18 | ## Installation | |
| 19 | ||
| 20 | Steps: | |
| 21 | ||
| 22 | ```bash | |
| 23 | cd yourBlog.com | |
| 24 | ``` | |
| 25 | ||
| 26 | ```bash | |
| 27 | git clone <REPO_URL> | |
| 28 | ``` | |
| 29 | ||
| 30 | Change the global variables at the top of the `index.php` script: | |
| 31 | ||
| 32 | ```php | |
| 33 | $websiteProtocol = 'https://'; | |
| 34 | $shortDomain = 'yourBlog.com'; | |
| 35 | ``` | |
| 36 | ||
| 37 | Remove my personal data files: | |
| 38 | ||
| 39 | ```bash | |
| 40 | cd _data/ && rm -rf * | |
| 41 | ``` | |
| 42 | ||
| 43 | Add blank data files: | |
| 44 | ||
| 45 | ```bash | |
| 46 | touch comments.json && touch metadata.json | |
| 47 | ``` | |
| 48 | ||
| 49 | Remove my personal posts: | |
| 50 | ||
| 51 | ```bash | |
| 52 | cd ../posts/ && rm -rf * | |
| 53 | ``` | |
| 54 | ||
| 55 | Add your first post: | |
| 56 | ||
| 57 | ```bash | |
| 58 | touch 001-your-first-post.md | |
| 59 | ``` | |
| 60 | ||
| 61 | For every post you add, also add the applicable JSON object in | |
| 62 | `_data/metadata.json`. | |
| 63 | ||
| 64 | Finally, enable `FallbackResource` in your Apache `.conf` file or in your | |
| 65 | `.htaccess` file: | |
| 66 | ||
| 67 | ```apacheconf | |
| 68 | FallbackResource /index.php | |
| 69 | ``` | |
| 70 | ||
| 71 | ## Project Structure | |
| 72 | ||
| 73 | This project uses the structure show below. Continue reading for a brief | |
| 74 | description of each file/folder. | |
| 75 | ||
| 76 | ```text | |
| 77 | blog/ | |
| 78 | │─── .gitignore | |
| 79 | │─── favicon.ico | |
| 80 | │─── index.php | |
| 81 | │─── LICENSE | |
| 82 | │─── README.md | |
| 83 | │ | |
| 84 | └─── _classes/ | |
| 85 | │ │─── Comment.php | |
| 86 | │ │─── Parsedown.php | |
| 87 | │ └─── Template.php | |
| 88 | │ | |
| 89 | └─── _data/ | |
| 90 | │ │─── comments.json | |
| 91 | │ └─── metadata.json | |
| 92 | │ | |
| 93 | └─── _functions/ | |
| 94 | │ │─── loadJSON.php | |
| 95 | │ │─── loadRSS.php | |
| 96 | │ │─── parseMarkdown.php | |
| 97 | │ └─── submitComment.php | |
| 98 | │ | |
| 99 | └─── _templates/ | |
| 100 | │ └───template.html | |
| 101 | │ | |
| 102 | └─── posts/ | |
| 103 | │ │─── 001-your-first-post.md | |
| 104 | │ │─── ... | |
| 105 | │ └─── 999-many-posts-later.md | |
| 106 | │ | |
| 107 | └─── static/ | |
| 108 | │─── app.css | |
| 109 | │─── prism.css | |
| 110 | └─── prism.js | |
| 111 | ``` | |
| 112 | ||
| 113 | ### File: `index.php` | |
| 114 | ||
| 115 | This file is the FallbackResource for the entire directory, so non-existent | |
| 116 | folders/files requested by users will be sent to `index.php` for processing. | |
| 117 | This file uses a switch statement to read the request URL and direct the user to | |
| 118 | various functions. | |
| 119 | ||
| 120 | Each function in this file will call various other functions/classes and then | |
| 121 | send the output to the template file. | |
| 122 | ||
| 123 | --- | |
| 124 | ||
| 125 | ### Folder: `_classes` | |
| 126 | ||
| 127 | #### File: `Comment.php` | |
| 128 | ||
| 129 | This class allows for the creation of user comments and provides the | |
| 130 | `saveComment()` function to do so. | |
| 131 | ||
| 132 | #### File: `Parsedown.php` | |
| 133 | ||
| 134 | This class was not created by me, it comes from | |
| 135 | [erusev/parsedown](https://github.com/erusev/parsedown). See his | |
| 136 | [MIT License](https://raw.githubusercontent.com/erusev/parsedown/master/LICENSE.txt) | |
| 137 | for licensing questions on this code. | |
| 138 | ||
| 139 | This class provides numerous capabilities to parse Markdown files and variables | |
| 140 | to HTML. | |
| 141 | ||
| 142 | #### File: `Template.php` | |
| 143 | ||
| 144 | This class allows for the creation of a final HTML page to show the user. The | |
| 145 | `echoTemplate()` function will replace the `{}` templates in the | |
| 146 | `_templates/template.html` file. | |
| 147 | ||
| 148 | --- | |
| 149 | ||
| 150 | ### Folder: `_data` | |
| 151 | ||
| 152 | #### File: `metadata.json` | |
| 153 | ||
| 154 | Your `metadata.json` file will need to contain an object for each post in the | |
| 155 | `post` folder. If you don't add an object for your new blog post, it won't be | |
| 156 | displayed in the browser. The structure will follow this exactly: | |
| 157 | ||
| 158 | ``` | |
| 159 | { | |
| 160 | "id": "001", | |
| 161 | "title": "Title of Post", | |
| 162 | "author": "Your Name", | |
| 163 | "description": "A quick little description for SEO and RSS.", | |
| 164 | "tag": "my-category", | |
| 165 | "created": "2018-12-08 00:00:00", | |
| 166 | "modified": "2018-12-08 00:00:00", | |
| 167 | "link": "https:\/\/www.example.com\/post\/blog-post-name.html", | |
| 168 | "published": "Yes" | |
| 169 | } | |
| 170 | ``` | |
| 171 | ||
| 172 | #### File: `comments.json` | |
| 173 | ||
| 174 | This file is updated server-side as users submit comments on posts. You can | |
| 175 | commit these changes back to your repository by making sure the server-side git | |
| 176 | repo can read & write. Then just create git commits back to your repo from there | |
| 177 | (you can even create periodic cron jobs to do this for you, if you trust it). | |
| 178 | ||
| 179 | You will need to perform the following commands to ensure whatever 'user' is | |
| 180 | writing to the `comments.json` file has the proper permissions. For Apache, the | |
| 181 | user is probably `www-data`. | |
| 182 | ||
| 183 | ```bash | |
| 184 | chgrp -R www-data /path/to/website/ | |
| 185 | chmod -R g+w _data/comments.json | |
| 186 | ``` | |
| 187 | ||
| 188 | --- | |
| 189 | ||
| 190 | ### Folder: `_functions` | |
| 191 | ||
| 192 | #### File: `loadJSON.php` | |
| 193 | ||
| 194 | This file contains four (4) functions that can be called to load JSON data from | |
| 195 | a local file in various ways. | |
| 196 | ||
| 197 | #### File: `loadRSS.php` | |
| 198 | ||
| 199 | This file contains a single function that will grab the `_data/metadata.json` | |
| 200 | file and generate a complete RSS file. | |
| 201 | ||
| 202 | #### File: `parseMarkdown.php` | |
| 203 | ||
| 204 | This file uses the `Parsedown` class to parse a posts or comments from Markdown | |
| 205 | to HTML. It also adds additional attributes to any link found in the Markdown. | |
| 206 | ||
| 207 | #### File: `submitComment.php` | |
| 208 | ||
| 209 | This file uses the `Comment` class to create a comment and then save it to | |
| 210 | `_data/comments.json`. | |
| 211 | ||
| 212 | --- | |
| 213 | ||
| 214 | ### Folder: `_templates` | |
| 215 | ||
| 216 | #### File: `template.html` | |
| 217 | ||
| 218 | This file is the end result template that will be shown to users, regardless of | |
| 219 | the URL they enter. The main content in the `<body>` and various elements in the | |
| 220 | `<head>` will change depending which function calls this template. | |
| 221 | ||
| 222 | --- | |
| 223 | ||
| 224 | ### Folder: `posts` | |
| 225 | ||
| 226 | Your `posts` folder will contain the `.md` files that will comprise the body of | |
| 227 | your blog post. Formatting follows standard Markdown guidelines. | |
| 228 | ||
| 229 | --- | |
| 230 | ||
| 231 | ### Folder: `static` | |
| 232 | ||
| 233 | This folder contains the main CSS file (`app.css`), as well as a pair of | |
| 234 | optional static files from [PrismJS](https://prismjs.com) to enable syntax | |
| 235 | highlighting in any code blocks found in posts or comments. | |
| 236 | ||
| 237 | To remove the optional files, simply delete the unwanted files and remove the | |
| 238 | following from the `pageExtras` parameter string in the `ShowComments()` and | |
| 239 | `ShowPost()` functions in `index.php`: | |
| 240 | ||
| 241 | ```html | |
| 242 | <link rel="stylesheet" href="/static/prism.css" /> | |
| 243 | <script src="/static/prism.js"></script> | |
| 244 | ``` | |
_classes/Comment.php added +26
| @@ -0,0 +1,26 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | ||
| 4 | class Comment | |
| 5 | { | |
| 6 | function __construct(string $comment, string $postURL, string $username = 'Anonymous') | |
| 7 | { | |
| 8 | $this->timestamp = date('Y-m-d H:i:s'); | |
| 9 | $this->username = $username; | |
| 10 | $this->comment = $comment; | |
| 11 | $this->postURL = $postURL; | |
| 12 | } | |
| 13 | ||
| 14 | function saveComment(string $fileName) | |
| 15 | { | |
| 16 | if (file_exists($fileName)) { | |
| 17 | $sourceData = file_get_contents($fileName); | |
| 18 | $tempArray = json_decode($sourceData); | |
| 19 | array_push($tempArray, $this); | |
| 20 | $jsonData = json_encode($tempArray, JSON_PRETTY_PRINT); | |
| 21 | file_put_contents($fileName, $jsonData); | |
| 22 | } else { | |
| 23 | die('Error: The ' . $fileName . ' file does not exist.'); | |
| 24 | } | |
| 25 | } | |
| 26 | } | |
| \ No newline at end of file | ||
_classes/Parsedown.php added +1719
| @@ -0,0 +1,1719 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | # | |
| 4 | # | |
| 5 | # Parsedown | |
| 6 | # http://parsedown.org | |
| 7 | # | |
| 8 | # (c) Emanuil Rusev | |
| 9 | # http://erusev.com | |
| 10 | # | |
| 11 | # For the full license information, _templates the LICENSE file that was distributed | |
| 12 | # with this source code. | |
| 13 | # | |
| 14 | # | |
| 15 | ||
| 16 | class Parsedown | |
| 17 | { | |
| 18 | # ~ | |
| 19 | ||
| 20 | const version = '1.7.4'; | |
| 21 | ||
| 22 | # ~ | |
| 23 | ||
| 24 | function text($text) | |
| 25 | { | |
| 26 | # make sure no definitions are set | |
| 27 | $this->DefinitionData = array(); | |
| 28 | ||
| 29 | # standardize line breaks | |
| 30 | $text = str_replace(array("\r\n", "\r"), "\n", $text); | |
| 31 | ||
| 32 | # remove surrounding line breaks | |
| 33 | $text = trim($text, "\n"); | |
| 34 | ||
| 35 | # split text into lines | |
| 36 | $lines = explode("\n", $text); | |
| 37 | ||
| 38 | # iterate through lines to identify blocks | |
| 39 | $markup = $this->lines($lines); | |
| 40 | ||
| 41 | # trim line breaks | |
| 42 | $markup = trim($markup, "\n"); | |
| 43 | ||
| 44 | return $markup; | |
| 45 | } | |
| 46 | ||
| 47 | # | |
| 48 | # Setters | |
| 49 | # | |
| 50 | ||
| 51 | function setBreaksEnabled($breaksEnabled) | |
| 52 | { | |
| 53 | $this->breaksEnabled = $breaksEnabled; | |
| 54 | ||
| 55 | return $this; | |
| 56 | } | |
| 57 | ||
| 58 | protected $breaksEnabled; | |
| 59 | ||
| 60 | function setMarkupEscaped($markupEscaped) | |
| 61 | { | |
| 62 | $this->markupEscaped = $markupEscaped; | |
| 63 | ||
| 64 | return $this; | |
| 65 | } | |
| 66 | ||
| 67 | protected $markupEscaped; | |
| 68 | ||
| 69 | function setUrlsLinked($urlsLinked) | |
| 70 | { | |
| 71 | $this->urlsLinked = $urlsLinked; | |
| 72 | ||
| 73 | return $this; | |
| 74 | } | |
| 75 | ||
| 76 | protected $urlsLinked = true; | |
| 77 | ||
| 78 | function setSafeMode($safeMode) | |
| 79 | { | |
| 80 | $this->safeMode = (bool) $safeMode; | |
| 81 | ||
| 82 | return $this; | |
| 83 | } | |
| 84 | ||
| 85 | protected $safeMode; | |
| 86 | ||
| 87 | protected $safeLinksWhitelist = array( | |
| 88 | 'http://', | |
| 89 | 'https://', | |
| 90 | 'ftp://', | |
| 91 | 'ftps://', | |
| 92 | 'mailto:', | |
| 93 | 'data:image/png;base64,', | |
| 94 | 'data:image/gif;base64,', | |
| 95 | 'data:image/jpeg;base64,', | |
| 96 | 'irc:', | |
| 97 | 'ircs:', | |
| 98 | 'git:', | |
| 99 | 'ssh:', | |
| 100 | 'news:', | |
| 101 | 'steam:', | |
| 102 | ); | |
| 103 | ||
| 104 | # | |
| 105 | # Lines | |
| 106 | # | |
| 107 | ||
| 108 | protected $BlockTypes = array( | |
| 109 | '#' => array('Header'), | |
| 110 | '*' => array('Rule', 'List'), | |
| 111 | '+' => array('List'), | |
| 112 | '-' => array('SetextHeader', 'Table', 'Rule', 'List'), | |
| 113 | '0' => array('List'), | |
| 114 | '1' => array('List'), | |
| 115 | '2' => array('List'), | |
| 116 | '3' => array('List'), | |
| 117 | '4' => array('List'), | |
| 118 | '5' => array('List'), | |
| 119 | '6' => array('List'), | |
| 120 | '7' => array('List'), | |
| 121 | '8' => array('List'), | |
| 122 | '9' => array('List'), | |
| 123 | ':' => array('Table'), | |
| 124 | '<' => array('Comment', 'Markup'), | |
| 125 | '=' => array('SetextHeader'), | |
| 126 | '>' => array('Quote'), | |
| 127 | '[' => array('Reference'), | |
| 128 | '_' => array('Rule'), | |
| 129 | '`' => array('FencedCode'), | |
| 130 | '|' => array('Table'), | |
| 131 | '~' => array('FencedCode'), | |
| 132 | ); | |
| 133 | ||
| 134 | # ~ | |
| 135 | ||
| 136 | protected $unmarkedBlockTypes = array( | |
| 137 | 'Code', | |
| 138 | ); | |
| 139 | ||
| 140 | # | |
| 141 | # Blocks | |
| 142 | # | |
| 143 | ||
| 144 | protected function lines(array $lines) | |
| 145 | { | |
| 146 | $CurrentBlock = null; | |
| 147 | ||
| 148 | foreach ($lines as $line) | |
| 149 | { | |
| 150 | if (chop($line) === '') | |
| 151 | { | |
| 152 | if (isset($CurrentBlock)) | |
| 153 | { | |
| 154 | $CurrentBlock['interrupted'] = true; | |
| 155 | } | |
| 156 | ||
| 157 | continue; | |
| 158 | } | |
| 159 | ||
| 160 | if (strpos($line, "\t") !== false) | |
| 161 | { | |
| 162 | $parts = explode("\t", $line); | |
| 163 | ||
| 164 | $line = $parts[0]; | |
| 165 | ||
| 166 | unset($parts[0]); | |
| 167 | ||
| 168 | foreach ($parts as $part) | |
| 169 | { | |
| 170 | $shortage = 4 - mb_strlen($line, 'utf-8') % 4; | |
| 171 | ||
| 172 | $line .= str_repeat(' ', $shortage); | |
| 173 | $line .= $part; | |
| 174 | } | |
| 175 | } | |
| 176 | ||
| 177 | $indent = 0; | |
| 178 | ||
| 179 | while (isset($line[$indent]) and $line[$indent] === ' ') | |
| 180 | { | |
| 181 | $indent ++; | |
| 182 | } | |
| 183 | ||
| 184 | $text = $indent > 0 ? substr($line, $indent) : $line; | |
| 185 | ||
| 186 | # ~ | |
| 187 | ||
| 188 | $Line = array('body' => $line, 'indent' => $indent, 'text' => $text); | |
| 189 | ||
| 190 | # ~ | |
| 191 | ||
| 192 | if (isset($CurrentBlock['continuable'])) | |
| 193 | { | |
| 194 | $Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock); | |
| 195 | ||
| 196 | if (isset($Block)) | |
| 197 | { | |
| 198 | $CurrentBlock = $Block; | |
| 199 | ||
| 200 | continue; | |
| 201 | } | |
| 202 | else | |
| 203 | { | |
| 204 | if ($this->isBlockCompletable($CurrentBlock['type'])) | |
| 205 | { | |
| 206 | $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); | |
| 207 | } | |
| 208 | } | |
| 209 | } | |
| 210 | ||
| 211 | # ~ | |
| 212 | ||
| 213 | $marker = $text[0]; | |
| 214 | ||
| 215 | # ~ | |
| 216 | ||
| 217 | $blockTypes = $this->unmarkedBlockTypes; | |
| 218 | ||
| 219 | if (isset($this->BlockTypes[$marker])) | |
| 220 | { | |
| 221 | foreach ($this->BlockTypes[$marker] as $blockType) | |
| 222 | { | |
| 223 | $blockTypes []= $blockType; | |
| 224 | } | |
| 225 | } | |
| 226 | ||
| 227 | # | |
| 228 | # ~ | |
| 229 | ||
| 230 | foreach ($blockTypes as $blockType) | |
| 231 | { | |
| 232 | $Block = $this->{'block'.$blockType}($Line, $CurrentBlock); | |
| 233 | ||
| 234 | if (isset($Block)) | |
| 235 | { | |
| 236 | $Block['type'] = $blockType; | |
| 237 | ||
| 238 | if ( ! isset($Block['identified'])) | |
| 239 | { | |
| 240 | $Blocks []= $CurrentBlock; | |
| 241 | ||
| 242 | $Block['identified'] = true; | |
| 243 | } | |
| 244 | ||
| 245 | if ($this->isBlockContinuable($blockType)) | |
| 246 | { | |
| 247 | $Block['continuable'] = true; | |
| 248 | } | |
| 249 | ||
| 250 | $CurrentBlock = $Block; | |
| 251 | ||
| 252 | continue 2; | |
| 253 | } | |
| 254 | } | |
| 255 | ||
| 256 | # ~ | |
| 257 | ||
| 258 | if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) | |
| 259 | { | |
| 260 | $CurrentBlock['element']['text'] .= "\n".$text; | |
| 261 | } | |
| 262 | else | |
| 263 | { | |
| 264 | $Blocks []= $CurrentBlock; | |
| 265 | ||
| 266 | $CurrentBlock = $this->paragraph($Line); | |
| 267 | ||
| 268 | $CurrentBlock['identified'] = true; | |
| 269 | } | |
| 270 | } | |
| 271 | ||
| 272 | # ~ | |
| 273 | ||
| 274 | if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type'])) | |
| 275 | { | |
| 276 | $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock); | |
| 277 | } | |
| 278 | ||
| 279 | # ~ | |
| 280 | ||
| 281 | $Blocks []= $CurrentBlock; | |
| 282 | ||
| 283 | unset($Blocks[0]); | |
| 284 | ||
| 285 | # ~ | |
| 286 | ||
| 287 | $markup = ''; | |
| 288 | ||
| 289 | foreach ($Blocks as $Block) | |
| 290 | { | |
| 291 | if (isset($Block['hidden'])) | |
| 292 | { | |
| 293 | continue; | |
| 294 | } | |
| 295 | ||
| 296 | $markup .= "\n"; | |
| 297 | $markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']); | |
| 298 | } | |
| 299 | ||
| 300 | $markup .= "\n"; | |
| 301 | ||
| 302 | # ~ | |
| 303 | ||
| 304 | return $markup; | |
| 305 | } | |
| 306 | ||
| 307 | protected function isBlockContinuable($Type) | |
| 308 | { | |
| 309 | return method_exists($this, 'block'.$Type.'Continue'); | |
| 310 | } | |
| 311 | ||
| 312 | protected function isBlockCompletable($Type) | |
| 313 | { | |
| 314 | return method_exists($this, 'block'.$Type.'Complete'); | |
| 315 | } | |
| 316 | ||
| 317 | # | |
| 318 | # Code | |
| 319 | ||
| 320 | protected function blockCode($Line, $Block = null) | |
| 321 | { | |
| 322 | if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted'])) | |
| 323 | { | |
| 324 | return; | |
| 325 | } | |
| 326 | ||
| 327 | if ($Line['indent'] >= 4) | |
| 328 | { | |
| 329 | $text = substr($Line['body'], 4); | |
| 330 | ||
| 331 | $Block = array( | |
| 332 | 'element' => array( | |
| 333 | 'name' => 'pre', | |
| 334 | 'handler' => 'element', | |
| 335 | 'text' => array( | |
| 336 | 'name' => 'code', | |
| 337 | 'text' => $text, | |
| 338 | ), | |
| 339 | ), | |
| 340 | ); | |
| 341 | ||
| 342 | return $Block; | |
| 343 | } | |
| 344 | } | |
| 345 | ||
| 346 | protected function blockCodeContinue($Line, $Block) | |
| 347 | { | |
| 348 | if ($Line['indent'] >= 4) | |
| 349 | { | |
| 350 | if (isset($Block['interrupted'])) | |
| 351 | { | |
| 352 | $Block['element']['text']['text'] .= "\n"; | |
| 353 | ||
| 354 | unset($Block['interrupted']); | |
| 355 | } | |
| 356 | ||
| 357 | $Block['element']['text']['text'] .= "\n"; | |
| 358 | ||
| 359 | $text = substr($Line['body'], 4); | |
| 360 | ||
| 361 | $Block['element']['text']['text'] .= $text; | |
| 362 | ||
| 363 | return $Block; | |
| 364 | } | |
| 365 | } | |
| 366 | ||
| 367 | protected function blockCodeComplete($Block) | |
| 368 | { | |
| 369 | $text = $Block['element']['text']['text']; | |
| 370 | ||
| 371 | $Block['element']['text']['text'] = $text; | |
| 372 | ||
| 373 | return $Block; | |
| 374 | } | |
| 375 | ||
| 376 | # | |
| 377 | # Comment | |
| 378 | ||
| 379 | protected function blockComment($Line) | |
| 380 | { | |
| 381 | if ($this->markupEscaped or $this->safeMode) | |
| 382 | { | |
| 383 | return; | |
| 384 | } | |
| 385 | ||
| 386 | if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!') | |
| 387 | { | |
| 388 | $Block = array( | |
| 389 | 'markup' => $Line['body'], | |
| 390 | ); | |
| 391 | ||
| 392 | if (preg_match('/-->$/', $Line['text'])) | |
| 393 | { | |
| 394 | $Block['closed'] = true; | |
| 395 | } | |
| 396 | ||
| 397 | return $Block; | |
| 398 | } | |
| 399 | } | |
| 400 | ||
| 401 | protected function blockCommentContinue($Line, array $Block) | |
| 402 | { | |
| 403 | if (isset($Block['closed'])) | |
| 404 | { | |
| 405 | return; | |
| 406 | } | |
| 407 | ||
| 408 | $Block['markup'] .= "\n" . $Line['body']; | |
| 409 | ||
| 410 | if (preg_match('/-->$/', $Line['text'])) | |
| 411 | { | |
| 412 | $Block['closed'] = true; | |
| 413 | } | |
| 414 | ||
| 415 | return $Block; | |
| 416 | } | |
| 417 | ||
| 418 | # | |
| 419 | # Fenced Code | |
| 420 | ||
| 421 | protected function blockFencedCode($Line) | |
| 422 | { | |
| 423 | if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([^`]+)?[ ]*$/', $Line['text'], $matches)) | |
| 424 | { | |
| 425 | $Element = array( | |
| 426 | 'name' => 'code', | |
| 427 | 'text' => '', | |
| 428 | ); | |
| 429 | ||
| 430 | if (isset($matches[1])) | |
| 431 | { | |
| 432 | /** | |
| 433 | * https://www.w3.org/TR/2011/WD-html5-20110525/elements.html#classes | |
| 434 | * Every HTML element may have a class attribute specified. | |
| 435 | * The attribute, if specified, must have a value that is a set | |
| 436 | * of space-separated tokens representing the various classes | |
| 437 | * that the element belongs to. | |
| 438 | * [...] | |
| 439 | * The space characters, for the purposes of this specification, | |
| 440 | * are U+0020 SPACE, U+0009 CHARACTER TABULATION (tab), | |
| 441 | * U+000A LINE FEED (LF), U+000C FORM FEED (FF), and | |
| 442 | * U+000D CARRIAGE RETURN (CR). | |
| 443 | */ | |
| 444 | $language = substr($matches[1], 0, strcspn($matches[1], " \t\n\f\r")); | |
| 445 | ||
| 446 | $class = 'language-'.$language; | |
| 447 | ||
| 448 | $Element['attributes'] = array( | |
| 449 | 'class' => $class, | |
| 450 | ); | |
| 451 | } | |
| 452 | ||
| 453 | $Block = array( | |
| 454 | 'char' => $Line['text'][0], | |
| 455 | 'element' => array( | |
| 456 | 'name' => 'pre', | |
| 457 | 'handler' => 'element', | |
| 458 | 'text' => $Element, | |
| 459 | ), | |
| 460 | ); | |
| 461 | ||
| 462 | return $Block; | |
| 463 | } | |
| 464 | } | |
| 465 | ||
| 466 | protected function blockFencedCodeContinue($Line, $Block) | |
| 467 | { | |
| 468 | if (isset($Block['complete'])) | |
| 469 | { | |
| 470 | return; | |
| 471 | } | |
| 472 | ||
| 473 | if (isset($Block['interrupted'])) | |
| 474 | { | |
| 475 | $Block['element']['text']['text'] .= "\n"; | |
| 476 | ||
| 477 | unset($Block['interrupted']); | |
| 478 | } | |
| 479 | ||
| 480 | if (preg_match('/^'.$Block['char'].'{3,}[ ]*$/', $Line['text'])) | |
| 481 | { | |
| 482 | $Block['element']['text']['text'] = substr($Block['element']['text']['text'], 1); | |
| 483 | ||
| 484 | $Block['complete'] = true; | |
| 485 | ||
| 486 | return $Block; | |
| 487 | } | |
| 488 | ||
| 489 | $Block['element']['text']['text'] .= "\n".$Line['body']; | |
| 490 | ||
| 491 | return $Block; | |
| 492 | } | |
| 493 | ||
| 494 | protected function blockFencedCodeComplete($Block) | |
| 495 | { | |
| 496 | $text = $Block['element']['text']['text']; | |
| 497 | ||
| 498 | $Block['element']['text']['text'] = $text; | |
| 499 | ||
| 500 | return $Block; | |
| 501 | } | |
| 502 | ||
| 503 | # | |
| 504 | # Header | |
| 505 | ||
| 506 | protected function blockHeader($Line) | |
| 507 | { | |
| 508 | if (isset($Line['text'][1])) | |
| 509 | { | |
| 510 | $level = 1; | |
| 511 | ||
| 512 | while (isset($Line['text'][$level]) and $Line['text'][$level] === '#') | |
| 513 | { | |
| 514 | $level ++; | |
| 515 | } | |
| 516 | ||
| 517 | if ($level > 6) | |
| 518 | { | |
| 519 | return; | |
| 520 | } | |
| 521 | ||
| 522 | $text = trim($Line['text'], '# '); | |
| 523 | ||
| 524 | $Block = array( | |
| 525 | 'element' => array( | |
| 526 | 'name' => 'h' . min(6, $level), | |
| 527 | 'text' => $text, | |
| 528 | 'handler' => 'line', | |
| 529 | ), | |
| 530 | ); | |
| 531 | ||
| 532 | return $Block; | |
| 533 | } | |
| 534 | } | |
| 535 | ||
| 536 | # | |
| 537 | # List | |
| 538 | ||
| 539 | protected function blockList($Line) | |
| 540 | { | |
| 541 | list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]'); | |
| 542 | ||
| 543 | if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) | |
| 544 | { | |
| 545 | $Block = array( | |
| 546 | 'indent' => $Line['indent'], | |
| 547 | 'pattern' => $pattern, | |
| 548 | 'element' => array( | |
| 549 | 'name' => $name, | |
| 550 | 'handler' => 'elements', | |
| 551 | ), | |
| 552 | ); | |
| 553 | ||
| 554 | if($name === 'ol') | |
| 555 | { | |
| 556 | $listStart = stristr($matches[0], '.', true); | |
| 557 | ||
| 558 | if($listStart !== '1') | |
| 559 | { | |
| 560 | $Block['element']['attributes'] = array('start' => $listStart); | |
| 561 | } | |
| 562 | } | |
| 563 | ||
| 564 | $Block['li'] = array( | |
| 565 | 'name' => 'li', | |
| 566 | 'handler' => 'li', | |
| 567 | 'text' => array( | |
| 568 | $matches[2], | |
| 569 | ), | |
| 570 | ); | |
| 571 | ||
| 572 | $Block['element']['text'] []= & $Block['li']; | |
| 573 | ||
| 574 | return $Block; | |
| 575 | } | |
| 576 | } | |
| 577 | ||
| 578 | protected function blockListContinue($Line, array $Block) | |
| 579 | { | |
| 580 | if ($Block['indent'] === $Line['indent'] and preg_match('/^'.$Block['pattern'].'(?:[ ]+(.*)|$)/', $Line['text'], $matches)) | |
| 581 | { | |
| 582 | if (isset($Block['interrupted'])) | |
| 583 | { | |
| 584 | $Block['li']['text'] []= ''; | |
| 585 | ||
| 586 | $Block['loose'] = true; | |
| 587 | ||
| 588 | unset($Block['interrupted']); | |
| 589 | } | |
| 590 | ||
| 591 | unset($Block['li']); | |
| 592 | ||
| 593 | $text = isset($matches[1]) ? $matches[1] : ''; | |
| 594 | ||
| 595 | $Block['li'] = array( | |
| 596 | 'name' => 'li', | |
| 597 | 'handler' => 'li', | |
| 598 | 'text' => array( | |
| 599 | $text, | |
| 600 | ), | |
| 601 | ); | |
| 602 | ||
| 603 | $Block['element']['text'] []= & $Block['li']; | |
| 604 | ||
| 605 | return $Block; | |
| 606 | } | |
| 607 | ||
| 608 | if ($Line['text'][0] === '[' and $this->blockReference($Line)) | |
| 609 | { | |
| 610 | return $Block; | |
| 611 | } | |
| 612 | ||
| 613 | if ( ! isset($Block['interrupted'])) | |
| 614 | { | |
| 615 | $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); | |
| 616 | ||
| 617 | $Block['li']['text'] []= $text; | |
| 618 | ||
| 619 | return $Block; | |
| 620 | } | |
| 621 | ||
| 622 | if ($Line['indent'] > 0) | |
| 623 | { | |
| 624 | $Block['li']['text'] []= ''; | |
| 625 | ||
| 626 | $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']); | |
| 627 | ||
| 628 | $Block['li']['text'] []= $text; | |
| 629 | ||
| 630 | unset($Block['interrupted']); | |
| 631 | ||
| 632 | return $Block; | |
| 633 | } | |
| 634 | } | |
| 635 | ||
| 636 | protected function blockListComplete(array $Block) | |
| 637 | { | |
| 638 | if (isset($Block['loose'])) | |
| 639 | { | |
| 640 | foreach ($Block['element']['text'] as &$li) | |
| 641 | { | |
| 642 | if (end($li['text']) !== '') | |
| 643 | { | |
| 644 | $li['text'] []= ''; | |
| 645 | } | |
| 646 | } | |
| 647 | } | |
| 648 | ||
| 649 | return $Block; | |
| 650 | } | |
| 651 | ||
| 652 | # | |
| 653 | # Quote | |
| 654 | ||
| 655 | protected function blockQuote($Line) | |
| 656 | { | |
| 657 | if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) | |
| 658 | { | |
| 659 | $Block = array( | |
| 660 | 'element' => array( | |
| 661 | 'name' => 'blockquote', | |
| 662 | 'handler' => 'lines', | |
| 663 | 'text' => (array) $matches[1], | |
| 664 | ), | |
| 665 | ); | |
| 666 | ||
| 667 | return $Block; | |
| 668 | } | |
| 669 | } | |
| 670 | ||
| 671 | protected function blockQuoteContinue($Line, array $Block) | |
| 672 | { | |
| 673 | if ($Line['text'][0] === '>' and preg_match('/^>[ ]?(.*)/', $Line['text'], $matches)) | |
| 674 | { | |
| 675 | if (isset($Block['interrupted'])) | |
| 676 | { | |
| 677 | $Block['element']['text'] []= ''; | |
| 678 | ||
| 679 | unset($Block['interrupted']); | |
| 680 | } | |
| 681 | ||
| 682 | $Block['element']['text'] []= $matches[1]; | |
| 683 | ||
| 684 | return $Block; | |
| 685 | } | |
| 686 | ||
| 687 | if ( ! isset($Block['interrupted'])) | |
| 688 | { | |
| 689 | $Block['element']['text'] []= $Line['text']; | |
| 690 | ||
| 691 | return $Block; | |
| 692 | } | |
| 693 | } | |
| 694 | ||
| 695 | # | |
| 696 | # Rule | |
| 697 | ||
| 698 | protected function blockRule($Line) | |
| 699 | { | |
| 700 | if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text'])) | |
| 701 | { | |
| 702 | $Block = array( | |
| 703 | 'element' => array( | |
| 704 | 'name' => 'hr' | |
| 705 | ), | |
| 706 | ); | |
| 707 | ||
| 708 | return $Block; | |
| 709 | } | |
| 710 | } | |
| 711 | ||
| 712 | # | |
| 713 | # Setext | |
| 714 | ||
| 715 | protected function blockSetextHeader($Line, array $Block = null) | |
| 716 | { | |
| 717 | if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) | |
| 718 | { | |
| 719 | return; | |
| 720 | } | |
| 721 | ||
| 722 | if (chop($Line['text'], $Line['text'][0]) === '') | |
| 723 | { | |
| 724 | $Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2'; | |
| 725 | ||
| 726 | return $Block; | |
| 727 | } | |
| 728 | } | |
| 729 | ||
| 730 | # | |
| 731 | # Markup | |
| 732 | ||
| 733 | protected function blockMarkup($Line) | |
| 734 | { | |
| 735 | if ($this->markupEscaped or $this->safeMode) | |
| 736 | { | |
| 737 | return; | |
| 738 | } | |
| 739 | ||
| 740 | if (preg_match('/^<(\w[\w-]*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches)) | |
| 741 | { | |
| 742 | $element = strtolower($matches[1]); | |
| 743 | ||
| 744 | if (in_array($element, $this->textLevelElements)) | |
| 745 | { | |
| 746 | return; | |
| 747 | } | |
| 748 | ||
| 749 | $Block = array( | |
| 750 | 'name' => $matches[1], | |
| 751 | 'depth' => 0, | |
| 752 | 'markup' => $Line['text'], | |
| 753 | ); | |
| 754 | ||
| 755 | $length = strlen($matches[0]); | |
| 756 | ||
| 757 | $remainder = substr($Line['text'], $length); | |
| 758 | ||
| 759 | if (trim($remainder) === '') | |
| 760 | { | |
| 761 | if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) | |
| 762 | { | |
| 763 | $Block['closed'] = true; | |
| 764 | ||
| 765 | $Block['void'] = true; | |
| 766 | } | |
| 767 | } | |
| 768 | else | |
| 769 | { | |
| 770 | if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) | |
| 771 | { | |
| 772 | return; | |
| 773 | } | |
| 774 | ||
| 775 | if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder)) | |
| 776 | { | |
| 777 | $Block['closed'] = true; | |
| 778 | } | |
| 779 | } | |
| 780 | ||
| 781 | return $Block; | |
| 782 | } | |
| 783 | } | |
| 784 | ||
| 785 | protected function blockMarkupContinue($Line, array $Block) | |
| 786 | { | |
| 787 | if (isset($Block['closed'])) | |
| 788 | { | |
| 789 | return; | |
| 790 | } | |
| 791 | ||
| 792 | if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open | |
| 793 | { | |
| 794 | $Block['depth'] ++; | |
| 795 | } | |
| 796 | ||
| 797 | if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close | |
| 798 | { | |
| 799 | if ($Block['depth'] > 0) | |
| 800 | { | |
| 801 | $Block['depth'] --; | |
| 802 | } | |
| 803 | else | |
| 804 | { | |
| 805 | $Block['closed'] = true; | |
| 806 | } | |
| 807 | } | |
| 808 | ||
| 809 | if (isset($Block['interrupted'])) | |
| 810 | { | |
| 811 | $Block['markup'] .= "\n"; | |
| 812 | ||
| 813 | unset($Block['interrupted']); | |
| 814 | } | |
| 815 | ||
| 816 | $Block['markup'] .= "\n".$Line['body']; | |
| 817 | ||
| 818 | return $Block; | |
| 819 | } | |
| 820 | ||
| 821 | # | |
| 822 | # Reference | |
| 823 | ||
| 824 | protected function blockReference($Line) | |
| 825 | { | |
| 826 | if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches)) | |
| 827 | { | |
| 828 | $id = strtolower($matches[1]); | |
| 829 | ||
| 830 | $Data = array( | |
| 831 | 'url' => $matches[2], | |
| 832 | 'title' => null, | |
| 833 | ); | |
| 834 | ||
| 835 | if (isset($matches[3])) | |
| 836 | { | |
| 837 | $Data['title'] = $matches[3]; | |
| 838 | } | |
| 839 | ||
| 840 | $this->DefinitionData['Reference'][$id] = $Data; | |
| 841 | ||
| 842 | $Block = array( | |
| 843 | 'hidden' => true, | |
| 844 | ); | |
| 845 | ||
| 846 | return $Block; | |
| 847 | } | |
| 848 | } | |
| 849 | ||
| 850 | # | |
| 851 | # Table | |
| 852 | ||
| 853 | protected function blockTable($Line, array $Block = null) | |
| 854 | { | |
| 855 | if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted'])) | |
| 856 | { | |
| 857 | return; | |
| 858 | } | |
| 859 | ||
| 860 | if (strpos($Block['element']['text'], '|') !== false and chop($Line['text'], ' -:|') === '') | |
| 861 | { | |
| 862 | $alignments = array(); | |
| 863 | ||
| 864 | $divider = $Line['text']; | |
| 865 | ||
| 866 | $divider = trim($divider); | |
| 867 | $divider = trim($divider, '|'); | |
| 868 | ||
| 869 | $dividerCells = explode('|', $divider); | |
| 870 | ||
| 871 | foreach ($dividerCells as $dividerCell) | |
| 872 | { | |
| 873 | $dividerCell = trim($dividerCell); | |
| 874 | ||
| 875 | if ($dividerCell === '') | |
| 876 | { | |
| 877 | continue; | |
| 878 | } | |
| 879 | ||
| 880 | $alignment = null; | |
| 881 | ||
| 882 | if ($dividerCell[0] === ':') | |
| 883 | { | |
| 884 | $alignment = 'left'; | |
| 885 | } | |
| 886 | ||
| 887 | if (substr($dividerCell, - 1) === ':') | |
| 888 | { | |
| 889 | $alignment = $alignment === 'left' ? 'center' : 'right'; | |
| 890 | } | |
| 891 | ||
| 892 | $alignments []= $alignment; | |
| 893 | } | |
| 894 | ||
| 895 | # ~ | |
| 896 | ||
| 897 | $HeaderElements = array(); | |
| 898 | ||
| 899 | $header = $Block['element']['text']; | |
| 900 | ||
| 901 | $header = trim($header); | |
| 902 | $header = trim($header, '|'); | |
| 903 | ||
| 904 | $headerCells = explode('|', $header); | |
| 905 | ||
| 906 | foreach ($headerCells as $index => $headerCell) | |
| 907 | { | |
| 908 | $headerCell = trim($headerCell); | |
| 909 | ||
| 910 | $HeaderElement = array( | |
| 911 | 'name' => 'th', | |
| 912 | 'text' => $headerCell, | |
| 913 | 'handler' => 'line', | |
| 914 | ); | |
| 915 | ||
| 916 | if (isset($alignments[$index])) | |
| 917 | { | |
| 918 | $alignment = $alignments[$index]; | |
| 919 | ||
| 920 | $HeaderElement['attributes'] = array( | |
| 921 | 'style' => 'text-align: '.$alignment.';', | |
| 922 | ); | |
| 923 | } | |
| 924 | ||
| 925 | $HeaderElements []= $HeaderElement; | |
| 926 | } | |
| 927 | ||
| 928 | # ~ | |
| 929 | ||
| 930 | $Block = array( | |
| 931 | 'alignments' => $alignments, | |
| 932 | 'identified' => true, | |
| 933 | 'element' => array( | |
| 934 | 'name' => 'table', | |
| 935 | 'handler' => 'elements', | |
| 936 | ), | |
| 937 | ); | |
| 938 | ||
| 939 | $Block['element']['text'] []= array( | |
| 940 | 'name' => 'thead', | |
| 941 | 'handler' => 'elements', | |
| 942 | ); | |
| 943 | ||
| 944 | $Block['element']['text'] []= array( | |
| 945 | 'name' => 'tbody', | |
| 946 | 'handler' => 'elements', | |
| 947 | 'text' => array(), | |
| 948 | ); | |
| 949 | ||
| 950 | $Block['element']['text'][0]['text'] []= array( | |
| 951 | 'name' => 'tr', | |
| 952 | 'handler' => 'elements', | |
| 953 | 'text' => $HeaderElements, | |
| 954 | ); | |
| 955 | ||
| 956 | return $Block; | |
| 957 | } | |
| 958 | } | |
| 959 | ||
| 960 | protected function blockTableContinue($Line, array $Block) | |
| 961 | { | |
| 962 | if (isset($Block['interrupted'])) | |
| 963 | { | |
| 964 | return; | |
| 965 | } | |
| 966 | ||
| 967 | if ($Line['text'][0] === '|' or strpos($Line['text'], '|')) | |
| 968 | { | |
| 969 | $Elements = array(); | |
| 970 | ||
| 971 | $row = $Line['text']; | |
| 972 | ||
| 973 | $row = trim($row); | |
| 974 | $row = trim($row, '|'); | |
| 975 | ||
| 976 | preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches); | |
| 977 | ||
| 978 | foreach ($matches[0] as $index => $cell) | |
| 979 | { | |
| 980 | $cell = trim($cell); | |
| 981 | ||
| 982 | $Element = array( | |
| 983 | 'name' => 'td', | |
| 984 | 'handler' => 'line', | |
| 985 | 'text' => $cell, | |
| 986 | ); | |
| 987 | ||
| 988 | if (isset($Block['alignments'][$index])) | |
| 989 | { | |
| 990 | $Element['attributes'] = array( | |
| 991 | 'style' => 'text-align: '.$Block['alignments'][$index].';', | |
| 992 | ); | |
| 993 | } | |
| 994 | ||
| 995 | $Elements []= $Element; | |
| 996 | } | |
| 997 | ||
| 998 | $Element = array( | |
| 999 | 'name' => 'tr', | |
| 1000 | 'handler' => 'elements', | |
| 1001 | 'text' => $Elements, | |
| 1002 | ); | |
| 1003 | ||
| 1004 | $Block['element']['text'][1]['text'] []= $Element; | |
| 1005 | ||
| 1006 | return $Block; | |
| 1007 | } | |
| 1008 | } | |
| 1009 | ||
| 1010 | # | |
| 1011 | # ~ | |
| 1012 | # | |
| 1013 | ||
| 1014 | protected function paragraph($Line) | |
| 1015 | { | |
| 1016 | $Block = array( | |
| 1017 | 'element' => array( | |
| 1018 | 'name' => 'p', | |
| 1019 | 'text' => $Line['text'], | |
| 1020 | 'handler' => 'line', | |
| 1021 | ), | |
| 1022 | ); | |
| 1023 | ||
| 1024 | return $Block; | |
| 1025 | } | |
| 1026 | ||
| 1027 | # | |
| 1028 | # Inline Elements | |
| 1029 | # | |
| 1030 | ||
| 1031 | protected $InlineTypes = array( | |
| 1032 | '"' => array('SpecialCharacter'), | |
| 1033 | '!' => array('Image'), | |
| 1034 | '&' => array('SpecialCharacter'), | |
| 1035 | '*' => array('Emphasis'), | |
| 1036 | ':' => array('Url'), | |
| 1037 | '<' => array('UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'), | |
| 1038 | '>' => array('SpecialCharacter'), | |
| 1039 | '[' => array('Link'), | |
| 1040 | '_' => array('Emphasis'), | |
| 1041 | '`' => array('Code'), | |
| 1042 | '~' => array('Strikethrough'), | |
| 1043 | '\\' => array('EscapeSequence'), | |
| 1044 | ); | |
| 1045 | ||
| 1046 | # ~ | |
| 1047 | ||
| 1048 | protected $inlineMarkerList = '!"*_&[:<>`~\\'; | |
| 1049 | ||
| 1050 | # | |
| 1051 | # ~ | |
| 1052 | # | |
| 1053 | ||
| 1054 | public function line($text, $nonNestables=array()) | |
| 1055 | { | |
| 1056 | $markup = ''; | |
| 1057 | ||
| 1058 | # $excerpt is based on the first occurrence of a marker | |
| 1059 | ||
| 1060 | while ($excerpt = strpbrk($text, $this->inlineMarkerList)) | |
| 1061 | { | |
| 1062 | $marker = $excerpt[0]; | |
| 1063 | ||
| 1064 | $markerPosition = strpos($text, $marker); | |
| 1065 | ||
| 1066 | $Excerpt = array('text' => $excerpt, 'context' => $text); | |
| 1067 | ||
| 1068 | foreach ($this->InlineTypes[$marker] as $inlineType) | |
| 1069 | { | |
| 1070 | # check to see if the current inline type is nestable in the current context | |
| 1071 | ||
| 1072 | if ( ! empty($nonNestables) and in_array($inlineType, $nonNestables)) | |
| 1073 | { | |
| 1074 | continue; | |
| 1075 | } | |
| 1076 | ||
| 1077 | $Inline = $this->{'inline'.$inlineType}($Excerpt); | |
| 1078 | ||
| 1079 | if ( ! isset($Inline)) | |
| 1080 | { | |
| 1081 | continue; | |
| 1082 | } | |
| 1083 | ||
| 1084 | # makes sure that the inline belongs to "our" marker | |
| 1085 | ||
| 1086 | if (isset($Inline['position']) and $Inline['position'] > $markerPosition) | |
| 1087 | { | |
| 1088 | continue; | |
| 1089 | } | |
| 1090 | ||
| 1091 | # sets a default inline position | |
| 1092 | ||
| 1093 | if ( ! isset($Inline['position'])) | |
| 1094 | { | |
| 1095 | $Inline['position'] = $markerPosition; | |
| 1096 | } | |
| 1097 | ||
| 1098 | # cause the new element to 'inherit' our non nestables | |
| 1099 | ||
| 1100 | foreach ($nonNestables as $non_nestable) | |
| 1101 | { | |
| 1102 | $Inline['element']['nonNestables'][] = $non_nestable; | |
| 1103 | } | |
| 1104 | ||
| 1105 | # the text that comes before the inline | |
| 1106 | $unmarkedText = substr($text, 0, $Inline['position']); | |
| 1107 | ||
| 1108 | # compile the unmarked text | |
| 1109 | $markup .= $this->unmarkedText($unmarkedText); | |
| 1110 | ||
| 1111 | # compile the inline | |
| 1112 | $markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']); | |
| 1113 | ||
| 1114 | # remove the examined text | |
| 1115 | $text = substr($text, $Inline['position'] + $Inline['extent']); | |
| 1116 | ||
| 1117 | continue 2; | |
| 1118 | } | |
| 1119 | ||
| 1120 | # the marker does not belong to an inline | |
| 1121 | ||
| 1122 | $unmarkedText = substr($text, 0, $markerPosition + 1); | |
| 1123 | ||
| 1124 | $markup .= $this->unmarkedText($unmarkedText); | |
| 1125 | ||
| 1126 | $text = substr($text, $markerPosition + 1); | |
| 1127 | } | |
| 1128 | ||
| 1129 | $markup .= $this->unmarkedText($text); | |
| 1130 | ||
| 1131 | return $markup; | |
| 1132 | } | |
| 1133 | ||
| 1134 | # | |
| 1135 | # ~ | |
| 1136 | # | |
| 1137 | ||
| 1138 | protected function inlineCode($Excerpt) | |
| 1139 | { | |
| 1140 | $marker = $Excerpt['text'][0]; | |
| 1141 | ||
| 1142 | if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(?<!'.$marker.')\1(?!'.$marker.')/s', $Excerpt['text'], $matches)) | |
| 1143 | { | |
| 1144 | $text = $matches[2]; | |
| 1145 | $text = preg_replace("/[ ]*\n/", ' ', $text); | |
| 1146 | ||
| 1147 | return array( | |
| 1148 | 'extent' => strlen($matches[0]), | |
| 1149 | 'element' => array( | |
| 1150 | 'name' => 'code', | |
| 1151 | 'text' => $text, | |
| 1152 | ), | |
| 1153 | ); | |
| 1154 | } | |
| 1155 | } | |
| 1156 | ||
| 1157 | protected function inlineEmailTag($Excerpt) | |
| 1158 | { | |
| 1159 | if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches)) | |
| 1160 | { | |
| 1161 | $url = $matches[1]; | |
| 1162 | ||
| 1163 | if ( ! isset($matches[2])) | |
| 1164 | { | |
| 1165 | $url = 'mailto:' . $url; | |
| 1166 | } | |
| 1167 | ||
| 1168 | return array( | |
| 1169 | 'extent' => strlen($matches[0]), | |
| 1170 | 'element' => array( | |
| 1171 | 'name' => 'a', | |
| 1172 | 'text' => $matches[1], | |
| 1173 | 'attributes' => array( | |
| 1174 | 'href' => $url, | |
| 1175 | 'rel' => 'noopener,noreferrer', | |
| 1176 | 'target' => '_blank' | |
| 1177 | ), | |
| 1178 | ), | |
| 1179 | ); | |
| 1180 | } | |
| 1181 | } | |
| 1182 | ||
| 1183 | protected function inlineEmphasis($Excerpt) | |
| 1184 | { | |
| 1185 | if ( ! isset($Excerpt['text'][1])) | |
| 1186 | { | |
| 1187 | return; | |
| 1188 | } | |
| 1189 | ||
| 1190 | $marker = $Excerpt['text'][0]; | |
| 1191 | ||
| 1192 | if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) | |
| 1193 | { | |
| 1194 | $emphasis = 'strong'; | |
| 1195 | } | |
| 1196 | elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) | |
| 1197 | { | |
| 1198 | $emphasis = 'em'; | |
| 1199 | } | |
| 1200 | else | |
| 1201 | { | |
| 1202 | return; | |
| 1203 | } | |
| 1204 | ||
| 1205 | return array( | |
| 1206 | 'extent' => strlen($matches[0]), | |
| 1207 | 'element' => array( | |
| 1208 | 'name' => $emphasis, | |
| 1209 | 'handler' => 'line', | |
| 1210 | 'text' => $matches[1], | |
| 1211 | ), | |
| 1212 | ); | |
| 1213 | } | |
| 1214 | ||
| 1215 | protected function inlineEscapeSequence($Excerpt) | |
| 1216 | { | |
| 1217 | if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters)) | |
| 1218 | { | |
| 1219 | return array( | |
| 1220 | 'markup' => $Excerpt['text'][1], | |
| 1221 | 'extent' => 2, | |
| 1222 | ); | |
| 1223 | } | |
| 1224 | } | |
| 1225 | ||
| 1226 | protected function inlineImage($Excerpt) | |
| 1227 | { | |
| 1228 | if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') | |
| 1229 | { | |
| 1230 | return; | |
| 1231 | } | |
| 1232 | ||
| 1233 | $Excerpt['text']= substr($Excerpt['text'], 1); | |
| 1234 | ||
| 1235 | $Link = $this->inlineLink($Excerpt); | |
| 1236 | ||
| 1237 | if ($Link === null) | |
| 1238 | { | |
| 1239 | return; | |
| 1240 | } | |
| 1241 | ||
| 1242 | $Inline = array( | |
| 1243 | 'extent' => $Link['extent'] + 1, | |
| 1244 | 'element' => array( | |
| 1245 | 'name' => 'img', | |
| 1246 | 'attributes' => array( | |
| 1247 | 'src' => $Link['element']['attributes']['href'], | |
| 1248 | 'alt' => $Link['element']['text'], | |
| 1249 | 'class' => 'img-fluid' | |
| 1250 | ), | |
| 1251 | ), | |
| 1252 | ); | |
| 1253 | ||
| 1254 | $Inline['element']['attributes'] += $Link['element']['attributes']; | |
| 1255 | ||
| 1256 | unset($Inline['element']['attributes']['href']); | |
| 1257 | ||
| 1258 | return $Inline; | |
| 1259 | } | |
| 1260 | ||
| 1261 | protected function inlineLink($Excerpt) | |
| 1262 | { | |
| 1263 | $Element = array( | |
| 1264 | 'name' => 'a', | |
| 1265 | 'handler' => 'line', | |
| 1266 | 'nonNestables' => array('Url', 'Link'), | |
| 1267 | 'text' => null, | |
| 1268 | 'attributes' => array( | |
| 1269 | 'href' => null, | |
| 1270 | 'title' => null, | |
| 1271 | ), | |
| 1272 | ); | |
| 1273 | ||
| 1274 | $extent = 0; | |
| 1275 | ||
| 1276 | $remainder = $Excerpt['text']; | |
| 1277 | ||
| 1278 | if (preg_match('/\[((?:[^][]++|(?R))*+)\]/', $remainder, $matches)) | |
| 1279 | { | |
| 1280 | $Element['text'] = $matches[1]; | |
| 1281 | ||
| 1282 | $extent += strlen($matches[0]); | |
| 1283 | ||
| 1284 | $remainder = substr($remainder, $extent); | |
| 1285 | } | |
| 1286 | else | |
| 1287 | { | |
| 1288 | return; | |
| 1289 | } | |
| 1290 | ||
| 1291 | if (preg_match('/^[(]\s*+((?:[^ ()]++|[(][^ )]+[)])++)(?:[ ]+("[^"]*"|\'[^\']*\'))?\s*[)]/', $remainder, $matches)) | |
| 1292 | { | |
| 1293 | $Element['attributes']['href'] = $matches[1]; | |
| 1294 | ||
| 1295 | if (isset($matches[2])) | |
| 1296 | { | |
| 1297 | $Element['attributes']['title'] = substr($matches[2], 1, - 1); | |
| 1298 | } | |
| 1299 | ||
| 1300 | $extent += strlen($matches[0]); | |
| 1301 | } | |
| 1302 | else | |
| 1303 | { | |
| 1304 | if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) | |
| 1305 | { | |
| 1306 | $definition = strlen($matches[1]) ? $matches[1] : $Element['text']; | |
| 1307 | $definition = strtolower($definition); | |
| 1308 | ||
| 1309 | $extent += strlen($matches[0]); | |
| 1310 | } | |
| 1311 | else | |
| 1312 | { | |
| 1313 | $definition = strtolower($Element['text']); | |
| 1314 | } | |
| 1315 | ||
| 1316 | if ( ! isset($this->DefinitionData['Reference'][$definition])) | |
| 1317 | { | |
| 1318 | return; | |
| 1319 | } | |
| 1320 | ||
| 1321 | $Definition = $this->DefinitionData['Reference'][$definition]; | |
| 1322 | ||
| 1323 | $Element['attributes']['href'] = $Definition['url']; | |
| 1324 | $Element['attributes']['title'] = $Definition['title']; | |
| 1325 | } | |
| 1326 | ||
| 1327 | return array( | |
| 1328 | 'extent' => $extent, | |
| 1329 | 'element' => $Element, | |
| 1330 | ); | |
| 1331 | } | |
| 1332 | ||
| 1333 | protected function inlineMarkup($Excerpt) | |
| 1334 | { | |
| 1335 | if ($this->markupEscaped or $this->safeMode or strpos($Excerpt['text'], '>') === false) | |
| 1336 | { | |
| 1337 | return; | |
| 1338 | } | |
| 1339 | ||
| 1340 | if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w[\w-]*[ ]*>/s', $Excerpt['text'], $matches)) | |
| 1341 | { | |
| 1342 | return array( | |
| 1343 | 'markup' => $matches[0], | |
| 1344 | 'extent' => strlen($matches[0]), | |
| 1345 | ); | |
| 1346 | } | |
| 1347 | ||
| 1348 | if ($Excerpt['text'][1] === '!' and preg_match('/^<!---?[^>-](?:-?[^-])*-->/s', $Excerpt['text'], $matches)) | |
| 1349 | { | |
| 1350 | return array( | |
| 1351 | 'markup' => $matches[0], | |
| 1352 | 'extent' => strlen($matches[0]), | |
| 1353 | ); | |
| 1354 | } | |
| 1355 | ||
| 1356 | if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w[\w-]*(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*\/?>/s', $Excerpt['text'], $matches)) | |
| 1357 | { | |
| 1358 | return array( | |
| 1359 | 'markup' => $matches[0], | |
| 1360 | 'extent' => strlen($matches[0]), | |
| 1361 | ); | |
| 1362 | } | |
| 1363 | } | |
| 1364 | ||
| 1365 | protected function inlineSpecialCharacter($Excerpt) | |
| 1366 | { | |
| 1367 | if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text'])) | |
| 1368 | { | |
| 1369 | return array( | |
| 1370 | 'markup' => '&', | |
| 1371 | 'extent' => 1, | |
| 1372 | ); | |
| 1373 | } | |
| 1374 | ||
| 1375 | $SpecialCharacter = array('>' => 'gt', '<' => 'lt', '"' => 'quot'); | |
| 1376 | ||
| 1377 | if (isset($SpecialCharacter[$Excerpt['text'][0]])) | |
| 1378 | { | |
| 1379 | return array( | |
| 1380 | 'markup' => '&'.$SpecialCharacter[$Excerpt['text'][0]].';', | |
| 1381 | 'extent' => 1, | |
| 1382 | ); | |
| 1383 | } | |
| 1384 | } | |
| 1385 | ||
| 1386 | protected function inlineStrikethrough($Excerpt) | |
| 1387 | { | |
| 1388 | if ( ! isset($Excerpt['text'][1])) | |
| 1389 | { | |
| 1390 | return; | |
| 1391 | } | |
| 1392 | ||
| 1393 | if ($Excerpt['text'][1] === '~' and preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches)) | |
| 1394 | { | |
| 1395 | return array( | |
| 1396 | 'extent' => strlen($matches[0]), | |
| 1397 | 'element' => array( | |
| 1398 | 'name' => 'del', | |
| 1399 | 'text' => $matches[1], | |
| 1400 | 'handler' => 'line', | |
| 1401 | ), | |
| 1402 | ); | |
| 1403 | } | |
| 1404 | } | |
| 1405 | ||
| 1406 | protected function inlineUrl($Excerpt) | |
| 1407 | { | |
| 1408 | if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/') | |
| 1409 | { | |
| 1410 | return; | |
| 1411 | } | |
| 1412 | ||
| 1413 | if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE)) | |
| 1414 | { | |
| 1415 | $url = $matches[0][0]; | |
| 1416 | ||
| 1417 | $Inline = array( | |
| 1418 | 'extent' => strlen($matches[0][0]), | |
| 1419 | 'position' => $matches[0][1], | |
| 1420 | 'element' => array( | |
| 1421 | 'name' => 'a', | |
| 1422 | 'text' => $url, | |
| 1423 | 'attributes' => array( | |
| 1424 | 'href' => $url, | |
| 1425 | 'rel' => 'noopener,noreferrer', | |
| 1426 | 'target' => '_blank' | |
| 1427 | ), | |
| 1428 | ), | |
| 1429 | ); | |
| 1430 | ||
| 1431 | return $Inline; | |
| 1432 | } | |
| 1433 | } | |
| 1434 | ||
| 1435 | protected function inlineUrlTag($Excerpt) | |
| 1436 | { | |
| 1437 | if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches)) | |
| 1438 | { | |
| 1439 | $url = $matches[1]; | |
| 1440 | ||
| 1441 | return array( | |
| 1442 | 'extent' => strlen($matches[0]), | |
| 1443 | 'element' => array( | |
| 1444 | 'name' => 'a', | |
| 1445 | 'text' => $url, | |
| 1446 | 'attributes' => array( | |
| 1447 | 'href' => $url, | |
| 1448 | 'rel' => 'noopener,noreferrer', | |
| 1449 | 'target' => '_blank' | |
| 1450 | ), | |
| 1451 | ), | |
| 1452 | ); | |
| 1453 | } | |
| 1454 | } | |
| 1455 | ||
| 1456 | # ~ | |
| 1457 | ||
| 1458 | protected function unmarkedText($text) | |
| 1459 | { | |
| 1460 | if ($this->breaksEnabled) | |
| 1461 | { | |
| 1462 | $text = preg_replace('/[ ]*\n/', "<br />\n", $text); | |
| 1463 | } | |
| 1464 | else | |
| 1465 | { | |
| 1466 | $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text); | |
| 1467 | $text = str_replace(" \n", "\n", $text); | |
| 1468 | } | |
| 1469 | ||
| 1470 | return $text; | |
| 1471 | } | |
| 1472 | ||
| 1473 | # | |
| 1474 | # Handlers | |
| 1475 | # | |
| 1476 | ||
| 1477 | protected function element(array $Element) | |
| 1478 | { | |
| 1479 | if ($this->safeMode) | |
| 1480 | { | |
| 1481 | $Element = $this->sanitiseElement($Element); | |
| 1482 | } | |
| 1483 | ||
| 1484 | $markup = '<'.$Element['name']; | |
| 1485 | ||
| 1486 | if (isset($Element['attributes'])) | |
| 1487 | { | |
| 1488 | foreach ($Element['attributes'] as $name => $value) | |
| 1489 | { | |
| 1490 | if ($value === null) | |
| 1491 | { | |
| 1492 | continue; | |
| 1493 | } | |
| 1494 | ||
| 1495 | $markup .= ' '.$name.'="'.self::escape($value).'"'; | |
| 1496 | } | |
| 1497 | } | |
| 1498 | ||
| 1499 | $permitRawHtml = false; | |
| 1500 | ||
| 1501 | if (isset($Element['text'])) | |
| 1502 | { | |
| 1503 | $text = $Element['text']; | |
| 1504 | } | |
| 1505 | // very strongly consider an alternative if you're writing an | |
| 1506 | // extension | |
| 1507 | elseif (isset($Element['rawHtml'])) | |
| 1508 | { | |
| 1509 | $text = $Element['rawHtml']; | |
| 1510 | $allowRawHtmlInSafeMode = isset($Element['allowRawHtmlInSafeMode']) && $Element['allowRawHtmlInSafeMode']; | |
| 1511 | $permitRawHtml = !$this->safeMode || $allowRawHtmlInSafeMode; | |
| 1512 | } | |
| 1513 | ||
| 1514 | if (isset($text)) | |
| 1515 | { | |
| 1516 | $markup .= '>'; | |
| 1517 | ||
| 1518 | if (!isset($Element['nonNestables'])) | |
| 1519 | { | |
| 1520 | $Element['nonNestables'] = array(); | |
| 1521 | } | |
| 1522 | ||
| 1523 | if (isset($Element['handler'])) | |
| 1524 | { | |
| 1525 | $markup .= $this->{$Element['handler']}($text, $Element['nonNestables']); | |
| 1526 | } | |
| 1527 | elseif (!$permitRawHtml) | |
| 1528 | { | |
| 1529 | $markup .= self::escape($text, true); | |
| 1530 | } | |
| 1531 | else | |
| 1532 | { | |
| 1533 | $markup .= $text; | |
| 1534 | } | |
| 1535 | ||
| 1536 | $markup .= '</'.$Element['name'].'>'; | |
| 1537 | } | |
| 1538 | else | |
| 1539 | { | |
| 1540 | $markup .= ' />'; | |
| 1541 | } | |
| 1542 | ||
| 1543 | return $markup; | |
| 1544 | } | |
| 1545 | ||
| 1546 | protected function elements(array $Elements) | |
| 1547 | { | |
| 1548 | $markup = ''; | |
| 1549 | ||
| 1550 | foreach ($Elements as $Element) | |
| 1551 | { | |
| 1552 | $markup .= "\n" . $this->element($Element); | |
| 1553 | } | |
| 1554 | ||
| 1555 | $markup .= "\n"; | |
| 1556 | ||
| 1557 | return $markup; | |
| 1558 | } | |
| 1559 | ||
| 1560 | # ~ | |
| 1561 | ||
| 1562 | protected function li($lines) | |
| 1563 | { | |
| 1564 | $markup = $this->lines($lines); | |
| 1565 | ||
| 1566 | $trimmedMarkup = trim($markup); | |
| 1567 | ||
| 1568 | if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>') | |
| 1569 | { | |
| 1570 | $markup = $trimmedMarkup; | |
| 1571 | $markup = substr($markup, 3); | |
| 1572 | ||
| 1573 | $position = strpos($markup, "</p>"); | |
| 1574 | ||
| 1575 | $markup = substr_replace($markup, '', $position, 4); | |
| 1576 | } | |
| 1577 | ||
| 1578 | return $markup; | |
| 1579 | } | |
| 1580 | ||
| 1581 | # | |
| 1582 | # Deprecated Methods | |
| 1583 | # | |
| 1584 | ||
| 1585 | function parse($text) | |
| 1586 | { | |
| 1587 | $markup = $this->text($text); | |
| 1588 | ||
| 1589 | return $markup; | |
| 1590 | } | |
| 1591 | ||
| 1592 | protected function sanitiseElement(array $Element) | |
| 1593 | { | |
| 1594 | static $goodAttribute = '/^[a-zA-Z0-9][a-zA-Z0-9-_]*+$/'; | |
| 1595 | static $safeUrlNameToAtt = array( | |
| 1596 | 'a' => 'href', | |
| 1597 | 'img' => 'src', | |
| 1598 | ); | |
| 1599 | ||
| 1600 | if (isset($safeUrlNameToAtt[$Element['name']])) | |
| 1601 | { | |
| 1602 | $Element = $this->filterUnsafeUrlInAttribute($Element, $safeUrlNameToAtt[$Element['name']]); | |
| 1603 | } | |
| 1604 | ||
| 1605 | if ( ! empty($Element['attributes'])) | |
| 1606 | { | |
| 1607 | foreach ($Element['attributes'] as $att => $val) | |
| 1608 | { | |
| 1609 | # filter out badly parsed attribute | |
| 1610 | if ( ! preg_match($goodAttribute, $att)) | |
| 1611 | { | |
| 1612 | unset($Element['attributes'][$att]); | |
| 1613 | } | |
| 1614 | # dump onevent attribute | |
| 1615 | elseif (self::striAtStart($att, 'on')) | |
| 1616 | { | |
| 1617 | unset($Element['attributes'][$att]); | |
| 1618 | } | |
| 1619 | } | |
| 1620 | } | |
| 1621 | ||
| 1622 | return $Element; | |
| 1623 | } | |
| 1624 | ||
| 1625 | protected function filterUnsafeUrlInAttribute(array $Element, $attribute) | |
| 1626 | { | |
| 1627 | foreach ($this->safeLinksWhitelist as $scheme) | |
| 1628 | { | |
| 1629 | if (self::striAtStart($Element['attributes'][$attribute], $scheme)) | |
| 1630 | { | |
| 1631 | return $Element; | |
| 1632 | } | |
| 1633 | } | |
| 1634 | ||
| 1635 | $Element['attributes'][$attribute] = str_replace(':', '%3A', $Element['attributes'][$attribute]); | |
| 1636 | ||
| 1637 | return $Element; | |
| 1638 | } | |
| 1639 | ||
| 1640 | # | |
| 1641 | # Static Methods | |
| 1642 | # | |
| 1643 | ||
| 1644 | protected static function escape($text, $allowQuotes = false) | |
| 1645 | { | |
| 1646 | return htmlspecialchars($text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8'); | |
| 1647 | } | |
| 1648 | ||
| 1649 | protected static function striAtStart($string, $needle) | |
| 1650 | { | |
| 1651 | $len = strlen($needle); | |
| 1652 | ||
| 1653 | if ($len > strlen($string)) | |
| 1654 | { | |
| 1655 | return false; | |
| 1656 | } | |
| 1657 | else | |
| 1658 | { | |
| 1659 | return strtolower(substr($string, 0, $len)) === strtolower($needle); | |
| 1660 | } | |
| 1661 | } | |
| 1662 | ||
| 1663 | static function instance($name = 'default') | |
| 1664 | { | |
| 1665 | if (isset(self::$instances[$name])) | |
| 1666 | { | |
| 1667 | return self::$instances[$name]; | |
| 1668 | } | |
| 1669 | ||
| 1670 | $instance = new static(); | |
| 1671 | ||
| 1672 | self::$instances[$name] = $instance; | |
| 1673 | ||
| 1674 | return $instance; | |
| 1675 | } | |
| 1676 | ||
| 1677 | private static $instances = array(); | |
| 1678 | ||
| 1679 | # | |
| 1680 | # Fields | |
| 1681 | # | |
| 1682 | ||
| 1683 | protected $DefinitionData; | |
| 1684 | ||
| 1685 | # | |
| 1686 | # Read-Only | |
| 1687 | ||
| 1688 | protected $specialCharacters = array( | |
| 1689 | '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|', | |
| 1690 | ); | |
| 1691 | ||
| 1692 | protected $StrongRegex = array( | |
| 1693 | '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s', | |
| 1694 | '_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us', | |
| 1695 | ); | |
| 1696 | ||
| 1697 | protected $EmRegex = array( | |
| 1698 | '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s', | |
| 1699 | '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us', | |
| 1700 | ); | |
| 1701 | ||
| 1702 | protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*(?:\s*=\s*(?:[^"\'=<>`\s]+|"[^"]*"|\'[^\']*\'))?'; | |
| 1703 | ||
| 1704 | protected $voidElements = array( | |
| 1705 | 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', | |
| 1706 | ); | |
| 1707 | ||
| 1708 | protected $textLevelElements = array( | |
| 1709 | 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont', | |
| 1710 | 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing', | |
| 1711 | 'i', 'rp', 'del', 'code', 'strike', 'marquee', | |
| 1712 | 'q', 'rt', 'ins', 'font', 'strong', | |
| 1713 | 's', 'tt', 'kbd', 'mark', | |
| 1714 | 'u', 'xm', 'sub', 'nobr', | |
| 1715 | 'sup', 'ruby', | |
| 1716 | 'var', 'span', | |
| 1717 | 'wbr', 'time', | |
| 1718 | ); | |
| 1719 | } | |
_classes/Template.php added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | ||
| 4 | class Template | |
| 5 | { | |
| 6 | public function __construct(string $canonicalURL, string $pageDescription, string $pageTitle, string $pageExtras, string $contentCol, string $commentSection) | |
| 7 | { | |
| 8 | $this->canonicalURL = $canonicalURL; | |
| 9 | $this->description = $pageDescription; | |
| 10 | $this->title = $pageTitle; | |
| 11 | $this->extras = $pageExtras; | |
| 12 | $this->content = $contentCol; | |
| 13 | $this->comments = $commentSection; | |
| 14 | $this->currentYear = date("Y"); | |
| 15 | } | |
| 16 | ||
| 17 | public function echoTemplate() | |
| 18 | { | |
| 19 | // Get the template file | |
| 20 | $templateFile = '_templates/template.html'; | |
| 21 | $page = file_get_contents($templateFile); | |
| 22 | ||
| 23 | // Replace the template variables | |
| 24 | $page = str_replace('{Page_Title}', $this->title, $page); | |
| 25 | $page = str_replace('{Page_Description}', $this->description, $page); | |
| 26 | $page = str_replace('{Canonical_URL}', $this->canonicalURL, $page); | |
| 27 | $page = str_replace('{Page_Extras}', $this->extras, $page); | |
| 28 | $page = str_replace('{Content_Column}', $this->content, $page); | |
| 29 | $page = str_replace('{User_Comments}', $this->comments, $page); | |
| 30 | $page = str_replace('{Current_Year}', $this->currentYear, $page); | |
| 31 | ||
| 32 | // Echo the filled-out template | |
| 33 | echo $page; | |
| 34 | } | |
| 35 | } | |
| \ No newline at end of file | ||
_data/comments.json added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | [ | |
| 2 | { | |
| 3 | "timestamp": "2021-04-20 19:16:36", | |
| 4 | "username": "John Doe", | |
| 5 | "comment": "Lorem ipsum dolor sit amet!", | |
| 6 | "postURL": "https:\/\/blog.example.com\/post\/lorem-ipsum.html" | |
| 7 | }, | |
| 8 | { | |
| 9 | "timestamp": "2021-04-21 02:32:39", | |
| 10 | "username": "Jane Dow", | |
| 11 | "comment": "# Lorem Ipsum!", | |
| 12 | "postURL": "https:\/\/blog.example.com\/post\/example-syntax.html" | |
| 13 | } | |
| 14 | ] | |
_data/metadata.json added +24
| @@ -0,0 +1,24 @@ | ||
| 1 | [ | |
| 2 | { | |
| 3 | "id": "002", | |
| 4 | "title": "Syntax Possiblities", | |
| 5 | "author": "John Doe", | |
| 6 | "description": "Praesent maximus erat vitae arcu semper, sit amet euismod risus porta.", | |
| 7 | "tag": "security", | |
| 8 | "created": "2020-12-08 00:00:00", | |
| 9 | "modified": "2020-12-08 00:00:00", | |
| 10 | "link": "https:\/\/blog.example.com\/post\/example-syntax.html", | |
| 11 | "published": "Yes" | |
| 12 | }, | |
| 13 | { | |
| 14 | "id": "001", | |
| 15 | "title": "Lorem Ipsum", | |
| 16 | "author": "John Doe", | |
| 17 | "description": "Lorem ipsum dolor sit amet...", | |
| 18 | "tag": "writing", | |
| 19 | "created": "2018-11-28 00:00:00", | |
| 20 | "modified": "2018-11-28 00:00:00", | |
| 21 | "link": "https:\/\/blog.example.com\/post\/lorem-ipsum.html", | |
| 22 | "published": "Yes" | |
| 23 | } | |
| 24 | ] | |
_functions/loadJSON.php added +111
| @@ -0,0 +1,111 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | function loadHomepageJSON(string $fileName): string | |
| 4 | { | |
| 5 | // Get the file contents and decode JSON | |
| 6 | $fileContents = file_get_contents($fileName); | |
| 7 | $data = json_decode($fileContents); | |
| 8 | ||
| 9 | // Loop through the JSON object | |
| 10 | $stack = []; | |
| 11 | $metadata = ''; | |
| 12 | foreach ($data as $postObject) { | |
| 13 | // Only load published posts | |
| 14 | if ($postObject->published == 'Yes') { | |
| 15 | // Add relevant metadata to the output template | |
| 16 | $year = date_format(date_create($postObject->created), "Y"); | |
| 17 | if (!in_array($year, $stack)) { | |
| 18 | // If any posts have been created in a list, close the existing <ul> and open a new <ul> after the heading | |
| 19 | if (!empty($stack)) { | |
| 20 | $metadata .= '</ul>'; | |
| 21 | } | |
| 22 | $metadata .= '<h2 class="text-center">' . $year . '</h2><ul class="blog-posts">'; | |
| 23 | array_push($stack, $year); | |
| 24 | } | |
| 25 | $metadata .= '<li><time datetime=' . date_format(date_create($postObject->created), "Y-m-d") . '>' . date_format(date_create($postObject->created), "Y-m-d") . '</time><a href=' . $postObject->link . ' aria-label="Read ' . $postObject->title . ' blog post">' . $postObject->title . '</a></li>'; | |
| 26 | } | |
| 27 | } | |
| 28 | $metadata .= '</ul>'; | |
| 29 | return $metadata; | |
| 30 | } | |
| 31 | ||
| 32 | function loadCategoryJSON(string $fileName): string | |
| 33 | { | |
| 34 | // Get the file contents and decode JSON | |
| 35 | $fileContents = file_get_contents($fileName); | |
| 36 | $data = json_decode($fileContents); | |
| 37 | ||
| 38 | // Sort the JSON data by the `tag`, then by `create`. | |
| 39 | // I had to sort a -> b to get an "A-Z" sort for `tag`, | |
| 40 | // but b -> a to get a "first-last" sort for `create`. | |
| 41 | uasort($data, function ($a, $b) { | |
| 42 | return strcmp($a->tag, $b->tag) ?: strcmp($b->created, $a->created); | |
| 43 | }); | |
| 44 | ||
| 45 | // Loop through the JSON object | |
| 46 | $stack = []; | |
| 47 | $metadata = ''; | |
| 48 | foreach ($data as $postObject) { | |
| 49 | // Only load published posts | |
| 50 | if ($postObject->published == 'Yes') { | |
| 51 | // Add relevant metadata to the output template | |
| 52 | $category = str_replace('-', ' ', $postObject->tag); | |
| 53 | if (!in_array($category, $stack)) { | |
| 54 | // If any posts have been created in a list, close the existing <ul> and open a new <ul> after the heading | |
| 55 | if (!empty($stack)) { | |
| 56 | $metadata .= '</ul>'; | |
| 57 | } | |
| 58 | $metadata .= '<h2 id=' . $category . ' class="text-center">' . ucwords($category) . '</h2><ul class="blog-posts">'; | |
| 59 | array_push($stack, $category); | |
| 60 | } | |
| 61 | ||
| 62 | $metadata .= '<li><time datetime=' . date_format(date_create($postObject->created), "Y-m-d") . '>' . date_format(date_create($postObject->created), "Y-m-d") . '</time><a href=' . $postObject->link . ' aria-label="Read ' . $postObject->title . ' blog post">' . $postObject->title . '</a></li>'; | |
| 63 | } | |
| 64 | } | |
| 65 | $metadata .= '</ul>'; | |
| 66 | return $metadata; | |
| 67 | } | |
| 68 | ||
| 69 | function loadPostJSON(string $fileName, string $query) | |
| 70 | { | |
| 71 | // Get the file contents and decode JSON | |
| 72 | $fileContents = file_get_contents($fileName); | |
| 73 | $data = json_decode($fileContents); | |
| 74 | ||
| 75 | // Loop through the JSON object | |
| 76 | foreach ($data as $postObject) { | |
| 77 | // If this function is called to get a specific post's metadata, return the whole object | |
| 78 | if ($postObject->link == $GLOBALS['fullDomain'] . "/post/" . $query) { | |
| 79 | return $postObject; | |
| 80 | } | |
| 81 | } | |
| 82 | } | |
| 83 | ||
| 84 | function loadCommentJSON(string $fileName, string $query = null): string | |
| 85 | { | |
| 86 | // Set up an empty comment section | |
| 87 | $commentSection = ''; | |
| 88 | ||
| 89 | // Load the file and decode the JSON | |
| 90 | $fileContents = file_get_contents($fileName); | |
| 91 | $data = json_decode($fileContents); | |
| 92 | ||
| 93 | // Sort comments by date - latest comments will appear at the top | |
| 94 | uasort($data, function ($a, $b) { | |
| 95 | return strcmp($b->timestamp, $a->timestamp); | |
| 96 | }); | |
| 97 | ||
| 98 | // Loop through all comments add to returned string if it matches criteria | |
| 99 | foreach ($data as $commentObject) { | |
| 100 | if (($query !== null) && ($commentObject->postURL == $GLOBALS['fullDomain'] . "/post/" . $query)) { | |
| 101 | $securedHTML = parseMarkdown(null, $commentObject->comment); | |
| 102 | $commentSection .= '<div class="user-comment"><div class="row"><label>Timestamp:</label><p>' . $commentObject->timestamp . '</p></div><div class="row"><label>Name:</label><p>' . $commentObject->username . '</p></div><div class="row markdown"><label>Comment:</label><div class="comment-markdown">' . $securedHTML . '</div></div></div>'; | |
| 103 | } else if ($query == null) { | |
| 104 | $securedHTML = parseMarkdown(null, $commentObject->comment); | |
| 105 | $pageURL = str_replace($GLOBALS['fullDomain'] . '/post/', '', $commentObject->postURL); | |
| 106 | $postObject = loadPostJSON('_data/metadata.json', $pageURL); | |
| 107 | $commentSection .= '<div class="user-comment"><div class="row"><label>Post:</label><a href="' . $commentObject->postURL . '#comments">' . $postObject->title . '</a></div><div class="row"><label>Timestamp:</label><p>' . $commentObject->timestamp . '</p></div><div class="row"><label>Name:</label><p>' . $commentObject->username . '</p></div><div class="row markdown"><label>Comment:</label><div class="comment-markdown">' . $securedHTML . '</div></div></div>'; | |
| 108 | } | |
| 109 | } | |
| 110 | return $commentSection; | |
| 111 | } | |
| \ No newline at end of file | ||
_functions/loadRSS.php added +51
| @@ -0,0 +1,51 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | function loadRSS(string $fileName): string | |
| 4 | { | |
| 5 | // Get the file contents and decode JSON | |
| 6 | $fileContents = file_get_contents($fileName); | |
| 7 | $data = json_decode($fileContents); | |
| 8 | ||
| 9 | // Set-up RSS variables | |
| 10 | $rssCounter = 0; | |
| 11 | $rssContents = '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" | |
| 12 | ><channel><atom:link href="' . $GLOBALS['fullDomain'] . '/rss.xml" rel="self" type="application/rss+xml" /><title>Blog</title><link>' . $GLOBALS['fullDomain'] . '</link><description>Lorem ipsum dolor sit amet...</description><copyright>Copyright 20xx - 20xx, My Name</copyright><language>en-us</language><docs>https://cyber.harvard.edu/rss/index.html</docs><lastBuildDate>Mon, 04 Jan 2021 00:00:00 CST</lastBuildDate><ttl>60</ttl><image><url></url><title>Blog</title><link>'.$GLOBALS['fullDomain'].'</link></image>'; | |
| 13 | ||
| 14 | // Loop through the JSON object | |
| 15 | foreach ($data as $postObject) { | |
| 16 | // Only load published posts | |
| 17 | if ($postObject->published == 'Yes') { | |
| 18 | // Parse the markdown to HTML | |
| 19 | include_once('_functions/parseMarkdown.php'); | |
| 20 | $fileLink = str_replace($GLOBALS['fullDomain'] . '/post/', '', $postObject->link); | |
| 21 | $fileName = 'posts/' . $postObject->id . '-' . str_replace('.html', '.md', $fileLink); | |
| 22 | $securedHTML = parseMarkdown($fileName); | |
| 23 | ||
| 24 | if ($rssCounter == 0) { | |
| 25 | $rssContents .= '<lastBuildDate>' . date_format(date_create($postObject->created), 'D, d M Y H:i:s T') . '</lastBuildDate>'; | |
| 26 | $rssCounter = $rssCounter + 1; | |
| 27 | } | |
| 28 | ||
| 29 | $rssContents .= | |
| 30 | '<item><title>' . | |
| 31 | str_replace(['&', '<', '>'], ['&', '<', '>'], $postObject->title) . | |
| 32 | '</title><author>' . | |
| 33 | str_replace(['&', '<', '>'], ['&', '<', '>'], $postObject->author) . | |
| 34 | '</author><dc:creator>' . | |
| 35 | str_replace(['&', '<', '>'], ['&', '<', '>'], $postObject->author) . | |
| 36 | '</dc:creator><link>' . | |
| 37 | str_replace(['&', '<', '>'], ['&', '<', '>'], $postObject->link) . | |
| 38 | '</link><pubDate>' . | |
| 39 | date_format(date_create($postObject->created), 'D, d M Y H:i:s T') . | |
| 40 | '</pubDate><guid>' . | |
| 41 | str_replace(['&', '<', '>'], ['&', '<', '>'], $postObject->link) . | |
| 42 | '</guid><description><![CDATA[' . | |
| 43 | $postObject->description . | |
| 44 | ']]></description><content:encoded><![CDATA[' . | |
| 45 | $securedHTML . | |
| 46 | ']]></content:encoded></item>'; | |
| 47 | } | |
| 48 | } | |
| 49 | $rssContents .= '</channel></rss>'; | |
| 50 | return $rssContents; | |
| 51 | } | |
| \ No newline at end of file | ||
_functions/parseMarkdown.php added +21
| @@ -0,0 +1,21 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | function parseMarkdown(string $fileName = null, string $fileContents = null) | |
| 4 | { | |
| 5 | if ($fileName != null) { | |
| 6 | // Get file contents | |
| 7 | $fileContents = file_get_contents('/var/www/' . $GLOBALS['shortDomain'] . '/' . $fileName, FILE_USE_INCLUDE_PATH); | |
| 8 | } | |
| 9 | ||
| 10 | // Parse the markdown to HTML | |
| 11 | include_once('_classes/Parsedown.php'); | |
| 12 | $md = Parsedown::instance()->text($fileContents); | |
| 13 | $html = new DOMDocument(); | |
| 14 | $html->loadHTML($md); | |
| 15 | $html_links = $html->getElementsByTagName('a'); | |
| 16 | foreach ($html_links as $html_ink) { | |
| 17 | $html_ink->setAttribute('rel', 'noopener,noreferrer'); | |
| 18 | $html_ink->setAttribute('target', '_blank'); | |
| 19 | } | |
| 20 | return $html->saveHTML(); | |
| 21 | } | |
| \ No newline at end of file | ||
_functions/submitComment.php added +25
| @@ -0,0 +1,25 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | function submitComment() | |
| 4 | { | |
| 5 | // Get the content sent from the comment form | |
| 6 | $comment = htmlentities($_POST['userContent']); | |
| 7 | $postURL = $_POST['postURL']; | |
| 8 | ||
| 9 | // Set default values if blank | |
| 10 | if (isset($_POST['userName']) && trim($_POST['userName']) !== "") { | |
| 11 | $username = $_POST['userName']; | |
| 12 | } else { | |
| 13 | $username = null; | |
| 14 | } | |
| 15 | ||
| 16 | // Create a 'Comment' object | |
| 17 | include_once('_classes/Comment.php'); | |
| 18 | $userComment = new Comment($comment, $postURL, $username); | |
| 19 | ||
| 20 | // Append comment to JSON file | |
| 21 | $userComment->saveComment('_data/comments.json'); | |
| 22 | ||
| 23 | // Send the user back | |
| 24 | header('Location: ' . $postURL . '#comments'); | |
| 25 | } | |
| \ No newline at end of file | ||
_templates/template.html added +40
| @@ -0,0 +1,40 @@ | ||
| 1 | <!doctype html> | |
| 2 | <html lang="en"> | |
| 3 | ||
| 4 | <head> | |
| 5 | <title>{Page_Title}</title> | |
| 6 | <meta charset="UTF-8"> | |
| 7 | <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
| 8 | <meta http-equiv="x-ua-compatible" content="ie=edge"> | |
| 9 | <meta name="author" content="My Name"> | |
| 10 | <meta name="description" content="{Page_Description}"> | |
| 11 | <link rel="canonical" href="{Canonical_URL}"> | |
| 12 | <link rel="icon" href="/favicon.ico"> | |
| 13 | <link rel="stylesheet" href="/static/app.css"> | |
| 14 | {Page_Extras} | |
| 15 | </head> | |
| 16 | ||
| 17 | <body> | |
| 18 | <main id="main"> | |
| 19 | <nav class="links"> | |
| 20 | <span>[<a href="/">Home</a>]</span> | |
| 21 | <span>[<a href="/categories/">Categories</a>]</span> | |
| 22 | <span>[<a href="/comments/">Comments</a>]</span> | |
| 23 | <span>[<a href="/rss.xml">RSS</a>]</span> | |
| 24 | </nav> | |
| 25 | {Content_Column} | |
| 26 | {User_Comments} | |
| 27 | </main> | |
| 28 | ||
| 29 | <footer> | |
| 30 | <h2>Contact</h2> | |
| 31 | <p>Have questions? Email me <br> | |
| 32 | at <a href="mailto:hello@example.com">hello@example.com</a>,<br> | |
| 33 | message me on <a rel="me" href="https://floss.social/@example">Mastodon</a>,<br> | |
| 34 | or open an issue on <a href="https://github.com/WittsEnd2/Example_Repo">GitHub</a>.</p> | |
| 35 | <p>Copyright © 20xx - {Current_Year}</p> | |
| 36 | </footer> | |
| 37 | ||
| 38 | </body> | |
| 39 | ||
| 40 | </html> | |
favicon.ico added
Binary file not shown.
index.php added +189
| @@ -0,0 +1,189 @@ | ||
| 1 | <?php | |
| 2 | ||
| 3 | // Set global variables for this specific website | |
| 4 | // Domains must match the URLs in the _data files | |
| 5 | $websiteProtocol = 'https://'; | |
| 6 | $shortDomain = 'blog.example.com'; | |
| 7 | $fullDomain = $websiteProtocol . $shortDomain; | |
| 8 | ||
| 9 | // Trim the leading slashes & split the path on slashes | |
| 10 | $path = ltrim($_SERVER['REQUEST_URI'], '/'); | |
| 11 | $elements = explode('/', $path); | |
| 12 | ||
| 13 | // Show home if there are no parameters or paths | |
| 14 | if (empty($elements[0])) { | |
| 15 | showHomepage(); | |
| 16 | } // Else, identify the first item in the URL so we can identify which function to use | |
| 17 | else { | |
| 18 | switch (array_shift($elements)) { | |
| 19 | case 'post': | |
| 20 | showPost($elements); | |
| 21 | break; | |
| 22 | case 'submit-comment': | |
| 23 | include_once('_functions/submitComment.php'); | |
| 24 | submitComment(); | |
| 25 | break; | |
| 26 | case 'comments': | |
| 27 | showComments(); | |
| 28 | break; | |
| 29 | case 'category': | |
| 30 | header('Location: ' . $fullDomain . '/categories/'); | |
| 31 | die(); | |
| 32 | case 'categories': | |
| 33 | showCategory(); | |
| 34 | break; | |
| 35 | case 'rss': | |
| 36 | case 'rss.xml': | |
| 37 | showRSS(); | |
| 38 | break; | |
| 39 | case 'robots.txt': | |
| 40 | showRobots(); | |
| 41 | break; | |
| 42 | default: | |
| 43 | header('HTTP/1.1 404 Not Found'); | |
| 44 | } | |
| 45 | } | |
| 46 | ||
| 47 | function showHomepage() | |
| 48 | { | |
| 49 | // Add Articles | |
| 50 | $contentCol = '<h1>My Blog</h1>'; | |
| 51 | ||
| 52 | // Get metadata on all posts from the metadata.json file | |
| 53 | include_once('_functions/loadJSON.php'); | |
| 54 | $contentCol .= loadHomepageJSON('_data/metadata.json'); | |
| 55 | ||
| 56 | // Create a template | |
| 57 | include_once('_classes/Template.php'); | |
| 58 | $template = new Template( | |
| 59 | $GLOBALS['fullDomain'], | |
| 60 | 'Explore the thoughts of...', | |
| 61 | 'Blog | YourName', | |
| 62 | '', | |
| 63 | $contentCol, | |
| 64 | '' | |
| 65 | ); | |
| 66 | ||
| 67 | // Echo the HTML to the user | |
| 68 | $template->echoTemplate(); | |
| 69 | } | |
| 70 | ||
| 71 | function showPost($params) | |
| 72 | { | |
| 73 | // URL Parameter | |
| 74 | $query = $params[0]; | |
| 75 | ||
| 76 | // Get metadata on this post from the metadata.json file | |
| 77 | include_once('_functions/loadJSON.php'); | |
| 78 | $headerData = loadPostJSON('_data/metadata.json', $query); | |
| 79 | ||
| 80 | // Apply metadata to post header | |
| 81 | $header = '<header><h1 class="blog-post-title">' . $headerData->title . '</h1><div class="blog-post-metadata"><time class="d-inline" datetime="' . date_format(date_create($headerData->created), "Y-m-d") . '">' . date_format(date_create($headerData->created), "Y-m-d") . '</time><span style="margin:0 0.5rem;">::</span><a href="' . $GLOBALS['fullDomain'] . '/categories/#' . $headerData->tag . '">#' . $headerData->tag . '</a></div></header>'; | |
| 82 | ||
| 83 | // Get post .md file that matches the .html file requested in the URL | |
| 84 | include_once('_functions/parseMarkdown.php'); | |
| 85 | $fileName = './posts/' . $headerData->id . '-' . str_replace('.html', '.md', $query); | |
| 86 | $securedHTML = parseMarkdown($fileName); | |
| 87 | ||
| 88 | // Echo Results | |
| 89 | $contentCol = '<article class="blog-post">' . $header . '<section class="blog-post-body">' . $securedHTML . '</section></article>'; | |
| 90 | ||
| 91 | // Create a comment section | |
| 92 | $postURL = $GLOBALS['fullDomain'] . '/post/' . $query; | |
| 93 | $commentForm = '<form action="/submit-comment/" method="POST"><h3>Leave a Comment</h3><section hidden><label class="form-label" for="postURL">Post URL</label><input class="form-control" id="postURL" name="postURL" type="text" value="' . $postURL . '"></section><section><label class="form-label" for="userName">Display Name</label><input class="form-control" id="userName" name="userName" placeholder="John Doe" type="text"></section><section><label class="form-label" for="userContent">Your Comment</label><textarea class="form-control" id="userContent" name="userContent" rows="3" placeholder="# Feel free to use Markdown" aria-describedby="commentHelp" required></textarea><div id="commentHelp" class="form-text">Comments are saved as Markdown and cannot be edited or deleted.</div></section><button type="submit">Submit</button></form>'; | |
| 94 | ||
| 95 | // Load saved comments | |
| 96 | $userComments = '<section id="comments" class="comments"><h3>Comments</h3>'; | |
| 97 | $userComments .= loadCommentJSON('_data/comments.json', $query); | |
| 98 | $userComments .= '</section>'; | |
| 99 | ||
| 100 | // Combine comment form and previous user comments | |
| 101 | $commentSection = $commentForm . $userComments; | |
| 102 | ||
| 103 | // Create a template | |
| 104 | include_once('_classes/Template.php'); | |
| 105 | $template = new Template( | |
| 106 | $GLOBALS['fullDomain'] . '/post/' . $query, | |
| 107 | $headerData->description . ' Read more at ' . $GLOBALS['fullDomain'] . '!', | |
| 108 | $headerData->title . ' | Blog', | |
| 109 | '<link rel="stylesheet" href="/static/prism.css"><script src="/static/prism.js"></script>', | |
| 110 | $contentCol, | |
| 111 | $commentSection | |
| 112 | ); | |
| 113 | ||
| 114 | // Echo the HTML to the user | |
| 115 | $template->echoTemplate(); | |
| 116 | } | |
| 117 | ||
| 118 | function showComments() | |
| 119 | { | |
| 120 | // Add title | |
| 121 | $commentHeader = '<h1>Recent Comments</h1>'; | |
| 122 | ||
| 123 | // Load saved comments | |
| 124 | include_once('_functions/parseMarkdown.php'); | |
| 125 | include_once('_functions/loadJSON.php'); | |
| 126 | $userComments = '<section id="comments" class="comments"><h3>Comments Across All Blog Posts</h3>'; | |
| 127 | $userComments .= loadCommentJSON('_data/comments.json'); | |
| 128 | $userComments .= '</section>'; | |
| 129 | ||
| 130 | // Combine comment form and previous user comments | |
| 131 | $commentSection = $commentHeader . $userComments; | |
| 132 | ||
| 133 | // Create a template | |
| 134 | include_once('_classes/Template.php'); | |
| 135 | $template = new Template( | |
| 136 | $GLOBALS['fullDomain'] . '/comments/', | |
| 137 | 'Read through some recent comments for blog posts at ' . $GLOBALS['fullDomain'] . '.', | |
| 138 | 'Recent Comments | Blog', | |
| 139 | '<link rel="stylesheet" href="/static/prism.css"><script src="/static/prism.js"></script><meta name="robots" content="noindex,nofollow">', | |
| 140 | '', | |
| 141 | $commentSection | |
| 142 | ); | |
| 143 | ||
| 144 | // Echo the HTML to the user | |
| 145 | $template->echoTemplate(); | |
| 146 | } | |
| 147 | ||
| 148 | function showCategory() | |
| 149 | { | |
| 150 | // Open the article list | |
| 151 | $contentCol = '<h1>Categories</h1>'; | |
| 152 | ||
| 153 | // Get metadata on all posts from the metadata.json file | |
| 154 | include_once('_functions/loadJSON.php'); | |
| 155 | $contentCol .= loadCategoryJSON('_data/metadata.json'); | |
| 156 | ||
| 157 | // Create a template | |
| 158 | include_once('_classes/Template.php'); | |
| 159 | $template = new Template( | |
| 160 | $GLOBALS['fullDomain'] . '/categories/', | |
| 161 | 'Browse the categories for blog posts at ' . $GLOBALS['fullDomain'] . '.', | |
| 162 | 'Categories | Blog', | |
| 163 | '<meta name="robots" content="noindex,nofollow">', | |
| 164 | $contentCol, | |
| 165 | '' | |
| 166 | ); | |
| 167 | ||
| 168 | // Echo the HTML to the user | |
| 169 | $template->echoTemplate(); | |
| 170 | } | |
| 171 | ||
| 172 | function showRSS() | |
| 173 | { | |
| 174 | // Loop through the metadata file and display any article that is published | |
| 175 | include_once('_functions/loadRSS.php'); | |
| 176 | $rssContents = loadRSS('_data/metadata.json'); | |
| 177 | ||
| 178 | // Echo the RSS XML | |
| 179 | header('Content-type: text/xml'); | |
| 180 | echo $rssContents; | |
| 181 | die(); | |
| 182 | } | |
| 183 | ||
| 184 | function showRobots() | |
| 185 | { | |
| 186 | header('Content-type: text/plain'); | |
| 187 | echo 'User-agent: * Disallow:'; | |
| 188 | die(); | |
| 189 | } | |
posts/001-lorem-ipsum.md added +42
| @@ -0,0 +1,42 @@ | ||
| 1 | ## Lorem Ipsum | |
| 2 | ||
| 3 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam aliquet lectus et elit pretium placerat. Etiam dolor | |
| 4 | nunc, varius vitae mattis eleifend, malesuada in eros. Suspendisse vulputate porta ex non ornare. Praesent lorem libero, | |
| 5 | maximus consequat mattis vitae, egestas at tellus. Nam suscipit felis libero, facilisis tempus elit mattis eu. Maecenas | |
| 6 | in luctus quam. Cras egestas, odio tincidunt bibendum tincidunt, enim dui feugiat eros, sed eleifend risus eros sed | |
| 7 | eros. Quisque ullamcorper sollicitudin arcu in convallis. Donec leo ligula, rutrum at tempus vitae, viverra at mi. Nunc | |
| 8 | diam odio, laoreet ut euismod nec, rhoncus ac sem. Phasellus consectetur in ante cursus consequat. Curabitur ac luctus | |
| 9 | justo, at posuere ante. Sed tempus eros quis malesuada efficitur. Curabitur gravida placerat felis, non maximus tortor | |
| 10 | mattis at. | |
| 11 | ||
| 12 | ## Praesent Maximus | |
| 13 | ||
| 14 | Praesent maximus erat vitae arcu semper, sit amet euismod risus porta. Praesent vel enim cursus, tincidunt erat non, | |
| 15 | hendrerit nisi. Maecenas id facilisis felis, scelerisque egestas erat. Sed volutpat, orci ac pulvinar volutpat, neque | |
| 16 | turpis posuere ipsum, mattis hendrerit velit magna ac tellus. Vestibulum eget ullamcorper dui, ac dictum diam. | |
| 17 | Pellentesque sed ex sapien. Sed ullamcorper aliquam fringilla. Pellentesque id tincidunt augue, aliquet porttitor arcu. | |
| 18 | Nullam sed mi id arcu posuere varius. Morbi maximus ligula sit amet lorem blandit lobortis. Cras feugiat risus id magna | |
| 19 | consequat, vitae mollis purus efficitur. | |
| 20 | ||
| 21 | ### Nullam Quis | |
| 22 | ||
| 23 | Nullam quis tortor sem. Nunc dictum augue eget mattis molestie. Interdum et malesuada fames ac ante ipsum primis in | |
| 24 | faucibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Donec at imperdiet | |
| 25 | ligula. Nulla rutrum in metus eu elementum. Morbi vehicula purus eget fermentum feugiat. Sed at metus nec ipsum sagittis | |
| 26 | dictum. Praesent quam augue, mollis vel pellentesque eget, fermentum sit amet urna. Mauris eget erat vitae libero | |
| 27 | hendrerit molestie. Duis sollicitudin sodales purus ac ornare. Proin ac ultrices ex. Pellentesque sollicitudin dolor non | |
| 28 | arcu lobortis aliquam. Maecenas vehicula, urna eget pellentesque varius, sapien purus porta lectus, id maximus quam | |
| 29 | sapien elementum mauris. Suspendisse et velit non purus feugiat malesuada ac a enim. | |
| 30 | ||
| 31 | Maecenas egestas ante vitae dignissim volutpat. Vivamus non mollis odio. Curabitur magna ligula, egestas at finibus ac, | |
| 32 | pretium at justo. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec bibendum ante nec suscipit | |
| 33 | viverra. Sed in risus neque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sem nisl, eleifend id | |
| 34 | euismod in, cursus sed dui. In luctus ipsum a ipsum imperdiet, ac eleifend magna fringilla. Integer commodo volutpat | |
| 35 | pharetra. Quisque vulputate fringilla libero, a vestibulum ante mollis in. Quisque sodales purus ipsum, a mattis justo | |
| 36 | rhoncus at. | |
| 37 | ||
| 38 | #### Mauris Suscipit | |
| 39 | ||
| 40 | Mauris suscipit rutrum ipsum quis maximus. Nulla facilisi. Etiam venenatis enim a ligula rutrum porta. Sed dictum nibh a | |
| 41 | elit iaculis, quis volutpat tortor vehicula. Ut sit amet mi turpis. Aenean imperdiet ullamcorper velit, eu pharetra | |
| 42 | magna rhoncus id. Curabitur id ornare ligula. Maecenas finibus dignissim nisl, eget feugiat lorem blandit nec. | |
posts/002-example-syntax.md added +77
| @@ -0,0 +1,77 @@ | ||
| 1 | ## Syntax Possiblities | |
| 2 | ||
| 3 | Please see the [GitHub Flavored Markdown specs](https://github.github.com/gfm/) and | |
| 4 | the [parsedown](https://github.com/erusev/parsedown) repository for more specific details on Markdown possiblities. | |
| 5 | ||
| 6 | --- | |
| 7 | ||
| 8 | Headings: | |
| 9 | ||
| 10 | # Heading - Level 1 | |
| 11 | ||
| 12 | ## Heading - Level 2 | |
| 13 | ||
| 14 | ### Heading - Level 3 | |
| 15 | ||
| 16 | #### Heading - Level 4 | |
| 17 | ||
| 18 | ##### Heading - Level 5 | |
| 19 | ||
| 20 | ###### Heading - Level 6 | |
| 21 | ||
| 22 | --- | |
| 23 | ||
| 24 | Formatted Text: | |
| 25 | ||
| 26 | **Bold text** | |
| 27 | *Italics* | |
| 28 | ~~strikethrough~~ | |
| 29 | [a simple link](https://example.com) | |
| 30 | ||
| 31 | --- | |
| 32 | ||
| 33 | Blockquotes: | |
| 34 | ||
| 35 | > # Foo | |
| 36 | > bar | |
| 37 | > baz | |
| 38 | ||
| 39 | --- | |
| 40 | ||
| 41 | Lists: | |
| 42 | ||
| 43 | 1. one | |
| 44 | 2. two | |
| 45 | 3. three | |
| 46 | 1. sub-bullet | |
| 47 | ||
| 48 | - unordered one | |
| 49 | - unordered two | |
| 50 | ||
| 51 | --- | |
| 52 | ||
| 53 | Code Blocks: | |
| 54 | ||
| 55 | ```html | |
| 56 | <!doctype html> | |
| 57 | <html lang="en"> | |
| 58 | <head> | |
| 59 | <meta charset="utf-8"> | |
| 60 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| 61 | <title>Hello, world!</title> | |
| 62 | </head> | |
| 63 | <body> | |
| 64 | <h1>Hello, world!</h1> | |
| 65 | </body> | |
| 66 | </html> | |
| 67 | ``` | |
| 68 | ||
| 69 | --- | |
| 70 | ||
| 71 | Tables: | |
| 72 | ||
| 73 | | foo | bar | | |
| 74 | | --- | --- | | |
| 75 | | baz | bim | | |
| 76 | ||
| 77 | --- | |
static/app.css added +274
| @@ -0,0 +1,274 @@ | ||
| 1 | :root { | |
| 2 | --bg0: #121212; | |
| 3 | --bg1: #202020; | |
| 4 | --bg2: #3b3b3b; | |
| 5 | --bg3: #5b5b5b; | |
| 6 | --fg0: #ffffff; | |
| 7 | --fg1: #cccccc; | |
| 8 | --fg2: #9aa0a7; | |
| 9 | --fg3: #fce21b; | |
| 10 | --fg4: #e2cb18; | |
| 11 | --fg3-5: rgba(252, 226, 27, 0.5); | |
| 12 | --fg3-8: rgba(252, 226, 27, 0.8); | |
| 13 | --fg3-25: rgba(252, 226, 27, 0.25) | |
| 14 | } | |
| 15 | ||
| 16 | *, ::after, ::before { | |
| 17 | box-sizing: border-box | |
| 18 | } | |
| 19 | ||
| 20 | html { | |
| 21 | font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; | |
| 22 | scroll-behavior: smooth | |
| 23 | } | |
| 24 | ||
| 25 | body { | |
| 26 | background-color: var(--bg0); | |
| 27 | color: var(--fg1); | |
| 28 | font-size: 1rem; | |
| 29 | font-weight: 400; | |
| 30 | line-height: 1.5; | |
| 31 | margin: 0; | |
| 32 | -webkit-text-size-adjust: 100% | |
| 33 | } | |
| 34 | ||
| 35 | h1, h2, h3, h4, h5, h6 { | |
| 36 | color: white; | |
| 37 | font-family: mSFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; | |
| 38 | } | |
| 39 | ||
| 40 | time { | |
| 41 | display: block; | |
| 42 | font-family: mSFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; | |
| 43 | margin: 0 | |
| 44 | } | |
| 45 | ||
| 46 | time.d-inline { | |
| 47 | display: inline | |
| 48 | } | |
| 49 | ||
| 50 | blockquote { | |
| 51 | background: var(--bg2); | |
| 52 | color: var(--fg0); | |
| 53 | border-left: 5px solid var(--fg3); | |
| 54 | margin: 1rem auto; | |
| 55 | padding: 1rem 2rem | |
| 56 | } | |
| 57 | ||
| 58 | blockquote p { | |
| 59 | margin: 0 | |
| 60 | } | |
| 61 | ||
| 62 | a { | |
| 63 | color: var(--fg3); | |
| 64 | font-family: mSFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; | |
| 65 | } | |
| 66 | ||
| 67 | .img-fluid { | |
| 68 | border: 1px solid var(--bg3); | |
| 69 | max-width: 100%; | |
| 70 | height: auto | |
| 71 | } | |
| 72 | ||
| 73 | kbd, ode, pre, samp { | |
| 74 | font-family: mSFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; | |
| 75 | font-size: 1em; | |
| 76 | direction: ltr; | |
| 77 | unicode-bidi: bidi-override | |
| 78 | } | |
| 79 | ||
| 80 | pre { | |
| 81 | background-color: var(--bg2); | |
| 82 | color: var(--fg0); | |
| 83 | display: block; | |
| 84 | margin-top: 0; | |
| 85 | margin-bottom: 1rem; | |
| 86 | overflow: auto; | |
| 87 | padding: 1rem; | |
| 88 | border-radius: 0.25rem | |
| 89 | } | |
| 90 | ||
| 91 | pre code { | |
| 92 | font-size: inherit; | |
| 93 | color: inherit; | |
| 94 | word-break: normal | |
| 95 | } | |
| 96 | ||
| 97 | code { | |
| 98 | color: #d63384; | |
| 99 | word-wrap: break-word | |
| 100 | } | |
| 101 | ||
| 102 | a > code { | |
| 103 | color: inherit | |
| 104 | } | |
| 105 | ||
| 106 | kbd { | |
| 107 | padding: 0.2rem 0.4rem; | |
| 108 | color: var(--fg0); | |
| 109 | background-color: #212529; | |
| 110 | border-radius: 0.2rem | |
| 111 | } | |
| 112 | ||
| 113 | kbd kbd { | |
| 114 | padding: 0; | |
| 115 | font-size: 1em; | |
| 116 | font-weight: 700 | |
| 117 | } | |
| 118 | ||
| 119 | nav.links { | |
| 120 | margin-bottom: 2rem; | |
| 121 | margin-top: 2rem; | |
| 122 | text-align: center | |
| 123 | } | |
| 124 | ||
| 125 | footer, main { | |
| 126 | margin: auto; | |
| 127 | max-width: 45em; | |
| 128 | padding: 2rem | |
| 129 | } | |
| 130 | ||
| 131 | footer { | |
| 132 | border-top: 1px solid var(--bg3); | |
| 133 | font-family: mSFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; | |
| 134 | } | |
| 135 | ||
| 136 | @media (max-width: 576px) { | |
| 137 | body { | |
| 138 | margin: 0 | |
| 139 | } | |
| 140 | ||
| 141 | footer, main { | |
| 142 | padding-left: 1rem; | |
| 143 | padding-right: 1rem | |
| 144 | } | |
| 145 | } | |
| 146 | ||
| 147 | ul.blog-posts { | |
| 148 | list-style: none; | |
| 149 | padding: 0 | |
| 150 | } | |
| 151 | ||
| 152 | ul.blog-posts li { | |
| 153 | margin-bottom: 1rem | |
| 154 | } | |
| 155 | ||
| 156 | @media (max-width: 576px) { | |
| 157 | .blog-post { | |
| 158 | border-radius: 0 | |
| 159 | } | |
| 160 | } | |
| 161 | ||
| 162 | .blog-post-body li, .blog-post-body p { | |
| 163 | color: #ddd | |
| 164 | } | |
| 165 | ||
| 166 | .blog-post-body a { | |
| 167 | color: var(--fg3); | |
| 168 | font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; | |
| 169 | } | |
| 170 | ||
| 171 | .blog-post-title { | |
| 172 | display: block; | |
| 173 | font-weight: bold; | |
| 174 | position: relative; | |
| 175 | margin: 0 0 15px; | |
| 176 | padding-bottom: 15px; | |
| 177 | border-bottom: 3px dotted var(--fg3) | |
| 178 | } | |
| 179 | ||
| 180 | .blog-post-title::after { | |
| 181 | content: ""; | |
| 182 | position: absolute; | |
| 183 | bottom: 2px; | |
| 184 | display: block; | |
| 185 | width: 100%; | |
| 186 | border-bottom: 3px dotted var(--fg3) | |
| 187 | } | |
| 188 | ||
| 189 | .blog-post-metadata a { | |
| 190 | color: var(--fg3) | |
| 191 | } | |
| 192 | ||
| 193 | .blog-post-body h2 { | |
| 194 | margin-top: 2rem | |
| 195 | } | |
| 196 | ||
| 197 | .form-label { | |
| 198 | margin-bottom: 0.5rem | |
| 199 | } | |
| 200 | ||
| 201 | .form-text { | |
| 202 | color: #ccc; | |
| 203 | margin-top: 0.25rem; | |
| 204 | font-size: 0.875em | |
| 205 | } | |
| 206 | ||
| 207 | .form-control { | |
| 208 | display: block; | |
| 209 | width: 100%; | |
| 210 | padding: 0.375rem 0.75rem; | |
| 211 | font-size: 1rem; | |
| 212 | font-weight: 400; | |
| 213 | line-height: 1.5; | |
| 214 | color: #fff; | |
| 215 | background-color: #5b5b5b; | |
| 216 | background-clip: padding-box; | |
| 217 | border: 1px solid #5b5b5b; | |
| 218 | -webkit-appearance: none; | |
| 219 | -moz-appearance: none; | |
| 220 | appearance: none; | |
| 221 | border-radius: 0.25rem; | |
| 222 | transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out | |
| 223 | } | |
| 224 | ||
| 225 | @media (prefers-reduced-motion: reduce) { | |
| 226 | .form-control { | |
| 227 | transition: none | |
| 228 | } | |
| 229 | } | |
| 230 | ||
| 231 | form { | |
| 232 | background-color: #3b3b3b; | |
| 233 | border-radius: 0.5rem; | |
| 234 | margin-top: 2rem; | |
| 235 | padding: 1rem | |
| 236 | } | |
| 237 | ||
| 238 | form section { | |
| 239 | margin-bottom: 1rem | |
| 240 | } | |
| 241 | ||
| 242 | textarea { | |
| 243 | font-family: inherit | |
| 244 | } | |
| 245 | ||
| 246 | .comments { | |
| 247 | background-color: #3b3b3b; | |
| 248 | border-radius: 0.5rem; | |
| 249 | margin-top: 1rem; | |
| 250 | padding: 1rem | |
| 251 | } | |
| 252 | ||
| 253 | .user-comment { | |
| 254 | background-color: var(--bg3); | |
| 255 | border-radius: 0.5rem; | |
| 256 | padding: 0.5rem; | |
| 257 | margin-bottom: 0.5rem | |
| 258 | } | |
| 259 | ||
| 260 | .user-comment .row:not(.markdown) { | |
| 261 | display: flex; | |
| 262 | justify-content: flex-start; | |
| 263 | align-items: center | |
| 264 | } | |
| 265 | ||
| 266 | .user-comment .row label { | |
| 267 | color: var(--fg1); | |
| 268 | margin-right: 0.25rem | |
| 269 | } | |
| 270 | ||
| 271 | .user-comment .row p { | |
| 272 | color: var(--fg0); | |
| 273 | margin: 0 | |
| 274 | } | |
| \ No newline at end of file | ||
static/prism.css added +125
| @@ -0,0 +1,125 @@ | ||
| 1 | /* PrismJS 1.23.0 | |
| 2 | https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript+bash+markdown+markup-templating+php+python+yaml */ | |
| 3 | /** | |
| 4 | * prism.js tomorrow night eighties for JavaScript, CoffeeScript, CSS and HTML | |
| 5 | * Based on https://github.com/chriskempson/tomorrow-theme | |
| 6 | * @author Rose Pritchard | |
| 7 | */ | |
| 8 | ||
| 9 | code[class*="language-"], | |
| 10 | pre[class*="language-"] { | |
| 11 | color: #ccc; | |
| 12 | background: none; | |
| 13 | /* font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; */ | |
| 14 | font-size: 1em; | |
| 15 | text-align: left; | |
| 16 | white-space: pre; | |
| 17 | word-spacing: normal; | |
| 18 | word-break: normal; | |
| 19 | word-wrap: normal; | |
| 20 | line-height: 1.5; | |
| 21 | ||
| 22 | -moz-tab-size: 4; | |
| 23 | -o-tab-size: 4; | |
| 24 | tab-size: 4; | |
| 25 | ||
| 26 | -webkit-hyphens: none; | |
| 27 | -moz-hyphens: none; | |
| 28 | -ms-hyphens: none; | |
| 29 | hyphens: none; | |
| 30 | ||
| 31 | } | |
| 32 | ||
| 33 | /* Code blocks */ | |
| 34 | pre[class*="language-"] { | |
| 35 | padding: 1em; | |
| 36 | margin: .5em 0; | |
| 37 | overflow: auto; | |
| 38 | } | |
| 39 | ||
| 40 | :not(pre) > code[class*="language-"], | |
| 41 | pre[class*="language-"] { | |
| 42 | background: #2d2d2d; | |
| 43 | } | |
| 44 | ||
| 45 | /* Inline code */ | |
| 46 | :not(pre) > code[class*="language-"] { | |
| 47 | padding: .1em; | |
| 48 | border-radius: .3em; | |
| 49 | white-space: normal; | |
| 50 | } | |
| 51 | ||
| 52 | .token.comment, | |
| 53 | .token.block-comment, | |
| 54 | .token.prolog, | |
| 55 | .token.doctype, | |
| 56 | .token.cdata { | |
| 57 | color: #999; | |
| 58 | } | |
| 59 | ||
| 60 | .token.punctuation { | |
| 61 | color: #ccc; | |
| 62 | } | |
| 63 | ||
| 64 | .token.tag, | |
| 65 | .token.attr-name, | |
| 66 | .token.namespace, | |
| 67 | .token.deleted { | |
| 68 | color: #e2777a; | |
| 69 | } | |
| 70 | ||
| 71 | .token.function-name { | |
| 72 | color: #6196cc; | |
| 73 | } | |
| 74 | ||
| 75 | .token.boolean, | |
| 76 | .token.number, | |
| 77 | .token.function { | |
| 78 | color: #f08d49; | |
| 79 | } | |
| 80 | ||
| 81 | .token.property, | |
| 82 | .token.class-name, | |
| 83 | .token.constant, | |
| 84 | .token.symbol { | |
| 85 | color: #f8c555; | |
| 86 | } | |
| 87 | ||
| 88 | .token.selector, | |
| 89 | .token.important, | |
| 90 | .token.atrule, | |
| 91 | .token.keyword, | |
| 92 | .token.builtin { | |
| 93 | color: #cc99cd; | |
| 94 | } | |
| 95 | ||
| 96 | .token.string, | |
| 97 | .token.char, | |
| 98 | .token.attr-value, | |
| 99 | .token.regex, | |
| 100 | .token.variable { | |
| 101 | color: #7ec699; | |
| 102 | } | |
| 103 | ||
| 104 | .token.operator, | |
| 105 | .token.entity, | |
| 106 | .token.url { | |
| 107 | color: #67cdcc; | |
| 108 | } | |
| 109 | ||
| 110 | .token.important, | |
| 111 | .token.bold { | |
| 112 | font-weight: bold; | |
| 113 | } | |
| 114 | .token.italic { | |
| 115 | font-style: italic; | |
| 116 | } | |
| 117 | ||
| 118 | .token.entity { | |
| 119 | cursor: help; | |
| 120 | } | |
| 121 | ||
| 122 | .token.inserted { | |
| 123 | color: green; | |
| 124 | } | |
| 125 | ||
static/prism.js added +13
| @@ -0,0 +1,13 @@ | ||
| 1 | /* PrismJS 1.23.0 | |
| 2 | https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript+bash+markdown+markup-templating+php+python+yaml */ | |
| 3 | var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(u){var c=/\blang(?:uage)?-([\w-]+)\b/i,n=0,e={},M={manual:u.Prism&&u.Prism.manual,disableWorkerMessageHandler:u.Prism&&u.Prism.disableWorkerMessageHandler,util:{encode:function e(n){return n instanceof W?new W(n.type,e(n.content),n.alias):Array.isArray(n)?n.map(e):n.replace(/&/g,"&").replace(/</g,"<").replace(/\u00a0/g," ")},type:function(e){return Object.prototype.toString.call(e).slice(8,-1)},objId:function(e){return e.__id||Object.defineProperty(e,"__id",{value:++n}),e.__id},clone:function t(e,r){var a,n;switch(r=r||{},M.util.type(e)){case"Object":if(n=M.util.objId(e),r[n])return r[n];for(var i in a={},r[n]=a,e)e.hasOwnProperty(i)&&(a[i]=t(e[i],r));return a;case"Array":return n=M.util.objId(e),r[n]?r[n]:(a=[],r[n]=a,e.forEach(function(e,n){a[n]=t(e,r)}),a);default:return e}},getLanguage:function(e){for(;e&&!c.test(e.className);)e=e.parentElement;return e?(e.className.match(c)||[,"none"])[1].toLowerCase():"none"},currentScript:function(){if("undefined"==typeof document)return null;if("currentScript"in document)return document.currentScript;try{throw new Error}catch(e){var n=(/at [^(\r\n]*\((.*):.+:.+\)$/i.exec(e.stack)||[])[1];if(n){var t=document.getElementsByTagName("script");for(var r in t)if(t[r].src==n)return t[r]}return null}},isActive:function(e,n,t){for(var r="no-"+n;e;){var a=e.classList;if(a.contains(n))return!0;if(a.contains(r))return!1;e=e.parentElement}return!!t}},languages:{plain:e,plaintext:e,text:e,txt:e,extend:function(e,n){var t=M.util.clone(M.languages[e]);for(var r in n)t[r]=n[r];return t},insertBefore:function(t,e,n,r){var a=(r=r||M.languages)[t],i={};for(var l in a)if(a.hasOwnProperty(l)){if(l==e)for(var o in n)n.hasOwnProperty(o)&&(i[o]=n[o]);n.hasOwnProperty(l)||(i[l]=a[l])}var s=r[t];return r[t]=i,M.languages.DFS(M.languages,function(e,n){n===s&&e!=t&&(this[e]=i)}),i},DFS:function e(n,t,r,a){a=a||{};var i=M.util.objId;for(var l in n)if(n.hasOwnProperty(l)){t.call(n,l,n[l],r||l);var o=n[l],s=M.util.type(o);"Object"!==s||a[i(o)]?"Array"!==s||a[i(o)]||(a[i(o)]=!0,e(o,t,l,a)):(a[i(o)]=!0,e(o,t,null,a))}}},plugins:{},highlightAll:function(e,n){M.highlightAllUnder(document,e,n)},highlightAllUnder:function(e,n,t){var r={callback:t,container:e,selector:'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'};M.hooks.run("before-highlightall",r),r.elements=Array.prototype.slice.apply(r.container.querySelectorAll(r.selector)),M.hooks.run("before-all-elements-highlight",r);for(var a,i=0;a=r.elements[i++];)M.highlightElement(a,!0===n,r.callback)},highlightElement:function(e,n,t){var r=M.util.getLanguage(e),a=M.languages[r];e.className=e.className.replace(c,"").replace(/\s+/g," ")+" language-"+r;var i=e.parentElement;i&&"pre"===i.nodeName.toLowerCase()&&(i.className=i.className.replace(c,"").replace(/\s+/g," ")+" language-"+r);var l={element:e,language:r,grammar:a,code:e.textContent};function o(e){l.highlightedCode=e,M.hooks.run("before-insert",l),l.element.innerHTML=l.highlightedCode,M.hooks.run("after-highlight",l),M.hooks.run("complete",l),t&&t.call(l.element)}if(M.hooks.run("before-sanity-check",l),(i=l.element.parentElement)&&"pre"===i.nodeName.toLowerCase()&&!i.hasAttribute("tabindex")&&i.setAttribute("tabindex","0"),!l.code)return M.hooks.run("complete",l),void(t&&t.call(l.element));if(M.hooks.run("before-highlight",l),l.grammar)if(n&&u.Worker){var s=new Worker(M.filename);s.onmessage=function(e){o(e.data)},s.postMessage(JSON.stringify({language:l.language,code:l.code,immediateClose:!0}))}else o(M.highlight(l.code,l.grammar,l.language));else o(M.util.encode(l.code))},highlight:function(e,n,t){var r={code:e,grammar:n,language:t};return M.hooks.run("before-tokenize",r),r.tokens=M.tokenize(r.code,r.grammar),M.hooks.run("after-tokenize",r),W.stringify(M.util.encode(r.tokens),r.language)},tokenize:function(e,n){var t=n.rest;if(t){for(var r in t)n[r]=t[r];delete n.rest}var a=new i;return I(a,a.head,e),function e(n,t,r,a,i,l){for(var o in r)if(r.hasOwnProperty(o)&&r[o]){var s=r[o];s=Array.isArray(s)?s:[s];for(var u=0;u<s.length;++u){if(l&&l.cause==o+","+u)return;var c=s[u],g=c.inside,f=!!c.lookbehind,h=!!c.greedy,d=c.alias;if(h&&!c.pattern.global){var p=c.pattern.toString().match(/[imsuy]*$/)[0];c.pattern=RegExp(c.pattern.source,p+"g")}for(var v=c.pattern||c,m=a.next,y=i;m!==t.tail&&!(l&&y>=l.reach);y+=m.value.length,m=m.next){var b=m.value;if(t.length>n.length)return;if(!(b instanceof W)){var k,x=1;if(h){if(!(k=z(v,y,n,f)))break;var w=k.index,A=k.index+k[0].length,P=y;for(P+=m.value.length;P<=w;)m=m.next,P+=m.value.length;if(P-=m.value.length,y=P,m.value instanceof W)continue;for(var E=m;E!==t.tail&&(P<A||"string"==typeof E.value);E=E.next)x++,P+=E.value.length;x--,b=n.slice(y,P),k.index-=y}else if(!(k=z(v,0,b,f)))continue;var w=k.index,S=k[0],O=b.slice(0,w),L=b.slice(w+S.length),N=y+b.length;l&&N>l.reach&&(l.reach=N);var j=m.prev;O&&(j=I(t,j,O),y+=O.length),q(t,j,x);var C=new W(o,g?M.tokenize(S,g):S,d,S);if(m=I(t,j,C),L&&I(t,m,L),1<x){var _={cause:o+","+u,reach:N};e(n,t,r,m.prev,y,_),l&&_.reach>l.reach&&(l.reach=_.reach)}}}}}}(e,a,n,a.head,0),function(e){var n=[],t=e.head.next;for(;t!==e.tail;)n.push(t.value),t=t.next;return n}(a)},hooks:{all:{},add:function(e,n){var t=M.hooks.all;t[e]=t[e]||[],t[e].push(n)},run:function(e,n){var t=M.hooks.all[e];if(t&&t.length)for(var r,a=0;r=t[a++];)r(n)}},Token:W};function W(e,n,t,r){this.type=e,this.content=n,this.alias=t,this.length=0|(r||"").length}function z(e,n,t,r){e.lastIndex=n;var a=e.exec(t);if(a&&r&&a[1]){var i=a[1].length;a.index+=i,a[0]=a[0].slice(i)}return a}function i(){var e={value:null,prev:null,next:null},n={value:null,prev:e,next:null};e.next=n,this.head=e,this.tail=n,this.length=0}function I(e,n,t){var r=n.next,a={value:t,prev:n,next:r};return n.next=a,r.prev=a,e.length++,a}function q(e,n,t){for(var r=n.next,a=0;a<t&&r!==e.tail;a++)r=r.next;(n.next=r).prev=n,e.length-=a}if(u.Prism=M,W.stringify=function n(e,t){if("string"==typeof e)return e;if(Array.isArray(e)){var r="";return e.forEach(function(e){r+=n(e,t)}),r}var a={type:e.type,content:n(e.content,t),tag:"span",classes:["token",e.type],attributes:{},language:t},i=e.alias;i&&(Array.isArray(i)?Array.prototype.push.apply(a.classes,i):a.classes.push(i)),M.hooks.run("wrap",a);var l="";for(var o in a.attributes)l+=" "+o+'="'+(a.attributes[o]||"").replace(/"/g,""")+'"';return"<"+a.tag+' class="'+a.classes.join(" ")+'"'+l+">"+a.content+"</"+a.tag+">"},!u.document)return u.addEventListener&&(M.disableWorkerMessageHandler||u.addEventListener("message",function(e){var n=JSON.parse(e.data),t=n.language,r=n.code,a=n.immediateClose;u.postMessage(M.highlight(r,M.languages[t],t)),a&&u.close()},!1)),M;var t=M.util.currentScript();function r(){M.manual||M.highlightAll()}if(t&&(M.filename=t.src,t.hasAttribute("data-manual")&&(M.manual=!0)),!M.manual){var a=document.readyState;"loading"===a||"interactive"===a&&t&&t.defer?document.addEventListener("DOMContentLoaded",r):window.requestAnimationFrame?window.requestAnimationFrame(r):window.setTimeout(r,16)}return M}(_self);"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); | |
| 4 | Prism.languages.markup={comment:/<!--[\s\S]*?-->/,prolog:/<\?[\s\S]+?\?>/,doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^<!|>$|[[\]]/,"doctype-tag":/^DOCTYPE/,name:/[^\s<>'"]+/}},cdata:/<!\[CDATA\[[\s\S]*?]]>/i,tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:"named-entity"},/&#x?[\da-f]{1,8};/i]},Prism.languages.markup.tag.inside["attr-value"].inside.entity=Prism.languages.markup.entity,Prism.languages.markup.doctype.inside["internal-subset"].inside=Prism.languages.markup,Prism.hooks.add("wrap",function(a){"entity"===a.type&&(a.attributes.title=a.content.replace(/&/,"&"))}),Object.defineProperty(Prism.languages.markup.tag,"addInlined",{value:function(a,e){var s={};s["language-"+e]={pattern:/(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,lookbehind:!0,inside:Prism.languages[e]},s.cdata=/^<!\[CDATA\[|\]\]>$/i;var t={"included-cdata":{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,inside:s}};t["language-"+e]={pattern:/[\s\S]+/,inside:Prism.languages[e]};var n={};n[a]={pattern:RegExp("(<__[^>]*>)(?:<!\\[CDATA\\[(?:[^\\]]|\\](?!\\]>))*\\]\\]>|(?!<!\\[CDATA\\[)[^])*?(?=</__>)".replace(/__/g,function(){return a}),"i"),lookbehind:!0,greedy:!0,inside:t},Prism.languages.insertBefore("markup","cdata",n)}}),Object.defineProperty(Prism.languages.markup.tag,"addAttribute",{value:function(a,e){Prism.languages.markup.tag.inside["special-attr"].push({pattern:RegExp("(^|[\"'\\s])(?:"+a+")\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s'\">=]+(?=[\\s>]))","i"),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[e,"language-"+e],inside:Prism.languages[e]},punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}}}})}}),Prism.languages.html=Prism.languages.markup,Prism.languages.mathml=Prism.languages.markup,Prism.languages.svg=Prism.languages.markup,Prism.languages.xml=Prism.languages.extend("markup",{}),Prism.languages.ssml=Prism.languages.xml,Prism.languages.atom=Prism.languages.xml,Prism.languages.rss=Prism.languages.xml; | |
| 5 | !function(s){var e=/("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/;s.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:/@[\w-](?:[^;{\s]|\s+(?![\s{]))*(?:;|(?=\s*\{))/,inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:"selector"},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp("\\burl\\((?:"+e.source+"|(?:[^\\\\\r\n()\"']|\\\\[^])*)\\)","i"),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp("^"+e.source+"$"),alias:"url"}}},selector:RegExp("[^{}\\s](?:[^{};\"'\\s]|\\s+(?![\\s{])|"+e.source+")*(?=\\s*\\{)"),string:{pattern:e,greedy:!0},property:/(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,important:/!important\b/i,function:/[-a-z0-9]+(?=\()/i,punctuation:/[(){};:,]/},s.languages.css.atrule.inside.rest=s.languages.css;var t=s.languages.markup;t&&(t.tag.addInlined("style","css"),t.tag.addAttribute("style","css"))}(Prism); | |
| 6 | Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|interface|extends|implements|trait|instanceof|new)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,boolean:/\b(?:true|false)\b/,function:/\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/}; | |
| 7 | Prism.languages.javascript=Prism.languages.extend("clike",{"class-name":[Prism.languages.clike["class-name"],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:prototype|constructor))/,lookbehind:!0}],keyword:[{pattern:/((?:^|})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:/\b(?:(?:0[xX](?:[\dA-Fa-f](?:_[\dA-Fa-f])?)+|0[bB](?:[01](?:_[01])?)+|0[oO](?:[0-7](?:_[0-7])?)+)n?|(?:\d(?:_\d)?)+n|NaN|Infinity)\b|(?:\b(?:\d(?:_\d)?)+\.?(?:\d(?:_\d)?)*|\B\.(?:\d(?:_\d)?)+)(?:[Ee][+-]?(?:\d(?:_\d)?)+)?/,operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),Prism.languages.javascript["class-name"][0].pattern=/(\b(?:class|interface|extends|implements|instanceof|new)\s+)[\w.\\]+/,Prism.languages.insertBefore("javascript","keyword",{regex:{pattern:/((?:^|[^$\w\xA0-\uFFFF."'\])\s]|\b(?:return|yield))\s*)\/(?:\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[gimyus]{0,6}(?=(?:\s|\/\*(?:[^*]|\*(?!\/))*\*\/)*(?:$|[\r\n,.;:})\]]|\/\/))/,lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:"language-regex",inside:Prism.languages.regex},"regex-flags":/[a-z]+$/,"regex-delimiter":/^\/|\/$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:"function"},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,inside:Prism.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:Prism.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:Prism.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),Prism.languages.insertBefore("javascript","string",{hashbang:{pattern:/^#!.*/,greedy:!0,alias:"comment"},"template-string":{pattern:/`(?:\\[\s\S]|\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}|(?!\${)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\${(?:[^{}]|{(?:[^{}]|{[^}]*})*})+}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\${|}$/,alias:"punctuation"},rest:Prism.languages.javascript}},string:/[\s\S]+/}}}),Prism.languages.markup&&(Prism.languages.markup.tag.addInlined("script","javascript"),Prism.languages.markup.tag.addAttribute("on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)","javascript")),Prism.languages.js=Prism.languages.javascript; | |
| 8 | !function(e){var t="\\b(?:BASH|BASHOPTS|BASH_ALIASES|BASH_ARGC|BASH_ARGV|BASH_CMDS|BASH_COMPLETION_COMPAT_DIR|BASH_LINENO|BASH_REMATCH|BASH_SOURCE|BASH_VERSINFO|BASH_VERSION|COLORTERM|COLUMNS|COMP_WORDBREAKS|DBUS_SESSION_BUS_ADDRESS|DEFAULTS_PATH|DESKTOP_SESSION|DIRSTACK|DISPLAY|EUID|GDMSESSION|GDM_LANG|GNOME_KEYRING_CONTROL|GNOME_KEYRING_PID|GPG_AGENT_INFO|GROUPS|HISTCONTROL|HISTFILE|HISTFILESIZE|HISTSIZE|HOME|HOSTNAME|HOSTTYPE|IFS|INSTANCE|JOB|LANG|LANGUAGE|LC_ADDRESS|LC_ALL|LC_IDENTIFICATION|LC_MEASUREMENT|LC_MONETARY|LC_NAME|LC_NUMERIC|LC_PAPER|LC_TELEPHONE|LC_TIME|LESSCLOSE|LESSOPEN|LINES|LOGNAME|LS_COLORS|MACHTYPE|MAILCHECK|MANDATORY_PATH|NO_AT_BRIDGE|OLDPWD|OPTERR|OPTIND|ORBIT_SOCKETDIR|OSTYPE|PAPERSIZE|PATH|PIPESTATUS|PPID|PS1|PS2|PS3|PS4|PWD|RANDOM|REPLY|SECONDS|SELINUX_INIT|SESSION|SESSIONTYPE|SESSION_MANAGER|SHELL|SHELLOPTS|SHLVL|SSH_AUTH_SOCK|TERM|UID|UPSTART_EVENTS|UPSTART_INSTANCE|UPSTART_JOB|UPSTART_SESSION|USER|WINDOWID|XAUTHORITY|XDG_CONFIG_DIRS|XDG_CURRENT_DESKTOP|XDG_DATA_DIRS|XDG_GREETER_DATA_DIR|XDG_MENU_PREFIX|XDG_RUNTIME_DIR|XDG_SEAT|XDG_SEAT_PATH|XDG_SESSION_DESKTOP|XDG_SESSION_ID|XDG_SESSION_PATH|XDG_SESSION_TYPE|XDG_VTNR|XMODIFIERS)\\b",n={pattern:/(^(["']?)\w+\2)[ \t]+\S.*/,lookbehind:!0,alias:"punctuation",inside:null},a={bash:n,environment:{pattern:RegExp("\\$"+t),alias:"constant"},variable:[{pattern:/\$?\(\([\s\S]+?\)\)/,greedy:!0,inside:{variable:[{pattern:/(^\$\(\([\s\S]+)\)\)/,lookbehind:!0},/^\$\(\(/],number:/\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee]-?\d+)?/,operator:/--?|-=|\+\+?|\+=|!=?|~|\*\*?|\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/,punctuation:/\(\(?|\)\)?|,|;/}},{pattern:/\$\((?:\([^)]+\)|[^()])+\)|`[^`]+`/,greedy:!0,inside:{variable:/^\$\(|^`|\)$|`$/}},{pattern:/\$\{[^}]+\}/,greedy:!0,inside:{operator:/:[-=?+]?|[!\/]|##?|%%?|\^\^?|,,?/,punctuation:/[\[\]]/,environment:{pattern:RegExp("(\\{)"+t),lookbehind:!0,alias:"constant"}}},/\$(?:\w+|[#?*!@$])/],entity:/\\(?:[abceEfnrtv\\"]|O?[0-7]{1,3}|x[0-9a-fA-F]{1,2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})/};e.languages.bash={shebang:{pattern:/^#!\s*\/.*/,alias:"important"},comment:{pattern:/(^|[^"{\\$])#.*/,lookbehind:!0},"function-name":[{pattern:/(\bfunction\s+)[\w-]+(?=(?:\s*\(?:\s*\))?\s*\{)/,lookbehind:!0,alias:"function"},{pattern:/\b[\w-]+(?=\s*\(\s*\)\s*\{)/,alias:"function"}],"for-or-select":{pattern:/(\b(?:for|select)\s+)\w+(?=\s+in\s)/,alias:"variable",lookbehind:!0},"assign-left":{pattern:/(^|[\s;|&]|[<>]\()\w+(?=\+?=)/,inside:{environment:{pattern:RegExp("(^|[\\s;|&]|[<>]\\()"+t),lookbehind:!0,alias:"constant"}},alias:"variable",lookbehind:!0},string:[{pattern:/((?:^|[^<])<<-?\s*)(\w+?)\s[\s\S]*?(?:\r?\n|\r)\2/,lookbehind:!0,greedy:!0,inside:a},{pattern:/((?:^|[^<])<<-?\s*)(["'])(\w+)\2\s[\s\S]*?(?:\r?\n|\r)\3/,lookbehind:!0,greedy:!0,inside:{bash:n}},{pattern:/(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\([^)]+\)|\$(?!\()|`[^`]+`|[^"\\`$])*"/,lookbehind:!0,greedy:!0,inside:a},{pattern:/(^|[^$\\])'[^']*'/,lookbehind:!0,greedy:!0},{pattern:/\$'(?:[^'\\]|\\[\s\S])*'/,greedy:!0,inside:{entity:a.entity}}],environment:{pattern:RegExp("\\$?"+t),alias:"constant"},variable:a.variable,function:{pattern:/(^|[\s;|&]|[<>]\()(?:add|apropos|apt|aptitude|apt-cache|apt-get|aspell|automysqlbackup|awk|basename|bash|bc|bconsole|bg|bzip2|cal|cat|cfdisk|chgrp|chkconfig|chmod|chown|chroot|cksum|clear|cmp|column|comm|composer|cp|cron|crontab|csplit|curl|cut|date|dc|dd|ddrescue|debootstrap|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|env|ethtool|expand|expect|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|git|gparted|grep|groupadd|groupdel|groupmod|groups|grub-mkconfig|gzip|halt|head|hg|history|host|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|ip|jobs|join|kill|killall|less|link|ln|locate|logname|logrotate|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|lynx|make|man|mc|mdadm|mkconfig|mkdir|mke2fs|mkfifo|mkfs|mkisofs|mknod|mkswap|mmv|more|most|mount|mtools|mtr|mutt|mv|nano|nc|netstat|nice|nl|nohup|notify-send|npm|nslookup|op|open|parted|passwd|paste|pathchk|ping|pkill|pnpm|popd|pr|printcap|printenv|ps|pushd|pv|quota|quotacheck|quotactl|ram|rar|rcp|reboot|remsync|rename|renice|rev|rm|rmdir|rpm|rsync|scp|screen|sdiff|sed|sendmail|seq|service|sftp|sh|shellcheck|shuf|shutdown|sleep|slocate|sort|split|ssh|stat|strace|su|sudo|sum|suspend|swapon|sync|tac|tail|tar|tee|time|timeout|top|touch|tr|traceroute|tsort|tty|umount|uname|unexpand|uniq|units|unrar|unshar|unzip|update-grub|uptime|useradd|userdel|usermod|users|uudecode|uuencode|v|vdir|vi|vim|virsh|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yarn|yes|zenity|zip|zsh|zypper)(?=$|[)\s;|&])/,lookbehind:!0},keyword:{pattern:/(^|[\s;|&]|[<>]\()(?:if|then|else|elif|fi|for|while|in|case|esac|function|select|do|done|until)(?=$|[)\s;|&])/,lookbehind:!0},builtin:{pattern:/(^|[\s;|&]|[<>]\()(?:\.|:|break|cd|continue|eval|exec|exit|export|getopts|hash|pwd|readonly|return|shift|test|times|trap|umask|unset|alias|bind|builtin|caller|command|declare|echo|enable|help|let|local|logout|mapfile|printf|read|readarray|source|type|typeset|ulimit|unalias|set|shopt)(?=$|[)\s;|&])/,lookbehind:!0,alias:"class-name"},boolean:{pattern:/(^|[\s;|&]|[<>]\()(?:true|false)(?=$|[)\s;|&])/,lookbehind:!0},"file-descriptor":{pattern:/\B&\d\b/,alias:"important"},operator:{pattern:/\d?<>|>\||\+=|==?|!=?|=~|<<[<-]?|[&\d]?>>|\d?[<>]&?|&[>&]?|\|[&|]?|<=?|>=?/,inside:{"file-descriptor":{pattern:/^\d/,alias:"important"}}},punctuation:/\$?\(\(?|\)\)?|\.\.|[{}[\];\\]/,number:{pattern:/(^|\s)(?:[1-9]\d*|0)(?:[.,]\d+)?\b/,lookbehind:!0}},n.inside=e.languages.bash;for(var s=["comment","function-name","for-or-select","assign-left","string","environment","function","keyword","builtin","boolean","file-descriptor","operator","punctuation","number"],i=a.variable[1].inside,o=0;o<s.length;o++)i[s[o]]=e.languages.bash[s[o]];e.languages.shell=e.languages.bash}(Prism); | |
| 9 | !function(u){function n(n){return n=n.replace(/<inner>/g,function(){return"(?:\\\\.|[^\\\\\n\r]|(?:\n|\r\n?)(?!\n|\r\n?))"}),RegExp("((?:^|[^\\\\])(?:\\\\{2})*)(?:"+n+")")}var e="(?:\\\\.|``(?:[^`\r\n]|`(?!`))+``|`[^`\r\n]+`|[^\\\\|\r\n`])+",t="\\|?__(?:\\|__)+\\|?(?:(?:\n|\r\n?)|(?![^]))".replace(/__/g,function(){return e}),a="\\|?[ \t]*:?-{3,}:?[ \t]*(?:\\|[ \t]*:?-{3,}:?[ \t]*)+\\|?(?:\n|\r\n?)";u.languages.markdown=u.languages.extend("markup",{}),u.languages.insertBefore("markdown","prolog",{"front-matter-block":{pattern:/(^(?:\s*[\r\n])?)---(?!.)[\s\S]*?[\r\n]---(?!.)/,lookbehind:!0,greedy:!0,inside:{punctuation:/^---|---$/,"font-matter":{pattern:/\S+(?:\s+\S+)*/,alias:["yaml","language-yaml"],inside:u.languages.yaml}}},blockquote:{pattern:/^>(?:[\t ]*>)*/m,alias:"punctuation"},table:{pattern:RegExp("^"+t+a+"(?:"+t+")*","m"),inside:{"table-data-rows":{pattern:RegExp("^("+t+a+")(?:"+t+")*$"),lookbehind:!0,inside:{"table-data":{pattern:RegExp(e),inside:u.languages.markdown},punctuation:/\|/}},"table-line":{pattern:RegExp("^("+t+")"+a+"$"),lookbehind:!0,inside:{punctuation:/\||:?-{3,}:?/}},"table-header-row":{pattern:RegExp("^"+t+"$"),inside:{"table-header":{pattern:RegExp(e),alias:"important",inside:u.languages.markdown},punctuation:/\|/}}}},code:[{pattern:/((?:^|\n)[ \t]*\n|(?:^|\r\n?)[ \t]*\r\n?)(?: {4}|\t).+(?:(?:\n|\r\n?)(?: {4}|\t).+)*/,lookbehind:!0,alias:"keyword"},{pattern:/``.+?``|`[^`\r\n]+`/,alias:"keyword"},{pattern:/^```[\s\S]*?^```$/m,greedy:!0,inside:{"code-block":{pattern:/^(```.*(?:\n|\r\n?))[\s\S]+?(?=(?:\n|\r\n?)^```$)/m,lookbehind:!0},"code-language":{pattern:/^(```).+/,lookbehind:!0},punctuation:/```/}}],title:[{pattern:/\S.*(?:\n|\r\n?)(?:==+|--+)(?=[ \t]*$)/m,alias:"important",inside:{punctuation:/==+$|--+$/}},{pattern:/(^\s*)#.+/m,lookbehind:!0,alias:"important",inside:{punctuation:/^#+|#+$/}}],hr:{pattern:/(^\s*)([*-])(?:[\t ]*\2){2,}(?=\s*$)/m,lookbehind:!0,alias:"punctuation"},list:{pattern:/(^\s*)(?:[*+-]|\d+\.)(?=[\t ].)/m,lookbehind:!0,alias:"punctuation"},"url-reference":{pattern:/!?\[[^\]]+\]:[\t ]+(?:\S+|<(?:\\.|[^>\\])+>)(?:[\t ]+(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\)))?/,inside:{variable:{pattern:/^(!?\[)[^\]]+/,lookbehind:!0},string:/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\((?:\\.|[^)\\])*\))$/,punctuation:/^[\[\]!:]|[<>]/},alias:"url"},bold:{pattern:n("\\b__(?:(?!_)<inner>|_(?:(?!_)<inner>)+_)+__\\b|\\*\\*(?:(?!\\*)<inner>|\\*(?:(?!\\*)<inner>)+\\*)+\\*\\*"),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^..)[\s\S]+(?=..$)/,lookbehind:!0,inside:{}},punctuation:/\*\*|__/}},italic:{pattern:n("\\b_(?:(?!_)<inner>|__(?:(?!_)<inner>)+__)+_\\b|\\*(?:(?!\\*)<inner>|\\*\\*(?:(?!\\*)<inner>)+\\*\\*)+\\*"),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^.)[\s\S]+(?=.$)/,lookbehind:!0,inside:{}},punctuation:/[*_]/}},strike:{pattern:n("(~~?)(?:(?!~)<inner>)+?\\2"),lookbehind:!0,greedy:!0,inside:{content:{pattern:/(^~~?)[\s\S]+(?=\1$)/,lookbehind:!0,inside:{}},punctuation:/~~?/}},url:{pattern:n('!?\\[(?:(?!\\])<inner>)+\\](?:\\([^\\s)]+(?:[\t ]+"(?:\\\\.|[^"\\\\])*")?\\)|[ \t]?\\[(?:(?!\\])<inner>)+\\])'),lookbehind:!0,greedy:!0,inside:{operator:/^!/,content:{pattern:/(^\[)[^\]]+(?=\])/,lookbehind:!0,inside:{}},variable:{pattern:/(^\][ \t]?\[)[^\]]+(?=\]$)/,lookbehind:!0},url:{pattern:/(^\]\()[^\s)]+/,lookbehind:!0},string:{pattern:/(^[ \t]+)"(?:\\.|[^"\\])*"(?=\)$)/,lookbehind:!0}}}}),["url","bold","italic","strike"].forEach(function(e){["url","bold","italic","strike"].forEach(function(n){e!==n&&(u.languages.markdown[e].inside.content.inside[n]=u.languages.markdown[n])})}),u.hooks.add("after-tokenize",function(n){"markdown"!==n.language&&"md"!==n.language||!function n(e){if(e&&"string"!=typeof e)for(var t=0,a=e.length;t<a;t++){var i=e[t];if("code"===i.type){var r=i.content[1],o=i.content[3];if(r&&o&&"code-language"===r.type&&"code-block"===o.type&&"string"==typeof r.content){var l=r.content.replace(/\b#/g,"sharp").replace(/\b\+\+/g,"pp"),s="language-"+(l=(/[a-z][\w-]*/i.exec(l)||[""])[0].toLowerCase());o.alias?"string"==typeof o.alias?o.alias=[o.alias,s]:o.alias.push(s):o.alias=[s]}}else n(i.content)}}(n.tokens)}),u.hooks.add("wrap",function(n){if("code-block"===n.type){for(var e="",t=0,a=n.classes.length;t<a;t++){var i=n.classes[t],r=/language-(.+)/.exec(i);if(r){e=r[1];break}}var o=u.languages[e];if(o){var l=document.createElement("div");l.innerHTML=n.content;var s=l.textContent;n.content=u.highlight(s,o,e)}else if(e&&"none"!==e&&u.plugins.autoloader){var d="md-"+(new Date).valueOf()+"-"+Math.floor(1e16*Math.random());n.attributes.id=d,u.plugins.autoloader.loadLanguages(e,function(){var n=document.getElementById(d);n&&(n.innerHTML=u.highlight(n.textContent,u.languages[e],e))})}}}),u.languages.md=u.languages.markdown}(Prism); | |
| 10 | !function(h){function v(e,n){return"___"+e.toUpperCase()+n+"___"}Object.defineProperties(h.languages["markup-templating"]={},{buildPlaceholders:{value:function(a,r,e,o){if(a.language===r){var c=a.tokenStack=[];a.code=a.code.replace(e,function(e){if("function"==typeof o&&!o(e))return e;for(var n,t=c.length;-1!==a.code.indexOf(n=v(r,t));)++t;return c[t]=e,n}),a.grammar=h.languages.markup}}},tokenizePlaceholders:{value:function(p,k){if(p.language===k&&p.tokenStack){p.grammar=h.languages[k];var m=0,d=Object.keys(p.tokenStack);!function e(n){for(var t=0;t<n.length&&!(m>=d.length);t++){var a=n[t];if("string"==typeof a||a.content&&"string"==typeof a.content){var r=d[m],o=p.tokenStack[r],c="string"==typeof a?a:a.content,i=v(k,r),u=c.indexOf(i);if(-1<u){++m;var g=c.substring(0,u),l=new h.Token(k,h.tokenize(o,p.grammar),"language-"+k,o),s=c.substring(u+i.length),f=[];g&&f.push.apply(f,e([g])),f.push(l),s&&f.push.apply(f,e([s])),"string"==typeof a?n.splice.apply(n,[t,1].concat(f)):a.content=f}}else a.content&&e(a.content)}return n}(p.tokens)}}}})}(Prism); | |
| 11 | !function(a){var e=/\/\*[\s\S]*?\*\/|\/\/.*|#(?!\[).*/,t=[{pattern:/\b(?:false|true)\b/i,alias:"boolean"},{pattern:/(::\s*)\b[a-z_]\w*\b(?!\s*\()/i,greedy:!0,lookbehind:!0},{pattern:/(\b(?:case|const)\s+)\b[a-z_]\w*(?=\s*[;=])/i,greedy:!0,lookbehind:!0},/\b(?:null)\b/i,/\b[A-Z_][A-Z0-9_]*\b(?!\s*\()/],i=/\b0b[01]+(?:_[01]+)*\b|\b0o[0-7]+(?:_[0-7]+)*\b|\b0x[\da-f]+(?:_[\da-f]+)*\b|(?:\b\d+(?:_\d+)*\.?(?:\d+(?:_\d+)*)?|\B\.\d+)(?:e[+-]?\d+)?/i,n=/<?=>|\?\?=?|\.{3}|\??->|[!=]=?=?|::|\*\*=?|--|\+\+|&&|\|\||<<|>>|[?~]|[/^|%*&<>.+-]=?/,s=/[{}\[\](),:;]/;a.languages.php={delimiter:{pattern:/\?>$|^<\?(?:php(?=\s)|=)?/i,alias:"important"},comment:e,variable:/\$+(?:\w+\b|(?={))/i,package:{pattern:/(namespace\s+|use\s+(?:function\s+)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,lookbehind:!0,inside:{punctuation:/\\/}},"class-name-definition":{pattern:/(\b(?:class|enum|interface|trait)\s+)\b[a-z_]\w*(?!\\)\b/i,lookbehind:!0,alias:"class-name"},"function-definition":{pattern:/(\bfunction\s+)[a-z_]\w*(?=\s*\()/i,lookbehind:!0,alias:"function"},keyword:[{pattern:/(\(\s*)\b(?:bool|boolean|int|integer|float|string|object|array)\b(?=\s*\))/i,alias:"type-casting",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)\b(?:bool|int|float|string|object|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*[a-z0-9_|]\|\s*)(?:null|false)\b(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*(?:\?\s*)?)\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|self|static|callable|iterable|(?:null|false)(?=\s*\|))\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*(?:\?\s*)?[a-z0-9_|]\|\s*)(?:null|false)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/\b(?:bool|int|float|string|object|void|array(?!\s*\()|mixed|iterable|(?:null|false)(?=\s*\|))\b/i,alias:"type-declaration",greedy:!0},{pattern:/(\|\s*)(?:null|false)\b/i,alias:"type-declaration",greedy:!0,lookbehind:!0},{pattern:/\b(?:parent|self|static)(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(\byield\s+)from\b/i,lookbehind:!0},/\bclass\b/i,{pattern:/((?:^|[^\s>:]|(?:^|[^-])>|(?:^|[^:]):)\s*)\b(?:__halt_compiler|abstract|and|array|as|break|callable|case|catch|clone|const|continue|declare|default|die|do|echo|else|elseif|empty|enddeclare|endfor|endforeach|endif|endswitch|endwhile|enum|eval|exit|extends|final|finally|fn|for|foreach|function|global|goto|if|implements|include|include_once|instanceof|insteadof|interface|isset|list|namespace|match|new|or|parent|print|private|protected|public|require|require_once|return|self|static|switch|throw|trait|try|unset|use|var|while|xor|yield)\b/i,lookbehind:!0}],"argument-name":{pattern:/([(,]\s+)\b[a-z_]\w*(?=\s*:(?!:))/i,lookbehind:!0},"class-name":[{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self|\s+static))\s+|\bcatch\s*\()\b[a-z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/(\|\s*)\b[a-z_]\w*(?!\\)\b/i,greedy:!0,lookbehind:!0},{pattern:/\b[a-z_]\w*(?!\\)\b(?=\s*\|)/i,greedy:!0},{pattern:/(\|\s*)(?:\\?\b[a-z_]\w*)+\b/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(?:\\?\b[a-z_]\w*)+\b(?=\s*\|)/i,alias:"class-name-fully-qualified",greedy:!0,inside:{punctuation:/\\/}},{pattern:/(\b(?:extends|implements|instanceof|new(?!\s+self\b|\s+static\b))\s+|\bcatch\s*\()(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:"class-name-fully-qualified",greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*\$)/i,alias:"type-declaration",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-declaration"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/\b[a-z_]\w*(?=\s*::)/i,alias:"static-context",greedy:!0},{pattern:/(?:\\?\b[a-z_]\w*)+(?=\s*::)/i,alias:["class-name-fully-qualified","static-context"],greedy:!0,inside:{punctuation:/\\/}},{pattern:/([(,?]\s*)[a-z_]\w*(?=\s*\$)/i,alias:"type-hint",greedy:!0,lookbehind:!0},{pattern:/([(,?]\s*)(?:\\?\b[a-z_]\w*)+(?=\s*\$)/i,alias:["class-name-fully-qualified","type-hint"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}},{pattern:/(\)\s*:\s*(?:\?\s*)?)\b[a-z_]\w*(?!\\)\b/i,alias:"return-type",greedy:!0,lookbehind:!0},{pattern:/(\)\s*:\s*(?:\?\s*)?)(?:\\?\b[a-z_]\w*)+\b(?!\\)/i,alias:["class-name-fully-qualified","return-type"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:t,function:/\b\w+(?=\s*\()/,property:{pattern:/(->\s*)\w+/,lookbehind:!0},number:i,operator:n,punctuation:s};var l={pattern:/{\$(?:{(?:{[^{}]+}|[^{}]+)}|[^{}])+}|(^|[^\\{])\$+(?:\w+(?:\[[^\r\n\[\]]+\]|->\w+)*)/,lookbehind:!0,inside:a.languages.php},r=[{pattern:/<<<'([^']+)'[\r\n](?:.*[\r\n])*?\1;/,alias:"nowdoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<'[^']+'|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<'?|[';]$/}}}},{pattern:/<<<(?:"([^"]+)"[\r\n](?:.*[\r\n])*?\1;|([a-z_]\w*)[\r\n](?:.*[\r\n])*?\2;)/i,alias:"heredoc-string",greedy:!0,inside:{delimiter:{pattern:/^<<<(?:"[^"]+"|[a-z_]\w*)|[a-z_]\w*;$/i,alias:"symbol",inside:{punctuation:/^<<<"?|[";]$/}},interpolation:l}},{pattern:/`(?:\\[\s\S]|[^\\`])*`/,alias:"backtick-quoted-string",greedy:!0},{pattern:/'(?:\\[\s\S]|[^\\'])*'/,alias:"single-quoted-string",greedy:!0},{pattern:/"(?:\\[\s\S]|[^\\"])*"/,alias:"double-quoted-string",greedy:!0,inside:{interpolation:l}}];a.languages.insertBefore("php","variable",{string:r,attribute:{pattern:/#\[(?:[^"'\/#]|\/(?![*/])|\/\/.*$|#(?!\[).*$|\/\*(?:[^*]|\*(?!\/))*\*\/|"(?:\\[\s\S]|[^\\"])*"|'(?:\\[\s\S]|[^\\'])*')+\](?=\s*[a-z$#])/im,greedy:!0,inside:{"attribute-content":{pattern:/^(#\[)[\s\S]+(?=]$)/,lookbehind:!0,inside:{comment:e,string:r,"attribute-class-name":[{pattern:/([^:]|^)\b[a-z_]\w*(?!\\)\b/i,alias:"class-name",greedy:!0,lookbehind:!0},{pattern:/([^:]|^)(?:\\?\b[a-z_]\w*)+/i,alias:["class-name","class-name-fully-qualified"],greedy:!0,lookbehind:!0,inside:{punctuation:/\\/}}],constant:t,number:i,operator:n,punctuation:s}},delimiter:{pattern:/^#\[|]$/,alias:"punctuation"}}}}),a.hooks.add("before-tokenize",function(e){if(/<\?/.test(e.code)){a.languages["markup-templating"].buildPlaceholders(e,"php",/<\?(?:[^"'/#]|\/(?![*/])|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|(?:\/\/|#(?!\[))(?:[^?\n\r]|\?(?!>))*(?=$|\?>|[\r\n])|#\[|\/\*(?:[^*]|\*(?!\/))*(?:\*\/|$))*?(?:\?>|$)/gi)}}),a.hooks.add("after-tokenize",function(e){a.languages["markup-templating"].tokenizePlaceholders(e,"php")})}(Prism); | |
| 12 | Prism.languages.python={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0},"string-interpolation":{pattern:/(?:f|rf|fr)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,greedy:!0,inside:{interpolation:{pattern:/((?:^|[^{])(?:{{)*){(?!{)(?:[^{}]|{(?!{)(?:[^{}]|{(?!{)(?:[^{}])+})+})+}/,lookbehind:!0,inside:{"format-spec":{pattern:/(:)[^:(){}]+(?=}$)/,lookbehind:!0},"conversion-option":{pattern://,alias:"punctuation"},rest:null}},string:/[\s\S]+/}},"triple-quoted-string":{pattern:/(?:[rub]|rb|br)?("""|''')[\s\S]*?\1/i,greedy:!0,alias:"string"},string:{pattern:/(?:[rub]|rb|br)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,greedy:!0},function:{pattern:/((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,lookbehind:!0},"class-name":{pattern:/(\bclass\s+)\w+/i,lookbehind:!0},decorator:{pattern:/(^\s*)@\w+(?:\.\w+)*/im,lookbehind:!0,alias:["annotation","punctuation"],inside:{punctuation:/\./}},keyword:/\b(?:and|as|assert|async|await|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,builtin:/\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,boolean:/\b(?:True|False|None)\b/,number:/(?:\b(?=\d)|\B(?=\.))(?:0[bo])?(?:(?:\d|0x[\da-f])[\da-f]*(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?j?\b/i,operator:/[-+%=]=?|!=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,punctuation:/[{}[\];(),.:]/},Prism.languages.python["string-interpolation"].inside.interpolation.inside.rest=Prism.languages.python,Prism.languages.py=Prism.languages.python; | |
| 13 | !function(e){var n=/[*&][^\s[\]{},]+/,r=/!(?:<[\w\-%#;/?:@&=+$,.!~*'()[\]]+>|(?:[a-zA-Z\d-]*!)?[\w\-%#;/?:@&=+$.~*'()]+)?/,t="(?:"+r.source+"(?:[ \t]+"+n.source+")?|"+n.source+"(?:[ \t]+"+r.source+")?)",a="(?:[^\\s\\x00-\\x08\\x0e-\\x1f!\"#%&'*,\\-:>?@[\\]`{|}\\x7f-\\x84\\x86-\\x9f\\ud800-\\udfff\\ufffe\\uffff]|[?:-]<PLAIN>)(?:[ \t]*(?:(?![#:])<PLAIN>|:<PLAIN>))*".replace(/<PLAIN>/g,function(){return"[^\\s\\x00-\\x08\\x0e-\\x1f,[\\]{}\\x7f-\\x84\\x86-\\x9f\\ud800-\\udfff\\ufffe\\uffff]"}),d="\"(?:[^\"\\\\\r\n]|\\\\.)*\"|'(?:[^'\\\\\r\n]|\\\\.)*'";function o(e,n){n=(n||"").replace(/m/g,"")+"m";var r="([:\\-,[{]\\s*(?:\\s<<prop>>[ \t]+)?)(?:<<value>>)(?=[ \t]*(?:$|,|]|}|(?:[\r\n]\\s*)?#))".replace(/<<prop>>/g,function(){return t}).replace(/<<value>>/g,function(){return e});return RegExp(r,n)}e.languages.yaml={scalar:{pattern:RegExp("([\\-:]\\s*(?:\\s<<prop>>[ \t]+)?[|>])[ \t]*(?:((?:\r?\n|\r)[ \t]+)\\S[^\r\n]*(?:\\2[^\r\n]+)*)".replace(/<<prop>>/g,function(){return t})),lookbehind:!0,alias:"string"},comment:/#.*/,key:{pattern:RegExp("((?:^|[:\\-,[{\r\n?])[ \t]*(?:<<prop>>[ \t]+)?)<<key>>(?=\\s*:\\s)".replace(/<<prop>>/g,function(){return t}).replace(/<<key>>/g,function(){return"(?:"+a+"|"+d+")"})),lookbehind:!0,greedy:!0,alias:"atrule"},directive:{pattern:/(^[ \t]*)%.+/m,lookbehind:!0,alias:"important"},datetime:{pattern:o("\\d{4}-\\d\\d?-\\d\\d?(?:[tT]|[ \t]+)\\d\\d?:\\d{2}:\\d{2}(?:\\.\\d*)?(?:[ \t]*(?:Z|[-+]\\d\\d?(?::\\d{2})?))?|\\d{4}-\\d{2}-\\d{2}|\\d\\d?:\\d{2}(?::\\d{2}(?:\\.\\d*)?)?"),lookbehind:!0,alias:"number"},boolean:{pattern:o("true|false","i"),lookbehind:!0,alias:"important"},null:{pattern:o("null|~","i"),lookbehind:!0,alias:"important"},string:{pattern:o(d),lookbehind:!0,greedy:!0},number:{pattern:o("[+-]?(?:0x[\\da-f]+|0o[0-7]+|(?:\\d+(?:\\.\\d*)?|\\.?\\d+)(?:e[+-]?\\d+)?|\\.inf|\\.nan)","i"),lookbehind:!0},tag:r,important:n,punctuation:/---|[:[\]{}\-,|>?]|\.\.\./},e.languages.yml=e.languages.yaml}(Prism); | |