├── .gitignore ├── LICENSE ├── README.md ├── config ├── config.default.js └── index.js ├── index.js ├── package-lock.json ├── package.json ├── resources ├── notfound0.webp ├── notfound1.webp ├── notfound2.webp └── text.json └── src ├── ApiHandler.js ├── Attempt.js ├── InlineStore.js ├── Logger.js ├── NamuRouter.js ├── Namuwiki.js ├── Telegram.js ├── Utils.js ├── WikiImage.js ├── parser ├── ParagraphParser.js ├── index.js ├── prerenderer │ ├── BracePreRenderer.js │ ├── PreRenderer.js │ └── PreRendererMacro.js ├── processor │ ├── Processor.js │ ├── ProcessorBrace.js │ ├── ProcessorInline.js │ ├── ProcessorLink.js │ ├── ProcessorList.js │ ├── ProcessorMacro.js │ ├── ProcessorQuote.js │ ├── ProcessorTable.js │ └── index.js └── tokenizer │ ├── Tokenizer.js │ ├── TokenizerRegex.js │ ├── TokenizerRegexLine.js │ └── index.js └── remover.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.bak 3 | 4 | src/parser/test.js 5 | src/parser/result.json 6 | config/config.custom.js 7 | 8 | node_modules/ 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | NamuWikiBot : A telegram bot which searches namu.wiki. 633 | Copyright (C) 2016 Khinenw 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NamuWikiBot 2 | 나무위키를 검색하는 텔레그램봇 3 | 4 | ## 사용법 5 | [링크](https://telegram.me/namuwikiBot) 을 눌러 채팅방에 추가한다. 6 | 7 | ## 명령어 8 | /nw [검색할 것] : 나무위키를 검색해서 간단한 설명과 링크를 보낸다. 9 | 10 | ## 저작권 11 | 사용한 이미지 (CC-BY-NC-SA 2.0): 12 | 13 | 1. 무냐 by eb 14 | 15 | 2. 세피로트 by SMINORFF_KAMCHATKA 16 | -------------------------------------------------------------------------------- /config/config.default.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | token: null, 3 | 4 | update: { 5 | mode: 'passive', 6 | 7 | passive: { 8 | url: 'https://namu.khinenw.tk/', 9 | cert: false 10 | }, 11 | 12 | active: { 13 | interval: 1000 14 | } 15 | }, 16 | 17 | failSticker: [ 18 | "AAQFABPA2r0yAAQ83MiKrz-riLwdAAIC", 19 | "AAQFABPW5b0yAAT1FavQm3UInFMEAAIC", 20 | "CAADBQADMAADUZLAVkoN4oAcmBapAg" 21 | ], 22 | 23 | request: { 24 | userAgent: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36", 25 | url: "https://namu.wiki/w/", 26 | rawUrl: "https://namu.wiki/raw/", 27 | searchUrl: "https://namu.wiki/search/", 28 | completeUrl: "https://namu.wiki/complete/", 29 | interval: 100 30 | }, 31 | 32 | attempt: { 33 | commands: 10, 34 | expire: 60000 35 | }, 36 | 37 | inline: { 38 | amount: 1, 39 | gcInterval: 60000 40 | }, 41 | 42 | namuwiki: { 43 | maxRedirection: 5, 44 | overviewLength: 1024, 45 | branchAmount: 8 46 | }, 47 | 48 | remove: { 49 | bold: 'tag', 50 | italic: 'tag', 51 | underline: 'tag', 52 | striken: 'whole', 53 | 54 | superscript: 'whole', 55 | subscript: 'whole', 56 | 57 | html: 'whole', 58 | size: 'tag', 59 | color: 'tag', 60 | nomarkup: 'tag', 61 | 62 | attachment: 'replace', 63 | image: 'replace', 64 | namuimage: 'replace', 65 | 66 | hyperlink: 'replace|noparagraph', //(replace, former, latter, tag, whole)|(paragraph, noparagraph) 67 | 68 | line: 'replace', 69 | youtube: 'replace', 70 | quote: 'replace', //replace changes it to grave accent. Because there is no quote in telegram. 71 | table: 'tag', 72 | include: 'whole', 73 | toc: 'replace', 74 | footnote_macro: 'replace', 75 | age: 'replace', 76 | date: 'replace', 77 | pagecount: 'replace', 78 | footnote: 'whole', 79 | 80 | finalizer: true 81 | } 82 | }; 83 | -------------------------------------------------------------------------------- /config/index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('object-merge')(require('./config.default.js'), require('./config.custom.js')); 2 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const bodyParser = require('body-parser'); 3 | const chalk = require('chalk'); 4 | const express = require('express'); 5 | const fs = require('fs'); 6 | const http = require('http'); 7 | const morgan = require('morgan'); 8 | 9 | const config = require('./config/'); 10 | const {fixedURIencode} = require('./src/Utils'); 11 | const translation = require('./resources/text.json'); 12 | const packageInfo = require('./package.json'); 13 | 14 | const ApiHandler = require('./src/ApiHandler'); 15 | const InlineStore = require('./src/InlineStore'); 16 | const Logger = require('./src/Logger'); 17 | const NamuRouter = require('./src/NamuRouter'); 18 | const Telegram = require('./src/Telegram'); 19 | 20 | const isDev = (process.env.NODE_ENV || 'development') === 'development'; 21 | 22 | const app = express(); 23 | const inlineStore = new InlineStore(); 24 | const namuRouter = new NamuRouter(); 25 | const telegram = new Telegram(isDev); 26 | 27 | const logger = new Logger(telegram, translation); 28 | const handler = new ApiHandler(inlineStore, logger, telegram, translation); 29 | 30 | namuRouter.on('message', async (message) => { 31 | const chatId = message.chat.id; 32 | const from = message.from.id; 33 | if(typeof message.text !== 'string') return; 34 | 35 | await handler.handleMessage(from, chatId, message); 36 | }); 37 | 38 | namuRouter.on('inline.callback.query', async (query) => { 39 | try{ 40 | await telegram.apiCall('answerCallbackQuery', { 41 | callback_query_id: query.id 42 | }); 43 | } catch(err) { 44 | logError(err, {}); 45 | return; 46 | } 47 | 48 | const queryData = inlineStore.get(query.data); 49 | 50 | if(queryData === undefined){ 51 | await telegram.ignoredApiCall('sendMessage', { 52 | chat_id: query.from.id, 53 | text: translation.query_invalid 54 | }); 55 | 56 | return; 57 | } 58 | 59 | await handler.handleMessage(query.from.id, queryData.to, { 60 | text: queryData.url 61 | }); 62 | }); 63 | 64 | namuRouter.on('inline.query', async (query) => { 65 | await handler.handleInline(query.from.id, query.query, query.id); 66 | }); 67 | 68 | const createServer = async (app) => { 69 | const port = ((val) => { 70 | const portNumber = parseInt(val, 10); 71 | 72 | if(isNaN(portNumber)){ 73 | return val; 74 | } 75 | 76 | if(portNumber >= 0){ 77 | return portNumber; 78 | } 79 | 80 | return false; 81 | })(process.env.PORT || config.update.passive.cert ? '443' : '80'); 82 | app.set('port', port); 83 | 84 | const cert = config.update.passive.cert; 85 | const formData = { 86 | url: `${config.update.passive.url}${config.token}` 87 | }; 88 | let options, httpServer; 89 | 90 | if(cert) { 91 | options = { 92 | key: fs.readFileSync(path.resolve(cert, 'key.pem')), 93 | crt: fs.readFileSync(path.resolve(cert, 'crt.pem')) 94 | }; 95 | 96 | httpServer = http.createServer(options, app); 97 | formData.certificate = fs.createReadStream('./cert/crt.pem'); 98 | 99 | } else httpServer = http.createServer(app); 100 | 101 | httpServer.listen(port); 102 | httpServer.on('error', (err) => { 103 | if(err.syscall !== 'listen') throw err; 104 | const bind = typeof port === 'string' ? 'Pipe ' + port : 'Port ' + port; 105 | 106 | switch(err.code){ 107 | case 'EACCES': 108 | console.error(chalk.bgRed('Permission Denied!')); 109 | process.exit(1); 110 | return; 111 | 112 | case 'EADDRINUSE': 113 | console.error(chalk.bgRed('Address in use!')); 114 | process.exit(1); 115 | return; 116 | } 117 | 118 | throw error; 119 | }); 120 | 121 | httpServer.on('listening', () => { 122 | const addr = httpServer.address(); 123 | console.log(chalk.magenta( 124 | (typeof addr === 'string') ? `Pipe ${addr}` : `Listening on port ${addr.port}`) 125 | ); 126 | }); 127 | 128 | await telegram.apiCall('setWebhook', formData); 129 | }; 130 | 131 | console.log(chalk.bgCyan("namuwikiBot " + packageInfo.version)); 132 | if(isDev) { 133 | console.log(chalk.black(chalk.bgYellow(`!! WARNING / namuwikiBot is running in "CONSTRUCTION MODE" / WARNING !!`))); 134 | } 135 | 136 | if(config.update.mode === 'passive') { 137 | console.log(chalk.blue("Using Passive(Web Hook) Mode")); 138 | 139 | if(isDev) app.use(morgan('dev')); 140 | 141 | app.use(bodyParser.text({ 142 | type: 'application/json' 143 | })); 144 | 145 | app.use('/', namuRouter.router); 146 | 147 | app.use((req, res, next) => { 148 | res.redirect('https://telegram.me/namuwikiBot'); 149 | }); 150 | 151 | createServer(app); 152 | } else { 153 | console.log(chalk.red("Using Active(Long Poll) Mode")); 154 | 155 | let offset = 0; 156 | const poll = async () => { 157 | try { 158 | const args = {}; 159 | if(offset) args.offset = offset; 160 | 161 | const respObject = await telegram.apiCall('getUpdates', args); 162 | if(!respObject.ok) throw new Error("Request failed with " + respObject.description); 163 | 164 | respObject.result.forEach(item => { 165 | namuRouter.handleItem(item); 166 | offset = Math.max(item.update_id + 1, offset); 167 | }); 168 | } catch(e) { 169 | logger.logError(e, { 170 | While: 'Polling' 171 | }); 172 | } 173 | 174 | process.nextTick(poll); 175 | }; 176 | 177 | telegram.apiCall('deleteWebhook').then(() => { 178 | poll(); 179 | }); 180 | } 181 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "namuwikibot", 3 | "version": "2.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@types/node": { 8 | "version": "11.11.6", 9 | "resolved": "https://registry.npmjs.org/@types/node/-/node-11.11.6.tgz", 10 | "integrity": "sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ==" 11 | }, 12 | "accepts": { 13 | "version": "1.3.5", 14 | "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", 15 | "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", 16 | "requires": { 17 | "mime-types": "~2.1.18", 18 | "negotiator": "0.6.1" 19 | } 20 | }, 21 | "ajv": { 22 | "version": "6.10.0", 23 | "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", 24 | "integrity": "sha512-nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYwYVIIH1TvE3tu4OEg==", 25 | "requires": { 26 | "fast-deep-equal": "^2.0.1", 27 | "fast-json-stable-stringify": "^2.0.0", 28 | "json-schema-traverse": "^0.4.1", 29 | "uri-js": "^4.2.2" 30 | } 31 | }, 32 | "ansi-regex": { 33 | "version": "2.1.1", 34 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", 35 | "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" 36 | }, 37 | "ansi-styles": { 38 | "version": "2.2.1", 39 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", 40 | "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" 41 | }, 42 | "array-flatten": { 43 | "version": "1.1.1", 44 | "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 45 | "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" 46 | }, 47 | "asn1": { 48 | "version": "0.2.4", 49 | "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz", 50 | "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==", 51 | "requires": { 52 | "safer-buffer": "~2.1.0" 53 | } 54 | }, 55 | "assert-plus": { 56 | "version": "1.0.0", 57 | "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", 58 | "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" 59 | }, 60 | "async": { 61 | "version": "1.5.2", 62 | "resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz", 63 | "integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=" 64 | }, 65 | "asynckit": { 66 | "version": "0.4.0", 67 | "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", 68 | "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" 69 | }, 70 | "aws-sign2": { 71 | "version": "0.7.0", 72 | "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", 73 | "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" 74 | }, 75 | "aws4": { 76 | "version": "1.8.0", 77 | "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", 78 | "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" 79 | }, 80 | "basic-auth": { 81 | "version": "2.0.1", 82 | "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", 83 | "integrity": "sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==", 84 | "requires": { 85 | "safe-buffer": "5.1.2" 86 | } 87 | }, 88 | "bcrypt-pbkdf": { 89 | "version": "1.0.2", 90 | "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", 91 | "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", 92 | "requires": { 93 | "tweetnacl": "^0.14.3" 94 | } 95 | }, 96 | "bluebird": { 97 | "version": "3.5.3", 98 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.3.tgz", 99 | "integrity": "sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==" 100 | }, 101 | "body-parser": { 102 | "version": "1.18.3", 103 | "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", 104 | "integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=", 105 | "requires": { 106 | "bytes": "3.0.0", 107 | "content-type": "~1.0.4", 108 | "debug": "2.6.9", 109 | "depd": "~1.1.2", 110 | "http-errors": "~1.6.3", 111 | "iconv-lite": "0.4.23", 112 | "on-finished": "~2.3.0", 113 | "qs": "6.5.2", 114 | "raw-body": "2.3.3", 115 | "type-is": "~1.6.16" 116 | } 117 | }, 118 | "boolbase": { 119 | "version": "1.0.0", 120 | "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", 121 | "integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24=" 122 | }, 123 | "bytes": { 124 | "version": "3.0.0", 125 | "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", 126 | "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" 127 | }, 128 | "caseless": { 129 | "version": "0.12.0", 130 | "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", 131 | "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" 132 | }, 133 | "chalk": { 134 | "version": "1.1.3", 135 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", 136 | "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", 137 | "requires": { 138 | "ansi-styles": "^2.2.1", 139 | "escape-string-regexp": "^1.0.2", 140 | "has-ansi": "^2.0.0", 141 | "strip-ansi": "^3.0.0", 142 | "supports-color": "^2.0.0" 143 | } 144 | }, 145 | "cheerio": { 146 | "version": "1.0.0-rc.2", 147 | "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.2.tgz", 148 | "integrity": "sha1-S59TqBsn5NXawxwP/Qz6A8xoMNs=", 149 | "requires": { 150 | "css-select": "~1.2.0", 151 | "dom-serializer": "~0.1.0", 152 | "entities": "~1.1.1", 153 | "htmlparser2": "^3.9.1", 154 | "lodash": "^4.15.0", 155 | "parse5": "^3.0.1" 156 | } 157 | }, 158 | "clone-function": { 159 | "version": "1.0.6", 160 | "resolved": "https://registry.npmjs.org/clone-function/-/clone-function-1.0.6.tgz", 161 | "integrity": "sha1-QoRxk3dQvKnEjsv7wW9uIy90oD0=" 162 | }, 163 | "combined-stream": { 164 | "version": "1.0.7", 165 | "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", 166 | "integrity": "sha512-brWl9y6vOB1xYPZcpZde3N9zDByXTosAeMDo4p1wzo6UMOX4vumB+TP1RZ76sfE6Md68Q0NJSrE/gbezd4Ul+w==", 167 | "requires": { 168 | "delayed-stream": "~1.0.0" 169 | } 170 | }, 171 | "content-disposition": { 172 | "version": "0.5.2", 173 | "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", 174 | "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" 175 | }, 176 | "content-type": { 177 | "version": "1.0.4", 178 | "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", 179 | "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" 180 | }, 181 | "cookie": { 182 | "version": "0.3.1", 183 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", 184 | "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" 185 | }, 186 | "cookie-signature": { 187 | "version": "1.0.6", 188 | "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", 189 | "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" 190 | }, 191 | "core-util-is": { 192 | "version": "1.0.2", 193 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", 194 | "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" 195 | }, 196 | "css-select": { 197 | "version": "1.2.0", 198 | "resolved": "https://registry.npmjs.org/css-select/-/css-select-1.2.0.tgz", 199 | "integrity": "sha1-KzoRBTnFNV8c2NMUYj6HCxIeyFg=", 200 | "requires": { 201 | "boolbase": "~1.0.0", 202 | "css-what": "2.1", 203 | "domutils": "1.5.1", 204 | "nth-check": "~1.0.1" 205 | } 206 | }, 207 | "css-what": { 208 | "version": "2.1.3", 209 | "resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.3.tgz", 210 | "integrity": "sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg==" 211 | }, 212 | "dashdash": { 213 | "version": "1.14.1", 214 | "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", 215 | "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", 216 | "requires": { 217 | "assert-plus": "^1.0.0" 218 | } 219 | }, 220 | "debug": { 221 | "version": "2.6.9", 222 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 223 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", 224 | "requires": { 225 | "ms": "2.0.0" 226 | } 227 | }, 228 | "delayed-stream": { 229 | "version": "1.0.0", 230 | "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", 231 | "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" 232 | }, 233 | "depd": { 234 | "version": "1.1.2", 235 | "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", 236 | "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" 237 | }, 238 | "destroy": { 239 | "version": "1.0.4", 240 | "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", 241 | "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" 242 | }, 243 | "dom-serializer": { 244 | "version": "0.1.1", 245 | "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz", 246 | "integrity": "sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA==", 247 | "requires": { 248 | "domelementtype": "^1.3.0", 249 | "entities": "^1.1.1" 250 | } 251 | }, 252 | "domelementtype": { 253 | "version": "1.3.1", 254 | "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz", 255 | "integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==" 256 | }, 257 | "domhandler": { 258 | "version": "2.4.2", 259 | "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz", 260 | "integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==", 261 | "requires": { 262 | "domelementtype": "1" 263 | } 264 | }, 265 | "domutils": { 266 | "version": "1.5.1", 267 | "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", 268 | "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", 269 | "requires": { 270 | "dom-serializer": "0", 271 | "domelementtype": "1" 272 | } 273 | }, 274 | "ecc-jsbn": { 275 | "version": "0.1.2", 276 | "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", 277 | "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", 278 | "requires": { 279 | "jsbn": "~0.1.0", 280 | "safer-buffer": "^2.1.0" 281 | } 282 | }, 283 | "ee-first": { 284 | "version": "1.1.1", 285 | "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 286 | "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 287 | }, 288 | "encodeurl": { 289 | "version": "1.0.2", 290 | "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 291 | "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" 292 | }, 293 | "entities": { 294 | "version": "1.1.2", 295 | "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", 296 | "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==" 297 | }, 298 | "escape-html": { 299 | "version": "1.0.3", 300 | "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 301 | "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" 302 | }, 303 | "escape-string-regexp": { 304 | "version": "1.0.5", 305 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", 306 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" 307 | }, 308 | "etag": { 309 | "version": "1.8.1", 310 | "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", 311 | "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" 312 | }, 313 | "express": { 314 | "version": "4.16.4", 315 | "resolved": "https://registry.npmjs.org/express/-/express-4.16.4.tgz", 316 | "integrity": "sha512-j12Uuyb4FMrd/qQAm6uCHAkPtO8FDTRJZBDd5D2KOL2eLaz1yUNdUB/NOIyq0iU4q4cFarsUCrnFDPBcnksuOg==", 317 | "requires": { 318 | "accepts": "~1.3.5", 319 | "array-flatten": "1.1.1", 320 | "body-parser": "1.18.3", 321 | "content-disposition": "0.5.2", 322 | "content-type": "~1.0.4", 323 | "cookie": "0.3.1", 324 | "cookie-signature": "1.0.6", 325 | "debug": "2.6.9", 326 | "depd": "~1.1.2", 327 | "encodeurl": "~1.0.2", 328 | "escape-html": "~1.0.3", 329 | "etag": "~1.8.1", 330 | "finalhandler": "1.1.1", 331 | "fresh": "0.5.2", 332 | "merge-descriptors": "1.0.1", 333 | "methods": "~1.1.2", 334 | "on-finished": "~2.3.0", 335 | "parseurl": "~1.3.2", 336 | "path-to-regexp": "0.1.7", 337 | "proxy-addr": "~2.0.4", 338 | "qs": "6.5.2", 339 | "range-parser": "~1.2.0", 340 | "safe-buffer": "5.1.2", 341 | "send": "0.16.2", 342 | "serve-static": "1.13.2", 343 | "setprototypeof": "1.1.0", 344 | "statuses": "~1.4.0", 345 | "type-is": "~1.6.16", 346 | "utils-merge": "1.0.1", 347 | "vary": "~1.1.2" 348 | }, 349 | "dependencies": { 350 | "statuses": { 351 | "version": "1.4.0", 352 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", 353 | "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" 354 | } 355 | } 356 | }, 357 | "extend": { 358 | "version": "3.0.2", 359 | "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", 360 | "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" 361 | }, 362 | "extsprintf": { 363 | "version": "1.3.0", 364 | "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", 365 | "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" 366 | }, 367 | "fast-deep-equal": { 368 | "version": "2.0.1", 369 | "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", 370 | "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=" 371 | }, 372 | "fast-json-stable-stringify": { 373 | "version": "2.0.0", 374 | "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", 375 | "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" 376 | }, 377 | "finalhandler": { 378 | "version": "1.1.1", 379 | "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz", 380 | "integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==", 381 | "requires": { 382 | "debug": "2.6.9", 383 | "encodeurl": "~1.0.2", 384 | "escape-html": "~1.0.3", 385 | "on-finished": "~2.3.0", 386 | "parseurl": "~1.3.2", 387 | "statuses": "~1.4.0", 388 | "unpipe": "~1.0.0" 389 | }, 390 | "dependencies": { 391 | "statuses": { 392 | "version": "1.4.0", 393 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", 394 | "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" 395 | } 396 | } 397 | }, 398 | "forever-agent": { 399 | "version": "0.6.1", 400 | "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", 401 | "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" 402 | }, 403 | "form-data": { 404 | "version": "2.3.3", 405 | "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", 406 | "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", 407 | "requires": { 408 | "asynckit": "^0.4.0", 409 | "combined-stream": "^1.0.6", 410 | "mime-types": "^2.1.12" 411 | } 412 | }, 413 | "forwarded": { 414 | "version": "0.1.2", 415 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", 416 | "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" 417 | }, 418 | "fresh": { 419 | "version": "0.5.2", 420 | "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 421 | "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" 422 | }, 423 | "getpass": { 424 | "version": "0.1.7", 425 | "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", 426 | "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", 427 | "requires": { 428 | "assert-plus": "^1.0.0" 429 | } 430 | }, 431 | "har-schema": { 432 | "version": "2.0.0", 433 | "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", 434 | "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" 435 | }, 436 | "har-validator": { 437 | "version": "5.1.3", 438 | "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.3.tgz", 439 | "integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==", 440 | "requires": { 441 | "ajv": "^6.5.5", 442 | "har-schema": "^2.0.0" 443 | } 444 | }, 445 | "has-ansi": { 446 | "version": "2.0.0", 447 | "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", 448 | "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", 449 | "requires": { 450 | "ansi-regex": "^2.0.0" 451 | } 452 | }, 453 | "html-truncate": { 454 | "version": "1.2.2", 455 | "resolved": "https://registry.npmjs.org/html-truncate/-/html-truncate-1.2.2.tgz", 456 | "integrity": "sha1-2y4zHc8cugvUMqUH0W6YhgnyV18=" 457 | }, 458 | "htmlparser2": { 459 | "version": "3.10.1", 460 | "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz", 461 | "integrity": "sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==", 462 | "requires": { 463 | "domelementtype": "^1.3.1", 464 | "domhandler": "^2.3.0", 465 | "domutils": "^1.5.1", 466 | "entities": "^1.1.1", 467 | "inherits": "^2.0.1", 468 | "readable-stream": "^3.1.1" 469 | } 470 | }, 471 | "http-errors": { 472 | "version": "1.6.3", 473 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", 474 | "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", 475 | "requires": { 476 | "depd": "~1.1.2", 477 | "inherits": "2.0.3", 478 | "setprototypeof": "1.1.0", 479 | "statuses": ">= 1.4.0 < 2" 480 | } 481 | }, 482 | "http-signature": { 483 | "version": "1.2.0", 484 | "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", 485 | "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", 486 | "requires": { 487 | "assert-plus": "^1.0.0", 488 | "jsprim": "^1.2.2", 489 | "sshpk": "^1.7.0" 490 | } 491 | }, 492 | "iconv-lite": { 493 | "version": "0.4.23", 494 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz", 495 | "integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==", 496 | "requires": { 497 | "safer-buffer": ">= 2.1.2 < 3" 498 | } 499 | }, 500 | "inherits": { 501 | "version": "2.0.3", 502 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 503 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 504 | }, 505 | "ipaddr.js": { 506 | "version": "1.8.0", 507 | "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz", 508 | "integrity": "sha1-6qM9bd16zo9/b+DJygRA5wZzix4=" 509 | }, 510 | "is-typedarray": { 511 | "version": "1.0.0", 512 | "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", 513 | "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" 514 | }, 515 | "isstream": { 516 | "version": "0.1.2", 517 | "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", 518 | "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" 519 | }, 520 | "jsbn": { 521 | "version": "0.1.1", 522 | "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", 523 | "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" 524 | }, 525 | "json-schema": { 526 | "version": "0.2.3", 527 | "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz", 528 | "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" 529 | }, 530 | "json-schema-traverse": { 531 | "version": "0.4.1", 532 | "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", 533 | "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" 534 | }, 535 | "json-stringify-safe": { 536 | "version": "5.0.1", 537 | "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", 538 | "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" 539 | }, 540 | "jsprim": { 541 | "version": "1.4.1", 542 | "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", 543 | "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", 544 | "requires": { 545 | "assert-plus": "1.0.0", 546 | "extsprintf": "1.3.0", 547 | "json-schema": "0.2.3", 548 | "verror": "1.10.0" 549 | } 550 | }, 551 | "lodash": { 552 | "version": "4.17.11", 553 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", 554 | "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" 555 | }, 556 | "media-typer": { 557 | "version": "0.3.0", 558 | "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 559 | "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" 560 | }, 561 | "merge-descriptors": { 562 | "version": "1.0.1", 563 | "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", 564 | "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" 565 | }, 566 | "methods": { 567 | "version": "1.1.2", 568 | "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", 569 | "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" 570 | }, 571 | "mime": { 572 | "version": "1.4.1", 573 | "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", 574 | "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" 575 | }, 576 | "mime-db": { 577 | "version": "1.38.0", 578 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.38.0.tgz", 579 | "integrity": "sha512-bqVioMFFzc2awcdJZIzR3HjZFX20QhilVS7hytkKrv7xFAn8bM1gzc/FOX2awLISvWe0PV8ptFKcon+wZ5qYkg==" 580 | }, 581 | "mime-types": { 582 | "version": "2.1.22", 583 | "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.22.tgz", 584 | "integrity": "sha512-aGl6TZGnhm/li6F7yx82bJiBZwgiEa4Hf6CNr8YO+r5UHr53tSTYZb102zyU50DOWWKeOv0uQLRL0/9EiKWCog==", 585 | "requires": { 586 | "mime-db": "~1.38.0" 587 | } 588 | }, 589 | "morgan": { 590 | "version": "1.9.1", 591 | "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz", 592 | "integrity": "sha512-HQStPIV4y3afTiCYVxirakhlCfGkI161c76kKFca7Fk1JusM//Qeo1ej2XaMniiNeaZklMVrh3vTtIzpzwbpmA==", 593 | "requires": { 594 | "basic-auth": "~2.0.0", 595 | "debug": "2.6.9", 596 | "depd": "~1.1.2", 597 | "on-finished": "~2.3.0", 598 | "on-headers": "~1.0.1" 599 | } 600 | }, 601 | "ms": { 602 | "version": "2.0.0", 603 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 604 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 605 | }, 606 | "negotiator": { 607 | "version": "0.6.1", 608 | "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", 609 | "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" 610 | }, 611 | "nth-check": { 612 | "version": "1.0.2", 613 | "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz", 614 | "integrity": "sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg==", 615 | "requires": { 616 | "boolbase": "~1.0.0" 617 | } 618 | }, 619 | "oauth-sign": { 620 | "version": "0.9.0", 621 | "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", 622 | "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" 623 | }, 624 | "object-foreach": { 625 | "version": "0.1.2", 626 | "resolved": "https://registry.npmjs.org/object-foreach/-/object-foreach-0.1.2.tgz", 627 | "integrity": "sha1-10IcW0DjtqPvV6xiQ2jSHY+NLew=" 628 | }, 629 | "object-merge": { 630 | "version": "2.5.1", 631 | "resolved": "https://registry.npmjs.org/object-merge/-/object-merge-2.5.1.tgz", 632 | "integrity": "sha1-B36JFc446nKUeIRIxd0znjTfQic=", 633 | "requires": { 634 | "clone-function": ">=1.0.1", 635 | "object-foreach": ">=0.1.2" 636 | } 637 | }, 638 | "on-finished": { 639 | "version": "2.3.0", 640 | "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", 641 | "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", 642 | "requires": { 643 | "ee-first": "1.1.1" 644 | } 645 | }, 646 | "on-headers": { 647 | "version": "1.0.2", 648 | "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", 649 | "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==" 650 | }, 651 | "parse5": { 652 | "version": "3.0.3", 653 | "resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz", 654 | "integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==", 655 | "requires": { 656 | "@types/node": "*" 657 | } 658 | }, 659 | "parseurl": { 660 | "version": "1.3.2", 661 | "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", 662 | "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" 663 | }, 664 | "path-to-regexp": { 665 | "version": "0.1.7", 666 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", 667 | "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" 668 | }, 669 | "performance-now": { 670 | "version": "2.1.0", 671 | "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", 672 | "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" 673 | }, 674 | "proxy-addr": { 675 | "version": "2.0.4", 676 | "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.4.tgz", 677 | "integrity": "sha512-5erio2h9jp5CHGwcybmxmVqHmnCBZeewlfJ0pex+UW7Qny7OOZXTtH56TGNyBizkgiOwhJtMKrVzDTeKcySZwA==", 678 | "requires": { 679 | "forwarded": "~0.1.2", 680 | "ipaddr.js": "1.8.0" 681 | } 682 | }, 683 | "psl": { 684 | "version": "1.1.31", 685 | "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz", 686 | "integrity": "sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw==" 687 | }, 688 | "punycode": { 689 | "version": "2.1.1", 690 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", 691 | "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" 692 | }, 693 | "qs": { 694 | "version": "6.5.2", 695 | "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", 696 | "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" 697 | }, 698 | "range-parser": { 699 | "version": "1.2.0", 700 | "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", 701 | "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" 702 | }, 703 | "raw-body": { 704 | "version": "2.3.3", 705 | "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.3.tgz", 706 | "integrity": "sha512-9esiElv1BrZoI3rCDuOuKCBRbuApGGaDPQfjSflGxdy4oyzqghxu6klEkkVIvBje+FF0BX9coEv8KqW6X/7njw==", 707 | "requires": { 708 | "bytes": "3.0.0", 709 | "http-errors": "1.6.3", 710 | "iconv-lite": "0.4.23", 711 | "unpipe": "1.0.0" 712 | } 713 | }, 714 | "readable-stream": { 715 | "version": "3.2.0", 716 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.2.0.tgz", 717 | "integrity": "sha512-RV20kLjdmpZuTF1INEb9IA3L68Nmi+Ri7ppZqo78wj//Pn62fCoJyV9zalccNzDD/OuJpMG4f+pfMl8+L6QdGw==", 718 | "requires": { 719 | "inherits": "^2.0.3", 720 | "string_decoder": "^1.1.1", 721 | "util-deprecate": "^1.0.1" 722 | } 723 | }, 724 | "request": { 725 | "version": "2.88.0", 726 | "resolved": "https://registry.npmjs.org/request/-/request-2.88.0.tgz", 727 | "integrity": "sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==", 728 | "requires": { 729 | "aws-sign2": "~0.7.0", 730 | "aws4": "^1.8.0", 731 | "caseless": "~0.12.0", 732 | "combined-stream": "~1.0.6", 733 | "extend": "~3.0.2", 734 | "forever-agent": "~0.6.1", 735 | "form-data": "~2.3.2", 736 | "har-validator": "~5.1.0", 737 | "http-signature": "~1.2.0", 738 | "is-typedarray": "~1.0.0", 739 | "isstream": "~0.1.2", 740 | "json-stringify-safe": "~5.0.1", 741 | "mime-types": "~2.1.19", 742 | "oauth-sign": "~0.9.0", 743 | "performance-now": "^2.1.0", 744 | "qs": "~6.5.2", 745 | "safe-buffer": "^5.1.2", 746 | "tough-cookie": "~2.4.3", 747 | "tunnel-agent": "^0.6.0", 748 | "uuid": "^3.3.2" 749 | }, 750 | "dependencies": { 751 | "punycode": { 752 | "version": "1.4.1", 753 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", 754 | "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" 755 | }, 756 | "tough-cookie": { 757 | "version": "2.4.3", 758 | "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", 759 | "integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==", 760 | "requires": { 761 | "psl": "^1.1.24", 762 | "punycode": "^1.4.1" 763 | } 764 | } 765 | } 766 | }, 767 | "request-promise": { 768 | "version": "4.2.4", 769 | "resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.4.tgz", 770 | "integrity": "sha512-8wgMrvE546PzbR5WbYxUQogUnUDfM0S7QIFZMID+J73vdFARkFy+HElj4T+MWYhpXwlLp0EQ8Zoj8xUA0he4Vg==", 771 | "requires": { 772 | "bluebird": "^3.5.0", 773 | "request-promise-core": "1.1.2", 774 | "stealthy-require": "^1.1.1", 775 | "tough-cookie": "^2.3.3" 776 | } 777 | }, 778 | "request-promise-core": { 779 | "version": "1.1.2", 780 | "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.2.tgz", 781 | "integrity": "sha512-UHYyq1MO8GsefGEt7EprS8UrXsm1TxEvFUX1IMTuSLU2Rh7fTIdFtl8xD7JiEYiWU2dl+NYAjCTksTehQUxPag==", 782 | "requires": { 783 | "lodash": "^4.17.11" 784 | } 785 | }, 786 | "safe-buffer": { 787 | "version": "5.1.2", 788 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 789 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 790 | }, 791 | "safer-buffer": { 792 | "version": "2.1.2", 793 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 794 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 795 | }, 796 | "send": { 797 | "version": "0.16.2", 798 | "resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz", 799 | "integrity": "sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw==", 800 | "requires": { 801 | "debug": "2.6.9", 802 | "depd": "~1.1.2", 803 | "destroy": "~1.0.4", 804 | "encodeurl": "~1.0.2", 805 | "escape-html": "~1.0.3", 806 | "etag": "~1.8.1", 807 | "fresh": "0.5.2", 808 | "http-errors": "~1.6.2", 809 | "mime": "1.4.1", 810 | "ms": "2.0.0", 811 | "on-finished": "~2.3.0", 812 | "range-parser": "~1.2.0", 813 | "statuses": "~1.4.0" 814 | }, 815 | "dependencies": { 816 | "statuses": { 817 | "version": "1.4.0", 818 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", 819 | "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" 820 | } 821 | } 822 | }, 823 | "serve-static": { 824 | "version": "1.13.2", 825 | "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz", 826 | "integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==", 827 | "requires": { 828 | "encodeurl": "~1.0.2", 829 | "escape-html": "~1.0.3", 830 | "parseurl": "~1.3.2", 831 | "send": "0.16.2" 832 | } 833 | }, 834 | "setprototypeof": { 835 | "version": "1.1.0", 836 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", 837 | "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" 838 | }, 839 | "sshpk": { 840 | "version": "1.16.1", 841 | "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", 842 | "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==", 843 | "requires": { 844 | "asn1": "~0.2.3", 845 | "assert-plus": "^1.0.0", 846 | "bcrypt-pbkdf": "^1.0.0", 847 | "dashdash": "^1.12.0", 848 | "ecc-jsbn": "~0.1.1", 849 | "getpass": "^0.1.1", 850 | "jsbn": "~0.1.0", 851 | "safer-buffer": "^2.0.2", 852 | "tweetnacl": "~0.14.0" 853 | } 854 | }, 855 | "statuses": { 856 | "version": "1.5.0", 857 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", 858 | "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" 859 | }, 860 | "stealthy-require": { 861 | "version": "1.1.1", 862 | "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", 863 | "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=" 864 | }, 865 | "string_decoder": { 866 | "version": "1.2.0", 867 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.2.0.tgz", 868 | "integrity": "sha512-6YqyX6ZWEYguAxgZzHGL7SsCeGx3V2TtOTqZz1xSTSWnqsbWwbptafNyvf/ACquZUXV3DANr5BDIwNYe1mN42w==", 869 | "requires": { 870 | "safe-buffer": "~5.1.0" 871 | } 872 | }, 873 | "strip-ansi": { 874 | "version": "3.0.1", 875 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", 876 | "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", 877 | "requires": { 878 | "ansi-regex": "^2.0.0" 879 | } 880 | }, 881 | "supports-color": { 882 | "version": "2.0.0", 883 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", 884 | "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" 885 | }, 886 | "tough-cookie": { 887 | "version": "2.5.0", 888 | "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", 889 | "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", 890 | "requires": { 891 | "psl": "^1.1.28", 892 | "punycode": "^2.1.1" 893 | } 894 | }, 895 | "tunnel-agent": { 896 | "version": "0.6.0", 897 | "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", 898 | "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", 899 | "requires": { 900 | "safe-buffer": "^5.0.1" 901 | } 902 | }, 903 | "tweetnacl": { 904 | "version": "0.14.5", 905 | "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", 906 | "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" 907 | }, 908 | "type-is": { 909 | "version": "1.6.16", 910 | "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", 911 | "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==", 912 | "requires": { 913 | "media-typer": "0.3.0", 914 | "mime-types": "~2.1.18" 915 | } 916 | }, 917 | "unpipe": { 918 | "version": "1.0.0", 919 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 920 | "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" 921 | }, 922 | "uri-js": { 923 | "version": "4.2.2", 924 | "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", 925 | "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", 926 | "requires": { 927 | "punycode": "^2.1.0" 928 | } 929 | }, 930 | "util-deprecate": { 931 | "version": "1.0.2", 932 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 933 | "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" 934 | }, 935 | "utils-merge": { 936 | "version": "1.0.1", 937 | "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", 938 | "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" 939 | }, 940 | "uuid": { 941 | "version": "3.3.2", 942 | "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz", 943 | "integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==" 944 | }, 945 | "vary": { 946 | "version": "1.1.2", 947 | "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", 948 | "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" 949 | }, 950 | "verror": { 951 | "version": "1.10.0", 952 | "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", 953 | "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", 954 | "requires": { 955 | "assert-plus": "^1.0.0", 956 | "core-util-is": "1.0.2", 957 | "extsprintf": "^1.2.0" 958 | } 959 | } 960 | } 961 | } 962 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "namuwikibot", 3 | "version": "2.0.0", 4 | "description": "A telegram bot which searches namu.wiki.", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "dependencies": { 11 | "async": "^1.5.1", 12 | "body-parser": "^1.15.0", 13 | "chalk": "^1.1.1", 14 | "cheerio": "^1.0.0-rc.2", 15 | "express": "^4.13.4", 16 | "html-truncate": "^1.2.2", 17 | "morgan": "^1.7.0", 18 | "object-merge": "^2.5.1", 19 | "request": "^2.88.0", 20 | "request-promise": "^4.2.1" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "git+https://github.com/HelloWorld017/NamuWikiBot.git" 25 | }, 26 | "keywords": [ 27 | "Namuwiki", 28 | "Telegram" 29 | ], 30 | "author": "Khinenw", 31 | "license": "AGPL-3.0", 32 | "bugs": { 33 | "url": "https://github.com/HelloWorld017/NamuWikiBot/issues" 34 | }, 35 | "homepage": "https://github.com/HelloWorld017/NamuWikiBot#readme" 36 | } 37 | -------------------------------------------------------------------------------- /resources/notfound0.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HelloWorld017/NamuWikiBot/11b97e826dd8e0d1675c088f16a7c3da874f3345/resources/notfound0.webp -------------------------------------------------------------------------------- /resources/notfound1.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HelloWorld017/NamuWikiBot/11b97e826dd8e0d1675c088f16a7c3da874f3345/resources/notfound1.webp -------------------------------------------------------------------------------- /resources/notfound2.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HelloWorld017/NamuWikiBot/11b97e826dd8e0d1675c088f16a7c3da874f3345/resources/notfound2.webp -------------------------------------------------------------------------------- /resources/text.json: -------------------------------------------------------------------------------- 1 | { 2 | "attempt": "조금 있다가 해보세요!\n(현재 60초에 명령어 %d개로 제한하고 있습니다.)\n나무위키 본관측에 많은 트래픽이 가는 것을 방지하기 위한 조치이니 협조해주시면 감사하겠습니다!", 3 | "search": "검색하실 항목을 선택해주세요!", 4 | "usage": [ 5 | "🌱 나무위키에서 궁금한 것을 검색해드립니다!", 6 | "❔ /nw [검색할 항목], /nq [자동 완성]", 7 | "", 8 | "💎 인라인 모드로도 사용가능해요 ><", 9 | "❔ @namuwikiBot [검색할 항목] 후 기다리기", 10 | "", 11 | "🔆 언제 어디에서든지 위키질을 이어가보세요 :D", 12 | "⚠️ 계속 링크를 타다보면 어느샌가 멀리 와 있을 수 있습니다.", 13 | "", 14 | "🛠 개발자: @Khinenw", 15 | "🌐 주소: khinenw.tk", 16 | "☑️ 깃허브: HelloWorld017/namuwikiBot", 17 | "🌀 후원: battle.net/heroes", 18 | "", 19 | "🌉 이미지 저작권: CC-BY-NC-SA 2.0", 20 | "🖋 세피로트: SMINORFF_KAMCHATKA님", 21 | "🌱 무냐: eb님", 22 | "", 23 | "♥️ 나무위키봇을 사용해주시는 사용자분들께 감사드립니다." 24 | ], 25 | "sucuri": "현재 Cloudflare DDoS 프로텍션 때문에 문서에 접근이 불가합니다.", 26 | "query_invalid": "쿼리가 만료되었습니다! /nw@namuwikiBot 명령어를 다시 입력해주세요!", 27 | "query_too_fast": "조금 있다가 다시 해주세요! T_T", 28 | "query_error": "앗, 이런!", 29 | "error": "요청을 처리하는 도중 서버측에서 오류가 발생했습니다! :(\n@Khinenw 에게 제보하여주시면 감사하겠습니다!" 30 | } 31 | -------------------------------------------------------------------------------- /src/ApiHandler.js: -------------------------------------------------------------------------------- 1 | const Attempt = require('./Attempt'); 2 | 3 | const config = require('../config'); 4 | const {fixedURIencode} = require('./Utils'); 5 | const getNamuwiki = require('./Namuwiki'); 6 | const rp = require('request-promise'); 7 | 8 | class ApiHandler { 9 | constructor(inlineStore, logger, telegram, translation) { 10 | this.attempt = new Attempt(config, translation); 11 | this.inlineStore = inlineStore; 12 | this.logger = logger; 13 | this.telegram = telegram; 14 | this.translation = translation; 15 | } 16 | 17 | /* ========== 18 | * Get Reply Markup 19 | * ========== */ 20 | wikiLinks(chatId, links, isSerialized = true) { 21 | const arr = []; 22 | let temparr = []; 23 | 24 | for(let i = 0; i < config.namuwiki.branchAmount; i++) { 25 | if(links.length > i) { 26 | const url = links[i]; 27 | const hash = this.inlineStore.add(url, chatId); 28 | 29 | temparr.push({ 30 | text: url, 31 | callback_data: hash 32 | }); 33 | 34 | if(temparr.length >= 2) { 35 | arr.push(temparr); 36 | temparr = []; 37 | } 38 | } 39 | } 40 | 41 | if(temparr.length > 0) arr.push(temparr); 42 | 43 | if(isSerialized) 44 | return JSON.stringify({ 45 | inline_keyboard: arr 46 | }); 47 | 48 | return { 49 | inline_keyboard: arr 50 | }; 51 | } 52 | 53 | /* ========== 54 | * Get 404 Message 55 | * ========== */ 56 | async search(url, chatId) { 57 | const searchSelector = 'article.wiki-article section a:not(.page-link)'; 58 | let body = ''; 59 | 60 | try { 61 | body = await rp({ 62 | method: 'get', 63 | headers: { 64 | 'User-Agent': config.request.userAgent 65 | }, 66 | url: `${config.request.searchUrl}${fixedURIencode(url)}` 67 | }); 68 | const $ = cheerio.load(body); 69 | const hrefs = $(searchSelector); 70 | const results = []; 71 | 72 | for(let i = 0; i < config.inline.amount; i++) { 73 | if(hrefs.length > i){ 74 | const url = decodeURIComponent($(hrefs.get(i)).attr('href').replace('/w/', '')); 75 | this.inlineStore.add(url, chatId); 76 | 77 | results.push([{ 78 | text: url, 79 | callback_data: hash 80 | }]); 81 | } 82 | } 83 | 84 | await this.telegram.apiCall('sendSticker', { 85 | chat_id: chatId, 86 | sticker: config.failSticker[Math.floor(Math.random() * config.failSticker.length)], 87 | reply_markup: JSON.stringify({ 88 | inline_keyboard: results 89 | }) 90 | }); 91 | 92 | } catch(err) { 93 | await this.logger.logError(err, {Query: url}, chatId); 94 | return; 95 | } 96 | } 97 | 98 | /* ========== 99 | * Command /nq 100 | * ========== */ 101 | async handleQuery(from, chatId, message) { 102 | if(this.attempt.attempt(from)) { 103 | await this.telegram.ignoredApiCall('sendMessage', { 104 | chat_id: chatId, 105 | text: this.attempt.text 106 | }); 107 | 108 | return; 109 | } 110 | 111 | let body; 112 | try { 113 | body = await rp({ 114 | method: 'get', 115 | headers: { 116 | 'User-Agent': config.request.userAgent 117 | }, 118 | url: config.request.completeUrl + 119 | fixedURIencode(message.text.replace(/^\/nq(?:@[a-zA-Z0-9]*)?[ ]*/, '')) 120 | }); 121 | } catch(err) { 122 | await this.logger.logError(err, chatId); 123 | return; 124 | } 125 | 126 | const arr = this.wikiLinks(chatId, JSON.parse(body)); 127 | 128 | await this.telegram.ignoredApiCall('sendMessage', { 129 | chat_id: chatId, 130 | text: this.translation.search, 131 | reply_markup: arr 132 | }); 133 | } 134 | 135 | /* ========== 136 | * Command /nw 137 | * ========== */ 138 | async handleWiki(from, chatId, message) { 139 | if(this.attempt.attempt(from)) { 140 | await this.telegram.ignoredApiCall('sendMessage', { 141 | chat_id: chatId, 142 | text: this.attempt.text 143 | }); 144 | 145 | return; 146 | } 147 | 148 | const url = message.text.replace(/^\/nw(?:@[a-zA-Z0-9]*)?[ ]*/, ''); 149 | if(url === ''){ 150 | await this.telegram.ignoredApiCall('sendMessage', { 151 | chat_id: chatId, 152 | text: this.translation.usage.join('\n'), 153 | disable_web_page_preview: "true", 154 | parse_mode: "html" 155 | }); 156 | 157 | return; 158 | } 159 | 160 | let overview, links; 161 | 162 | try { 163 | ({overview, links} = await getNamuwiki(url)); 164 | } catch (err) { 165 | if(err.status === 404) { 166 | await this.search(url, chatId); 167 | } else if(err.status === 503) { 168 | await this.telegram.ignoredApiCall('sendMessage', { 169 | chat_id: chatId, 170 | text: this.translation.sucuri 171 | }); 172 | } else { 173 | await this.logger.logError(err, { 174 | Query: url 175 | }, chatId); 176 | } 177 | return; 178 | } 179 | 180 | const arr = this.wikiLinks(chatId, links); 181 | 182 | try { 183 | await this.telegram.apiCall('sendMessage', { 184 | chat_id: chatId, 185 | text: overview, 186 | parse_mode: 'html', 187 | reply_markup: arr, 188 | disable_web_page_preview: 'false' 189 | }); 190 | } catch (err) { 191 | await this.logger.logError(err, {Query: url}, chatId); 192 | } 193 | } 194 | 195 | /* ========== 196 | * @namuwikiBot Inline Search 197 | * ========== */ 198 | async handleInline(from, query, id) { 199 | if(this.attempt.attempt(from)){ 200 | await this.telegram.ignoredApiCall('answerInlineQuery', { 201 | inline_query_id: id, 202 | results: [{ 203 | type: 'article', 204 | id: 'query_too_fast', 205 | title: this.translation.query_too_fast, 206 | input_message_content: { 207 | message_text: this.attempt.text 208 | } 209 | }] 210 | }); 211 | 212 | return; 213 | } 214 | 215 | let complete = []; 216 | 217 | try { 218 | complete = await rp({ 219 | method: 'get', 220 | headers: { 221 | 'User-Agent': config.request.userAgent 222 | }, 223 | url: `${config.request.completeUrl}${fixedURIencode(query)}`, 224 | json: true 225 | }); 226 | 227 | if(!Array.isArray(complete)) { 228 | const err = new Error("Returned object is not an array!"); 229 | err.value = complete; 230 | 231 | throw err; 232 | } 233 | } catch (err) { 234 | await this.logger.logError(err, { 235 | Inline: true, 236 | Query: query, 237 | From: from 238 | }); 239 | 240 | await this.telegram.ignoredApiCall('answerInlineQuery', { 241 | inline_query_id: id, 242 | results: [{ 243 | type: 'article', 244 | id: 'query_error', 245 | title: this.translation.query_error, 246 | input_message_content: { 247 | message_text: this.translation.error 248 | } 249 | }] 250 | }); 251 | 252 | return; 253 | } 254 | 255 | const results = []; 256 | 257 | for(let url of complete.slice(0, config.inline.amount)) { 258 | let overview = '', links = []; 259 | 260 | try { 261 | ({overview, links} = await getNamuwiki(url)); 262 | } catch (err) { 263 | if(err.status === 503) { 264 | results.push({ 265 | type: 'article', 266 | id: 'query_sucuri', 267 | title: this.translation.query_error, 268 | input_message_content: { 269 | message_text: this.translation.sucuri 270 | } 271 | }); 272 | } else if(err.status !== 404) { 273 | await this.logger.logError(err, { 274 | Inline: true, 275 | Query: url, 276 | From: from 277 | }); 278 | } 279 | continue; 280 | } 281 | 282 | results.push({ 283 | type: 'article', 284 | id: crypto.createHash('md5').update(url).digest('hex'), 285 | title: url, 286 | message_text: overview, 287 | parse_mode: 'html', 288 | url: config.request.url + fixedURIencode(url) 289 | }); 290 | }; 291 | 292 | try { 293 | await this.telegram.apiCall('answerInlineQuery', { 294 | inline_query_id: id, 295 | results: JSON.stringify(results) 296 | }); 297 | } catch(e) { 298 | this.logger.logError(e, { 299 | Inline: true, 300 | Query: query, 301 | From: from 302 | }); 303 | } 304 | } 305 | 306 | /* ========== 307 | * Handle Overall Messages 308 | * ========== */ 309 | async handleMessage (from, chatId, message) { 310 | if(message.text.startsWith('/nq')){ 311 | await this.handleQuery(from, chatId, message); 312 | } 313 | 314 | if(message.text.startsWith('/nw')){ 315 | await this.handleWiki(from, chatId, message); 316 | } 317 | } 318 | } 319 | 320 | module.exports = ApiHandler; 321 | -------------------------------------------------------------------------------- /src/Attempt.js: -------------------------------------------------------------------------------- 1 | class Attempt { 2 | constructor(config, translation) { 3 | this.commandAmount = config.attempt.commands; 4 | this.expiresIn = config.attempt.expire; 5 | this.text = translation.attempt.replace('%d', this.commandAmount); 6 | this.reqIds = []; 7 | } 8 | 9 | attempt(from) { 10 | if(this.reqIds[from] !== undefined){ 11 | if(this.reqIds[from].date < Date.now()){ 12 | this.reqIds[from].count = 0; 13 | this.reqIds[from].date = Date.now() + this.expiresIn; 14 | } 15 | 16 | if(this.reqIds[from].count >= this.commandAmount){ 17 | return true; 18 | } 19 | 20 | this.reqIds[from].count++; 21 | }else{ 22 | this.reqIds[from] = { 23 | count: 0, 24 | date: Date.now() + this.expiresIn 25 | }; 26 | } 27 | 28 | return false; 29 | }; 30 | } 31 | 32 | module.exports = Attempt; 33 | -------------------------------------------------------------------------------- /src/InlineStore.js: -------------------------------------------------------------------------------- 1 | const crypto = require('crypto'); 2 | const config = require('../config'); 3 | 4 | class InlineStore { 5 | constructor() { 6 | this.store = {}; 7 | 8 | setInterval(() => { 9 | this.removeExpired(); 10 | }, config.inline.gcInterval); 11 | } 12 | 13 | add(url, chatId) { 14 | const hash = crypto.createHash('md5').update(chatId + ':' + url).digest('hex'); 15 | 16 | this.store[hash] = { 17 | url: '/nw ' + url, 18 | to: chatId, 19 | expires: Date.now() + 120 * 1000 20 | }; 21 | 22 | return hash; 23 | } 24 | 25 | removeExpired() { 26 | Object.keys(this.store).forEach((k) => { 27 | if(this.store[k].expires < Date.now()){ 28 | this.store[k] = undefined; 29 | delete this.store[k]; 30 | } 31 | }); 32 | } 33 | 34 | get(key) { 35 | return this.store[key]; 36 | } 37 | } 38 | 39 | module.exports = InlineStore; 40 | -------------------------------------------------------------------------------- /src/Logger.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | const util = require('util'); 3 | 4 | class Logger { 5 | constructor(telegram, translation) { 6 | this.telegram = telegram; 7 | this.translation = translation; 8 | 9 | telegram.logger = this; 10 | } 11 | 12 | async log(logContents, chatId) { 13 | if(chatId) 14 | await this.telegram.ignoredApiCall('sendMessage', { 15 | chat_id: chatId, 16 | text: this.translation.error 17 | }); 18 | 19 | console.log(chalk.bgRed("=======Starting error report=======")); 20 | 21 | Object.keys(logContents).forEach((k) => { 22 | const v = logContents[k]; 23 | console.log(chalk.yellow(k + " : " + v)); 24 | }); 25 | 26 | console.log(chalk.bgRed("========End of error report========")); 27 | } 28 | 29 | async logError(err, additionalInformation, chatId) { 30 | if(err.name === 'StatusCodeError') { 31 | err.response = {}; 32 | } 33 | const logObject = { 34 | Time: new Date().toUTCString(), 35 | Error: util.inspect(err), 36 | From: chatId 37 | }; 38 | 39 | Object.keys(additionalInformation).forEach((k) => { 40 | logObject[k] = additionalInformation[k]; 41 | }); 42 | 43 | return await this.log(logObject, chatId); 44 | } 45 | } 46 | 47 | module.exports = Logger; 48 | -------------------------------------------------------------------------------- /src/NamuRouter.js: -------------------------------------------------------------------------------- 1 | const config = require('../config'); 2 | 3 | const EventEmitter = require('events'); 4 | const {Router} = require('express'); 5 | 6 | class NamuRouter extends EventEmitter { 7 | constructor(token) { 8 | super(); 9 | 10 | this._router = Router(); 11 | this._router.post(`/${token}`, (req, res) => { 12 | const item = JSON.parse(req.body); 13 | res.status(200).send(':D'); 14 | 15 | this.handleItem(item); 16 | }); 17 | } 18 | 19 | handleItem(item) { 20 | this.emit('update', item); 21 | 22 | if(item.callback_query) { 23 | this.emit('inline.callback.query', item.callback_query); 24 | return; 25 | } 26 | 27 | if(item.inline_query) { 28 | this.emit('inline.query', item.inline_query); 29 | return; 30 | } 31 | 32 | if(item.chosen_inline_result) { 33 | this.emit('inline.result', item.chosen_inline_result); 34 | return; 35 | } 36 | 37 | if(item.message) this.emit('message', item.message); 38 | } 39 | 40 | get router() { 41 | return this._router; 42 | } 43 | } 44 | 45 | module.exports = NamuRouter; 46 | -------------------------------------------------------------------------------- /src/Namuwiki.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | const cheerio = require('cheerio'); 3 | const config = require('../config'); 4 | const {fixedURIencode} = require('./Utils'); 5 | const remover = require('./Remover'); 6 | const rp = require('request-promise'); 7 | const truncate = require('html-truncate'); 8 | 9 | const isEmptyText = (text) => text.trim().length === 0; 10 | 11 | let queryQueue = 0; 12 | let lastRequest = 0; 13 | 14 | const getNamuwiki = async (url, redirectionCount = 0, waited = false) => { 15 | if(!waited && lastRequest + config.request.interval > Date.now()){ 16 | await (() => new Promise((resolve) => setTimeout(resolve, config.request.interval * queryQueue)))(); 17 | return await getNamuwiki(url, redirectionCount, true); 18 | } 19 | 20 | lastRequest = Date.now(); 21 | 22 | if(redirectionCount > config.namuwiki.maxRedirection){ 23 | callback(new Error("Too many redirections!")); 24 | } 25 | 26 | let resp, body, err; 27 | 28 | if(url.includes('#')) url = url.split('#')[0]; 29 | 30 | queryQueue++; 31 | try { 32 | resp = await rp({ 33 | method: 'get', 34 | headers: { 35 | 'User-Agent': config.request.userAgent 36 | }, 37 | url: config.request.rawUrl + fixedURIencode(url), 38 | resolveWithFullResponse: true 39 | }); 40 | } catch(e) { 41 | err = e; 42 | err.status = resp ? resp.statusCode : 500; 43 | chalk.red; 44 | } 45 | queryQueue--; 46 | 47 | if(resp) body = resp.body; 48 | 49 | if(typeof body !== 'string' || body.includes('')) { 50 | err = new Error("Not Found"); 51 | err.status = 404; 52 | } 53 | 54 | if(err) { 55 | const loggerText = `${err.status} : ${url}`; 56 | if(err.status === 404) 57 | console.log(chalk.yellow(loggerText)); 58 | else 59 | console.error(chalk.red(loggerText)); 60 | throw err; 61 | } 62 | 63 | if(body.includes('#redirect')) { 64 | const redirectionTarget = body.match(/^\s*#redirect\s+(.*)(#s-.*)?\s*$/m); 65 | console.log(chalk.green(`302 : ${url}`)); 66 | 67 | if(redirectionTarget && redirectionTarget[1]) { 68 | try { 69 | return await getNamuwiki(redirectionTarget[1], redirectionCount + 1, true); 70 | } catch(e) { 71 | throw e; 72 | } 73 | } 74 | } 75 | 76 | console.log(chalk.cyan(`200 : ${url}`)); 77 | 78 | const split = body.split(/^\s*[=]+ .* [=]+\s*$/gm); 79 | let overview = ""; 80 | 81 | if(split.length <= 1) overview = split[0]; 82 | else { 83 | for(let i = 1; i < split.length; i++) { 84 | if(!isEmptyText(split[i])) { 85 | overview = split[i]; 86 | break; 87 | } 88 | } 89 | } 90 | 91 | const links = []; 92 | 93 | for(let key of Object.keys(config.remove)) { 94 | const removed = await remover[key].remove(config.remove[key], overview, url); 95 | if(typeof removed === 'string') { 96 | overview = removed; 97 | }else if(typeof removed === 'object') { 98 | if(removed.text) overview = removed.text; 99 | if(removed.links) links.push(...removed.links); 100 | } 101 | } 102 | 103 | overview = truncate(overview, config.namuwiki.overviewLength); 104 | overview = `${url}\n${overview}\n\n자세히 보기`; 105 | 106 | /*const $ = cheerio.load(overview, { 107 | xmlMode: true 108 | }); 109 | 110 | //Unwrap nested tags 111 | $.root().children().each((i, _el) => { 112 | const el = $(_el); 113 | if(!el) return; 114 | 115 | const children = el.children(); 116 | if(!children) return; 117 | 118 | children.each((i2, _el2) => { 119 | const el2 = $(_el2); 120 | if(!el2) return; 121 | 122 | el2.html(el2.text()); 123 | }); 124 | }); 125 | 126 | overview = $.html().replace('', '').replace('', '').replace(/<([^<> ]*[^<>]*)\/>/g, '<$1>');*/ 127 | 128 | const tagRegex = /(<([^<> ]+)(?:\s+\w+(?:="[^<>"=]+"))*>)(.+?)(<\/\2>)/g; 129 | 130 | const toText = (text) => { 131 | return text.replace(tagRegex, (match, startingTag, tagName, content, endTag) => { 132 | if(content.match(tagRegex)) { 133 | return toText(content); 134 | } 135 | 136 | return content; 137 | }); 138 | }; 139 | 140 | overview = overview.replace(tagRegex, (match, startingTag, tagName, content, endTag) => { 141 | if(content.match(tagRegex)) { 142 | return toText(content); 143 | } 144 | 145 | return startingTag + content + endTag; 146 | }); 147 | 148 | return { 149 | overview, 150 | links 151 | }; 152 | }; 153 | 154 | module.exports = getNamuwiki; 155 | -------------------------------------------------------------------------------- /src/Telegram.js: -------------------------------------------------------------------------------- 1 | const config = require('../config'); 2 | const rp = require('request-promise'); 3 | 4 | class Telegram { 5 | constructor(isDev) { 6 | this.apiUrl = 'https://api.telegram.org/bot' + config.token + '/'; 7 | this.logger = null; 8 | this.isDev = isDev; 9 | } 10 | 11 | async apiCall(target, data) { 12 | return rp({ 13 | method: 'POST', 14 | json: true, 15 | formData: data, 16 | url: `${this.apiUrl}${target}` 17 | }); 18 | } 19 | 20 | async ignoredApiCall(...args) { 21 | try { 22 | return await this.apiCall(...args); 23 | } catch(err) { 24 | if(this.isDev && this.logger) { 25 | this.logger.logError(err, {}); 26 | } 27 | } 28 | } 29 | } 30 | 31 | module.exports = Telegram; 32 | -------------------------------------------------------------------------------- /src/Utils.js: -------------------------------------------------------------------------------- 1 | const Utils = { 2 | fixedURIencode: (uri) => encodeURIComponent(uri).replace(/\(/g, '%28').replace(/\)/g, '%29'), 3 | match: (str, regex) => { 4 | const result = []; 5 | while ((match = regex.exec(str)) !== null) { 6 | result.push(match); 7 | } 8 | 9 | return result; 10 | }, 11 | padn: (str, n, letter = '0') => letter.repeat(Math.max(0, n - str.length)) + str 12 | }; 13 | 14 | module.exports = Utils; 15 | -------------------------------------------------------------------------------- /src/WikiImage.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HelloWorld017/NamuWikiBot/11b97e826dd8e0d1675c088f16a7c3da874f3345/src/WikiImage.js -------------------------------------------------------------------------------- /src/parser/ParagraphParser.js: -------------------------------------------------------------------------------- 1 | const {match} = require('../Utils'); 2 | 3 | const ParagraphParser = { 4 | parse(text) { 5 | const paragraphLiterals = match(text, /^(=+)(#?)[ ]+([^=\r\n]+)[ ]+\2\1$/gm); 6 | const paragraphs = {}; 7 | let lastIndex = 0; 8 | let lastLevel = -1; 9 | let hierachy = []; 10 | 11 | paragraphLiterals.forEach(matchResult => { 12 | const lastParagraph = text.slice(lastIndex, matchResult.index); 13 | const [level, isHidden, paragraphName] = matchResult; 14 | paragraphs[hierachy.join('')] = lastParagraph; 15 | 16 | if(level.length > lastLevel) { 17 | hierachy.push(1); 18 | } else if(level.length === lastLevel) { 19 | hierachy[hierachy.length - 1]++; 20 | } else { 21 | if(hierachy.length > 0) hierachy.pop(); 22 | } 23 | 24 | lastIndex = matchResult.index; 25 | 26 | if(lastLevel < 0) { 27 | lastLevel = level.length - 1; 28 | } 29 | }); 30 | 31 | paragraphs[hierachy.join('')] = text.slice(lastIndex); 32 | 33 | return paragraphs; 34 | } 35 | }; 36 | 37 | module.exports = ParagraphParser; 38 | -------------------------------------------------------------------------------- /src/parser/index.js: -------------------------------------------------------------------------------- 1 | const ParagraphParser = require('./ParagraphParser'); 2 | const {parse} = require('./processor'); 3 | 4 | module.exports = (text, context, targetParagraph = '1', debug = false) => { 5 | let content = text; 6 | 7 | if(targetParagraph !== '*') { 8 | const paragraphs = ParagraphParser.parse(text); 9 | if(!paragraphs[targetParagraph]) { 10 | targetParagraph = ''; 11 | } 12 | content = paragraphs[targetParagraph]; 13 | } 14 | 15 | return parse(content, context, debug); 16 | }; 17 | -------------------------------------------------------------------------------- /src/parser/prerenderer/BracePreRenderer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HelloWorld017/NamuWikiBot/11b97e826dd8e0d1675c088f16a7c3da874f3345/src/parser/prerenderer/BracePreRenderer.js -------------------------------------------------------------------------------- /src/parser/prerenderer/PreRenderer.js: -------------------------------------------------------------------------------- 1 | class PreRenderer { 2 | constructor(name) { 3 | this.name = name; 4 | } 5 | 6 | prepareRender(tokens) { 7 | 8 | } 9 | 10 | get tokens() { 11 | return []; 12 | } 13 | } 14 | 15 | module.exports = PreRenderer; 16 | -------------------------------------------------------------------------------- /src/parser/prerenderer/PreRendererMacro.js: -------------------------------------------------------------------------------- 1 | const PreRenderer = require('./PreRenderer'); 2 | 3 | const {padn} = require('../../Utils'); 4 | 5 | class PreRendererMacro extends PreRenderer { 6 | constructor() { 7 | super('Macro'); 8 | this.statistics = {}; 9 | } 10 | 11 | prepareRender(macros, tokens) { 12 | let str = ''; 13 | 14 | macros.forEach(v => { 15 | switch(v.name.toLowerCase()) { 16 | case 'datetime': 17 | case 'date': 18 | const date = new Date(); 19 | const yyyy = date.getFullYear(); 20 | const MM = padn(2, date.getMonth() + 1); 21 | const dd = padn(2, date.getDate()); 22 | 23 | const HH = padn(2, date.getHours()); 24 | const mm = padn(2, date.getMinutes()); 25 | const dd = padn(2, date.getSeconds()); 26 | 27 | str = `${yyyy}-${MM}-${dd} ${HH}:${mm}:${dd}`; 28 | break; 29 | 30 | case 'br': 31 | str = '\n'; 32 | break; 33 | 34 | case 'pagecount': 35 | const [namespace] = v.args; 36 | break; 37 | 38 | case 'include': 39 | break; 40 | 41 | case '목차': 42 | case 'tableofcontents': 43 | break; 44 | 45 | case '각주': 46 | case 'footnote': 47 | break; 48 | 49 | case 'age': 50 | break; 51 | 52 | case 'dday': 53 | break; 54 | 55 | case 'ruby': 56 | break; 57 | } 58 | }); 59 | } 60 | 61 | get tokens() { 62 | return ['Macro']; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/parser/processor/Processor.js: -------------------------------------------------------------------------------- 1 | class Processor { 2 | constructor(name) { 3 | this.name = name; 4 | } 5 | 6 | isStartOf(tokens, index) { 7 | return false; 8 | } 9 | 10 | process(tokens, start, processors, debug=false) { 11 | return { 12 | end: 0, 13 | node: [null] 14 | }; 15 | } 16 | 17 | get tokens() { 18 | return []; 19 | } 20 | 21 | get inside() { 22 | return []; 23 | } 24 | } 25 | 26 | module.exports = Processor; 27 | -------------------------------------------------------------------------------- /src/parser/processor/ProcessorBrace.js: -------------------------------------------------------------------------------- 1 | const Processor = require('./Processor'); 2 | class ProcessorBrace extends Processor { 3 | constructor() { 4 | super('Brace'); 5 | this.hasFirstLineArgument = [ 6 | '#!syntax', 7 | '#!wiki', 8 | '#!folding' 9 | ]; 10 | 11 | this.isNonParsing = [ 12 | '', 13 | '#!syntax', 14 | '#!html' 15 | ]; 16 | } 17 | 18 | isStartOf(tokens, index) { 19 | return tokens[index].name === 'BraceOpen'; 20 | } 21 | 22 | process(tokens, start, {parse, flatten}, {name}, debug=false) { 23 | const startToken = tokens[start]; 24 | let end = null; 25 | let level = 1; 26 | 27 | for(let i = start + 1; i < tokens.length; i++) { 28 | if(tokens[i].name === 'BraceOpen') level++; 29 | 30 | if(tokens[i].name === 'BraceClose') { 31 | level--; 32 | 33 | if(level === 0) { 34 | end = i; 35 | break; 36 | } 37 | } 38 | } 39 | 40 | if(end === null) { 41 | return { 42 | end: start + 1, 43 | node: [ 44 | { 45 | name: 'Text', 46 | content: startToken.content 47 | } 48 | ] 49 | }; 50 | } 51 | 52 | const innerTokens = tokens.slice(start + 1, end); 53 | const innerContent = flatten(innerTokens); 54 | let innerParsing = innerContent; 55 | let args = ''; 56 | let children = []; 57 | 58 | if(this.hasFirstLineArgument.includes(startToken.match[1])) { 59 | const [firstLine, leftLine] = innerContent.match(/([^]*)(\n[^]*)?/).slice(1); 60 | args = firstLine; 61 | innerParsing = leftLine; 62 | } 63 | 64 | if(this.isNonParsing.includes(startToken.match[1])) { 65 | children = [ 66 | { 67 | name: 'Text', 68 | content: innerParsing 69 | } 70 | ]; 71 | } else { 72 | children = parse(innerParsing); 73 | } 74 | 75 | return { 76 | end: end, 77 | node: [ 78 | { 79 | name: 'Brace', 80 | tag: startToken.match[1], 81 | args, 82 | children, 83 | content: startToken.content + innerContent + tokens[end].content 84 | } 85 | ] 86 | }; 87 | } 88 | 89 | get inside() { 90 | return ['Escape', 'Footnote', 'Macro', 'Inline', 'Link', 'Brace']; 91 | } 92 | 93 | get tokens() { 94 | return ['BraceOpen', 'BraceClose']; 95 | } 96 | } 97 | 98 | module.exports = ProcessorBrace; 99 | -------------------------------------------------------------------------------- /src/parser/processor/ProcessorInline.js: -------------------------------------------------------------------------------- 1 | const Processor = require('./Processor'); 2 | 3 | class ProcessorInline extends Processor { 4 | constructor() { 5 | super('Inline'); 6 | } 7 | 8 | isStartOf(tokens, index) { 9 | return tokens[index].name === 'Inline'; 10 | } 11 | 12 | process(tokens, start, {parse, flatten}, debug=false) { 13 | const startToken = tokens[start]; 14 | let end = null; 15 | 16 | for(let i = start + 1; i < tokens.length; i++) { 17 | if(tokens[i].name === 'Inline' && tokens[i].match[1] === startToken.match[1]) { 18 | end = i; 19 | break; 20 | } 21 | } 22 | 23 | if(end === null) { 24 | return { 25 | end: start + 1, 26 | node: [ 27 | { 28 | name: 'Text', 29 | content: startToken.content 30 | } 31 | ] 32 | }; 33 | } 34 | 35 | const innerTokens = tokens.slice(start + 1, end); 36 | 37 | return { 38 | end: end, 39 | node: [ 40 | { 41 | name: 'Inline', 42 | tag: startToken.match[1], 43 | children: parse(innerTokens), 44 | content: startToken.content + flatten(innerTokens) + tokens[end].content 45 | } 46 | ] 47 | }; 48 | } 49 | 50 | get inside() { 51 | return ['Escape', 'Footnote', 'Macro', 'Inline', 'Link', 'Brace']; 52 | } 53 | 54 | get tokens() { 55 | return ['Inline']; 56 | } 57 | } 58 | 59 | module.exports = ProcessorInline; 60 | -------------------------------------------------------------------------------- /src/parser/processor/ProcessorLink.js: -------------------------------------------------------------------------------- 1 | const Processor = require('./Processor'); 2 | class ProcessorLink extends Processor { 3 | constructor() { 4 | super('Link'); 5 | } 6 | 7 | isStartOf(tokens, index) { 8 | return tokens[index].name === 'LinkOpen'; 9 | } 10 | 11 | process(tokens, start, {parse, flatten}, {name}, debug=false) { 12 | const startToken = tokens[start]; 13 | let end = null; 14 | let level = 1; 15 | 16 | for(let i = start + 1; i < tokens.length; i++) { 17 | if(tokens[i].name === 'LinkOpen') { 18 | level++; 19 | } 20 | 21 | if(tokens[i].name === 'LinkClose') { 22 | level--; 23 | 24 | if(level === 0) { 25 | end = i; 26 | break; 27 | } 28 | } 29 | } 30 | 31 | if(end === null) { 32 | return { 33 | end: start + 1, 34 | node: [ 35 | { 36 | name: 'Text', 37 | content: startToken.content 38 | } 39 | ] 40 | }; 41 | } 42 | 43 | const innerTokens = tokens.slice(start + 1, end); 44 | const innerContent = flatten(innerTokens); 45 | const linkDescriptor = {}; 46 | 47 | let splitPoint = -1; 48 | let showText = ''; 49 | let link = ''; 50 | 51 | for(let i = 0; i < innerContent.length; i++) { 52 | if(innerContent[i] === '|' && innerContent[i - 1] !== '\\') { 53 | splitPoint = i; 54 | break; 55 | } 56 | } 57 | 58 | if(splitPoint !== -1) { 59 | link = innerContent.slice(0, splitPoint); 60 | showText = innerContent.slice(splitPoint + 1); 61 | } else { 62 | link = innerContent; 63 | showText = innerContent; 64 | } 65 | 66 | if(/^https?:\/\/|mailto:/.test(link)) { 67 | linkDescriptor.external = link; 68 | } else { 69 | if(link.startsWith('../')) { 70 | const rawLink = link.replace('../', ''); 71 | const parentMatch = name.match(/^(.*)\//); 72 | if(parentMatch) link = parentMatch[1] + rawLink; 73 | else link = name + rawLink; 74 | } else if(link.startsWith('/')) { 75 | link = name + link; 76 | } 77 | 78 | const anchorMatch = link.match(/^(.*)#(.*)/); 79 | if(anchorMatch) { 80 | linkDescriptor.anchor = anchorMatch[2]; 81 | link = anchorMatch[1]; 82 | } 83 | 84 | linkDescriptor.internal = link; 85 | } 86 | 87 | return { 88 | end: end, 89 | node: [ 90 | { 91 | name: 'Link', 92 | link: linkDescriptor, 93 | children: parse(showText), 94 | content: startToken.content + innerContent + tokens[end].content 95 | } 96 | ] 97 | }; 98 | } 99 | 100 | get inside() { 101 | return ['Escape', 'Footnote', 'Macro', 'Inline', 'Link', 'Brace']; 102 | } 103 | 104 | get tokens() { 105 | return ['LinkOpen', 'LinkClose']; 106 | } 107 | } 108 | 109 | module.exports = ProcessorLink; 110 | -------------------------------------------------------------------------------- /src/parser/processor/ProcessorList.js: -------------------------------------------------------------------------------- 1 | const Processor = require('./Processor'); 2 | 3 | const abcdize = num => (num - 1).toString(26).split('').map((v, i, arr) => { 4 | let index = parseInt(v, 26) - 1; 5 | if(i === arr.length - 1) index++; 6 | 7 | return 'abcdefghijklmnopqrstuvwxyz'[index]; 8 | }).join(''); 9 | 10 | class ProcessorList extends Processor { 11 | constructor() { 12 | super('List'); 13 | } 14 | 15 | isStartOf(tokens, index) { 16 | return tokens[index].name === 'List'; 17 | } 18 | 19 | process(tokens, start, {parse, flatten}, {name}, debug=false) { 20 | const startToken = tokens[start]; 21 | let end = null; 22 | 23 | const whitespace = /^\s*$/; 24 | const newline = /\n/g; 25 | 26 | for(let i = start; i < tokens.length; i++) { 27 | if(tokens[i].name === 'List') { 28 | let isEnd = true; 29 | for(let delta = 1; delta <= 2; delta++) { 30 | if(i + delta >= tokens.length) { 31 | break; 32 | } 33 | 34 | if(tokens[i + delta].name === 'List') { 35 | isEnd = false; 36 | break; 37 | } 38 | 39 | if(!whitespace.test(tokens[i + delta].content)) { 40 | break; 41 | } 42 | 43 | const lines = tokens[i + delta].content.match(newline); 44 | if(lines && lines.length > 2) { 45 | break; 46 | } 47 | } 48 | 49 | if(isEnd) { 50 | end = i; 51 | break; 52 | } 53 | } 54 | } 55 | 56 | if(end === null) { 57 | return { 58 | end: start + 1, 59 | node: [ 60 | { 61 | name: 'Text', 62 | content: parse(startToken.content) 63 | } 64 | ] 65 | }; 66 | } 67 | 68 | let level = 0; 69 | 70 | const result = []; 71 | const context = {}; 72 | const listTokens = tokens.slice(start, end + 1); 73 | listTokens.forEach(list => { 74 | if(list.name !== 'List') return; 75 | 76 | const [rawContent, rawIndent, rawChar, rawStart, rawChildren] = list.match; 77 | let levelDelta = 0; 78 | 79 | if(rawIndent.length !== level) { 80 | levelDelta = Math.sign(rawIndent.length - level); 81 | level += levelDelta; 82 | 83 | if(levelDelta >= 1) { 84 | context[level] = { 85 | index: 0, 86 | char: rawChar 87 | }; 88 | } 89 | } 90 | 91 | if(context[level].char !== rawChar) { 92 | context[level].index = 0; 93 | context[level].char = rawChar; 94 | } 95 | 96 | const children = parse(rawChildren); 97 | 98 | if(rawChar === '*') { 99 | result.push({ 100 | name: 'ListItem', 101 | listChar: '*', 102 | unordered: true, 103 | level, 104 | children, 105 | content: rawContent 106 | }); 107 | 108 | return; 109 | } 110 | 111 | context[level].index++; 112 | 113 | if(rawStart) { 114 | const newIndex = parseInt(rawStart.slice(1)); 115 | if(isFinite(newIndex)) { 116 | context[level].index = newIndex; 117 | } 118 | } 119 | 120 | let listChar = ''; 121 | switch(rawChar) { 122 | case '1.': 123 | listChar = '' + context[level].index; 124 | break; 125 | 126 | case 'I.': 127 | listChar = romanize(context[level].index).toUpperCase(); 128 | break; 129 | 130 | case 'i.': 131 | listChar = romanize(context[level].index).toLowerCase(); 132 | break; 133 | 134 | case 'A.': 135 | listChar = abcdize(context[level].index).toUpperCase(); 136 | break; 137 | 138 | case 'a.': 139 | listChar = abcdize(context[level].index).toLowerCase(); 140 | break; 141 | } 142 | 143 | listChar += '.'; 144 | 145 | result.push({ 146 | name: 'ListItem', 147 | listChar, 148 | level, 149 | children, 150 | content: rawContent 151 | }); 152 | }); 153 | 154 | return { 155 | end: end, 156 | node: [ 157 | { 158 | name: 'List', 159 | children: result, 160 | content: flatten(listTokens) 161 | } 162 | ] 163 | }; 164 | } 165 | 166 | get inside() { 167 | return ['Escape', 'Footnote', 'Macro', 'Inline', 'Link', 'Brace']; 168 | } 169 | 170 | get tokens() { 171 | return ['List']; 172 | } 173 | } 174 | 175 | module.exports = ProcessorList; 176 | -------------------------------------------------------------------------------- /src/parser/processor/ProcessorMacro.js: -------------------------------------------------------------------------------- 1 | const Processor = require('./Processor'); 2 | class ProcessorMacro extends Processor { 3 | constructor() { 4 | super('Macro'); 5 | } 6 | 7 | isStartOf(tokens, index) { 8 | return tokens[index].name === 'Macro'; 9 | } 10 | 11 | process(tokens, start, {parse, flatten}, {name}, debug=false) { 12 | const startToken = tokens[start]; 13 | const argsRaw = startToken.match[2]; 14 | const argsSplit = argsRaw.split(/(? { 19 | if(isKwArgs === null) return null; 20 | 21 | const kwMatch = curr.match(/([^=]*)=(.*)/); 22 | if(isKwArgs) { 23 | if(!kwMatch) { 24 | args = [argsRaw]; 25 | kwargs = {}; 26 | return null; 27 | } 28 | } else { 29 | if(index > 1 && kwMatch) isKwArgs = true; 30 | } 31 | 32 | if(isKwArgs) { 33 | kwargs[kwMatch[1]] = kwMatch[2]; 34 | } else { 35 | args.push(curr); 36 | } 37 | }, false); 38 | 39 | return { 40 | end: start, 41 | node: [ 42 | { 43 | name: 'Macro', 44 | macro: { 45 | name: startToken.match[1], 46 | args, 47 | kwargs 48 | }, 49 | content: startToken.content 50 | } 51 | ] 52 | }; 53 | } 54 | 55 | get inside() { 56 | return []; 57 | } 58 | 59 | get tokens() { 60 | return ['Macro']; 61 | } 62 | } 63 | 64 | module.exports = ProcessorMacro; 65 | -------------------------------------------------------------------------------- /src/parser/processor/ProcessorQuote.js: -------------------------------------------------------------------------------- 1 | const Processor = require('./Processor'); 2 | 3 | class ProcessorQuote extends Processor { 4 | constructor() { 5 | super('Quote'); 6 | } 7 | 8 | isStartOf(tokens, index) { 9 | return tokens[index].name === 'Quote'; 10 | } 11 | 12 | process(tokens, start, {parse, flatten}, {name}, debug=false) { 13 | const startToken = tokens[start]; 14 | const whitespace = /^\s*$/; 15 | const newline = /\n/g; 16 | 17 | let end = null; 18 | 19 | for(let i = start; i < tokens.length; i++) { 20 | if(tokens[i].name === 'Quote') { 21 | let isEnd = true; 22 | for(let delta = 1; delta <= 2; delta++) { 23 | if(i + delta >= tokens.length) { 24 | break; 25 | } 26 | 27 | if(tokens[i + delta].name === 'Quote') { 28 | isEnd = false; 29 | break; 30 | } 31 | 32 | if(!whitespace.test(tokens[i + delta].content)) { 33 | break; 34 | } 35 | 36 | const lines = tokens[i + delta].content.match(newline); 37 | if(lines && lines.length > 2) { 38 | break; 39 | } 40 | } 41 | 42 | if(isEnd) { 43 | end = i; 44 | break; 45 | } 46 | } 47 | } 48 | 49 | if(end === null) { 50 | return { 51 | end: start + 1, 52 | node: [ 53 | { 54 | name: 'Text', 55 | content: parse(startToken.content) 56 | } 57 | ] 58 | }; 59 | } 60 | 61 | const rootNode = { 62 | name: 'Quote', 63 | children: [], 64 | content: '' 65 | }; 66 | let leafNode = rootNode; 67 | let previousLevel = 1; 68 | 69 | const quoteTokens = tokens.slice(start, end + 1); 70 | quoteTokens.forEach(quote => { 71 | if(quote.name === 'Text') { 72 | leafNode.children[leafNode.children.length - 1].content += quote.content; 73 | leafNode.content += quote.content; 74 | return; 75 | } 76 | 77 | let [level, text] = quote.match.slice(1); 78 | level = level.length; 79 | 80 | if(level > previousLevel) { 81 | previousLevel = level; 82 | 83 | const newNode = { 84 | name: 'Quote', 85 | children: [ 86 | { 87 | name: 'Text', 88 | content: text 89 | } 90 | ], 91 | level, 92 | parent: leafNode, 93 | content: quote.match[0] 94 | }; 95 | leafNode.children.push(newNode); 96 | leafNode = newNode; 97 | return; 98 | } 99 | 100 | if(level < previousLevel) { 101 | previousLevel = level; 102 | leafNode.children = parse(leafNode.children); 103 | leafNode.parent.content += leafNode.content; 104 | 105 | const parent = leafNode.parent; 106 | delete leafNode.parent; 107 | 108 | leafNode = parent; 109 | } 110 | 111 | const sibiling = leafNode.children[leafNode.children.length - 1]; 112 | if(sibiling && sibiling.name === 'Text') { 113 | sibiling.content += text; 114 | } else { 115 | leafNode.children.push({ 116 | name: 'Text', 117 | content: text 118 | }); 119 | } 120 | leafNode.content += quote.match[0]; 121 | }); 122 | 123 | if(leafNode.parent) { 124 | leafNode.children = parse(leafNode.children); 125 | leafNode.parent.content += leafNode.content; 126 | 127 | delete leafNode.parent; 128 | } 129 | 130 | return { 131 | end: end, 132 | node: [ 133 | rootNode 134 | ] 135 | }; 136 | } 137 | 138 | get inside() { 139 | return ['Escape', 'Footnote', 'Macro', 'Inline', 'Link', 'Brace']; 140 | } 141 | 142 | get tokens() { 143 | return ['Quote']; 144 | } 145 | } 146 | 147 | module.exports = ProcessorQuote; 148 | -------------------------------------------------------------------------------- /src/parser/processor/ProcessorTable.js: -------------------------------------------------------------------------------- 1 | const Processor = require('./Processor'); 2 | 3 | class ProcessorTable extends Processor { 4 | constructor() { 5 | super('Table'); 6 | } 7 | 8 | isStartOf(tokens, index) { 9 | return tokens[index].name === 'TableRowStart'; 10 | } 11 | 12 | process(tokens, start, {parse, flatten}, debug=false) { 13 | const startToken = tokens[start]; 14 | let end = null; 15 | 16 | if(startToken.match[1] && startToken.match[1].length > 0) 17 | table.name = startToken.match[1]; 18 | 19 | const table = { 20 | styles: {}, 21 | cells: {} 22 | }; 23 | const whitespace = /^\s*$/; 24 | const newline = /\n/g; 25 | 26 | let x = 0, y = 0; 27 | const createCell = () => { 28 | const cellId = [`${x}:${y}`]; 29 | if(!table.cells[cellId]) { 30 | table.cells[cellId] = { 31 | children: [], 32 | align: {}, 33 | styles: {} 34 | }; 35 | } 36 | 37 | return cellId; 38 | }; 39 | 40 | const mergeCell = (mergingLength, direction = 0) => { 41 | const cellId = `${x}:${y}`; 42 | for(let merging = 1; merging < mergingLength; merging++) { 43 | const cellIdRaw = [x, y]; 44 | cellIdRaw[direction] += merging; 45 | table.cells[cellIdRaw.join(':')] = { 46 | children: [], 47 | reference: cellId, 48 | isMergedCell: true 49 | }; 50 | } 51 | }; 52 | 53 | for(let i = start + 1; i < tokens.length; i++) { 54 | if(tokens[i].name === 'TableRowEnd') { 55 | let isEnd = true; 56 | for(let delta = 1; delta <= 2; delta++) { 57 | if(i + delta >= tokens.length) { 58 | break; 59 | } 60 | 61 | if(tokens[i + delta].name === 'TableRowStart') { 62 | if(!tokens[i + delta].match[1] || tokens[i + delta].match[1] === '') { 63 | isEnd = false; 64 | } 65 | break; 66 | } 67 | 68 | if(!whitespace.test(tokens[i + delta].content)) { 69 | break; 70 | } 71 | 72 | const lines = tokens[i + delta].content.match(newline); 73 | if(lines && lines.length > 1) { 74 | break; 75 | } 76 | } 77 | 78 | if(isEnd) { 79 | end = i; 80 | break; 81 | } 82 | } 83 | } 84 | 85 | if(end === null) { 86 | return { 87 | end: start + 1, 88 | node: [ 89 | { 90 | name: 'Text', 91 | content: startToken.content 92 | } 93 | ] 94 | }; 95 | } 96 | 97 | const tableTokens = parse(flatten(tokens.slice(start, end + 1))); 98 | tableTokens.forEach((token, i) => { 99 | const args = token.match ? token.match.slice(1) : []; 100 | 101 | switch(token.name) { 102 | case 'TableRowStart': { 103 | const lastCell = table.cells[`${x}:${y}`]; 104 | const lastElem = lastCell.children[lastCell.children.length - 1]; 105 | if(lastElem.name === 'Text') { 106 | lastElem.content = lastElem.content.replace(/\s*$/, ''); 107 | if(lastElem.content === '') { 108 | lastCell.children.pop(); 109 | } 110 | } 111 | 112 | x = 0; 113 | y++; 114 | 115 | while(table.cells[`${x}:${y}`]) { 116 | x++; 117 | } 118 | createCell(); 119 | 120 | const [_, mergingLength] = args; 121 | mergeCell(mergingLength.length / 2 + 1); 122 | 123 | break; 124 | } 125 | 126 | case 'TableDivider': { 127 | while(table.cells[`${x}:${y}`]) { 128 | x++; 129 | } 130 | createCell(); 131 | 132 | const [mergingLength] = args; 133 | mergeCell(mergingLength.length / 2); 134 | 135 | break; 136 | } 137 | 138 | case 'TableRowEnd': { 139 | const [mergingLength] = args; 140 | mergeCell(mergingLength.length / 2); 141 | 142 | break; 143 | } 144 | 145 | case 'TableColorDecoration': { 146 | const [color] = args; 147 | const cellId = createCell(); 148 | table.cells[cellId].styles.bgcolor = color; 149 | break; 150 | } 151 | 152 | case 'TableDecoration': { 153 | const [isTable, key, value] = args; 154 | if(isTable) { 155 | table.styles[key] = value; 156 | break; 157 | } 158 | 159 | const cellId = createCell(); 160 | table.cells[cellId].styles[key] = value; 161 | break; 162 | } 163 | 164 | case 'TableVAlignMerge': { 165 | const [alignValue, mergingLength] = args; 166 | const cellId = createCell(); 167 | 168 | if(alignValue === '^') 169 | table.cells[cellId].align.top = true; 170 | 171 | else if(alignValue === 'v') 172 | table.cells[cellId].align.bottom = true; 173 | 174 | else { 175 | table.cells[cellId].align.top = true; 176 | table.cells[cellId].align.bottom = true; 177 | } 178 | 179 | mergeCell(parseInt(mergingLength), 1); 180 | break; 181 | } 182 | 183 | case 'TableHAlign': { 184 | const [alignValue] = args; 185 | const cellId = createCell(); 186 | 187 | if(alignValue === '(') { 188 | table.cells[cellId].align.forceLeft = true; 189 | table.cells[cellId].align.forceRight = false; 190 | } else if (alignValue === ')') { 191 | table.cells[cellId].align.forceLeft = false; 192 | table.cells[cellId].align.forceRight = true; 193 | } else { 194 | table.cells[cellId].align.forceLeft = true; 195 | table.cells[cellId].align.forceRight = true; 196 | } 197 | break; 198 | } 199 | 200 | case 'TableHMerge': { 201 | const [mergingLength] = args; 202 | 203 | createCell(); 204 | mergeCell(parseInt(mergingLength)); 205 | break; 206 | } 207 | 208 | default: { 209 | const cellId = createCell(); 210 | table.cells[cellId].children.push(token); 211 | break; 212 | } 213 | } 214 | }); 215 | 216 | Object.keys(table.cells).forEach(k => { 217 | const children = table.cells[k].children.reduce((prev, curr) => { 218 | if(prev[prev.length - 1] && prev[prev.length - 1].name === 'Text' && curr.name === 'Text') { 219 | prev[prev.length - 1].content += curr.content; 220 | } else { 221 | prev.push(curr); 222 | } 223 | return prev; 224 | }, []); 225 | 226 | if(children.length === 0) return; 227 | 228 | table.cells[k].align.left = children[0].content.startsWith(' '); 229 | table.cells[k].align.right = children[children.length - 1].content.endsWith(' '); 230 | 231 | children[0].content = children[0].content 232 | .replace(/^\s*/, '') 233 | .replace(/\s*$/, ''); 234 | 235 | if(table.cells[k].align.forceLeft) { 236 | table.cells[k].align.left = table.cells[k].align.forceLeft; 237 | delete table.cells[k].align.forceLeft; 238 | } 239 | 240 | if(table.cells[k].align.forceRight) { 241 | table.cells[k].align.right = table.cells[k].align.forceRight; 242 | delete table.cells[k].align.forceRight; 243 | } 244 | 245 | table.cells[k].children = children; 246 | }); 247 | 248 | return { 249 | end: end, 250 | node: [ 251 | { 252 | name: 'Table', 253 | children: [], 254 | table, 255 | content: tableTokens.map(v => v.content).join('') 256 | } 257 | ] 258 | }; 259 | } 260 | 261 | get inside() { 262 | return [ 263 | 'Escape', 'Footnote', 'Macro', 'Inline', 'Link', 'Brace', 264 | 265 | 'TableRowStart', 'TableRowEnd', 'TableHAlign', 'TableHMerge', 266 | 'TableVAlignMerge', 'TableDecoration', 'TableDivider', 'TableCaption', 267 | 'TableColorDecoration' 268 | ]; 269 | } 270 | 271 | get tokens() { 272 | return ['TableRowStart', 'TableRowEnd']; 273 | } 274 | } 275 | 276 | module.exports = ProcessorTable; 277 | -------------------------------------------------------------------------------- /src/parser/processor/index.js: -------------------------------------------------------------------------------- 1 | const tokenize = require('../tokenizer'); 2 | 3 | const ProcessorBrace = require('./ProcessorBrace'); 4 | const ProcessorInline = require('./ProcessorInline'); 5 | const ProcessorLink = require('./ProcessorLink'); 6 | const ProcessorList = require('./ProcessorList'); 7 | const ProcessorMacro = require('./ProcessorMacro'); 8 | const ProcessorQuote = require('./ProcessorQuote'); 9 | const ProcessorTable = require('./ProcessorTable'); 10 | 11 | const processors = [ 12 | new ProcessorBrace(), 13 | new ProcessorInline(), 14 | new ProcessorLink(), 15 | new ProcessorMacro(), 16 | new ProcessorList(), 17 | new ProcessorQuote(), 18 | new ProcessorTable(), 19 | ]; 20 | 21 | const flatten = tokens => tokens.map(v => v.content).join(''); 22 | const splitProcessorTokenizer = processorOrTokenizerNames => { 23 | const processorNames = []; 24 | const tokenizerNames = processorOrTokenizerNames 25 | .map(name => { 26 | const foundProcessor = processors.find(v => v.name === name); 27 | if(foundProcessor !== undefined) { 28 | processorNames.push(name); 29 | return foundProcessor.tokens; 30 | } 31 | return name; 32 | }) 33 | .reduce((prev, curr) => prev.concat(curr), []); 34 | 35 | return { 36 | processorNames, 37 | tokenizerNames 38 | }; 39 | }; 40 | const parseInternal = (processorOrTokenizerNames, context, debug = false) => contentOrTokens => { 41 | let content = contentOrTokens; 42 | if(typeof contentOrTokens === 'string') { 43 | content = [ 44 | { 45 | name: 'Text', 46 | content: contentOrTokens 47 | } 48 | ]; 49 | } 50 | 51 | content = content.reduce((array, v) => { 52 | const isLastString = typeof array[array.length - 1] === 'string'; 53 | if(v.name === 'Text') { 54 | if(!isLastString) array.push(''); 55 | array[array.length - 1] += v.content; 56 | 57 | return array; 58 | } 59 | 60 | array.push(v); 61 | return array; 62 | }, []); 63 | 64 | const {processorNames, tokenizerNames} = splitProcessorTokenizer(processorOrTokenizerNames); 65 | 66 | const tokenizeUsing = tokenize(tokenizerNames); 67 | const tokenized = content.reduce((array, v) => { 68 | if(typeof v === 'string') { 69 | array.push(...tokenizeUsing(v)); 70 | } else { 71 | array.push(v); 72 | } 73 | 74 | return array; 75 | }, []); 76 | 77 | return process(processorNames, context, debug)(tokenized); 78 | }; 79 | 80 | const process = (processorNames, context, debug=false) => tokens => { 81 | const usingProcessors = processors.filter(v => processorNames.includes(v.name)); 82 | usingProcessors.forEach(processor => { 83 | const {tokenizerNames} = splitProcessorTokenizer(processor.inside); 84 | const tokenizeUsing = tokenize(tokenizerNames); 85 | 86 | const tools = { 87 | parse: parseInternal(processor.inside, context, debug), 88 | tokenize: tokenizeUsing, 89 | flatten 90 | }; 91 | 92 | let tokenLength = tokens.length; 93 | for(let i = 0; i < tokenLength; i++) { 94 | if(!processor.isStartOf(tokens, i)) continue; 95 | 96 | 97 | const {end, node} = processor.process(tokens, i, tools, context, debug); 98 | tokens.splice(i, end - i + 1, ...node); 99 | tokenLength = tokens.length; 100 | } 101 | }); 102 | 103 | return tokens; 104 | }; 105 | 106 | module.exports = process; 107 | module.exports.parse = (text, ...args) => parseInternal([ 108 | 'Escape', 109 | 'Footnote', 110 | ...tokenize.tokenizers.map(v => v.name), 111 | ...processors.map(v => v.name) 112 | ].reduce((prev, v) => { 113 | if(!prev.includes(v)) { 114 | prev.push(v); 115 | } 116 | 117 | return prev; 118 | }, []), ...args)(text); 119 | -------------------------------------------------------------------------------- /src/parser/tokenizer/Tokenizer.js: -------------------------------------------------------------------------------- 1 | class Tokenizer { 2 | constructor(name) { 3 | this.name = name; 4 | } 5 | 6 | tokenize(string) { 7 | return { 8 | token: null, 9 | length: 0 10 | }; 11 | } 12 | } 13 | 14 | module.exports = Tokenizer; 15 | -------------------------------------------------------------------------------- /src/parser/tokenizer/TokenizerRegex.js: -------------------------------------------------------------------------------- 1 | const Tokenizer = require("./Tokenizer"); 2 | 3 | class TokenizerRegex extends Tokenizer { 4 | constructor(name, regex, negativeLookBehind = '\\') { 5 | super(name); 6 | 7 | this.originalRegex = regex; 8 | this.negativeLookBehind = negativeLookBehind; 9 | 10 | const regexStr = regex.source; 11 | const concatedRegex = negativeLookBehind === null 12 | ? regexStr 13 | : '(?+)\s*(.*)$/), 20 | new TokenizerRegexLine('Horizontal', /^-{4,9}$/), 21 | new TokenizerRegexLine('Annotation', /^##(.*)$/), 22 | new TokenizerRegexLine('List', /^([^\S\r\n]+)([1IiAa]\.|\*)((?:#[0-9+])?)([^]*?)$/) 23 | ]; 24 | 25 | const tokenizerInternal = [ 26 | new TokenizerRegex('TableDecoration', /<((?:table )?)([a-z]+?)=([^>]*?)>/), 27 | new TokenizerRegex('TableDivider', /(?/), 29 | new TokenizerRegex('TableHMerge', /<-([0-9]+)>/), 30 | new TokenizerRegex('TableHAlign', /<([\(\):])>/), 31 | new TokenizerRegex('TableColorDecoration', /<((?:[a-z]+)|(?:#[0-9a-f]{3,6}))>/) 32 | ]; 33 | 34 | const tokenize = tokenNames => text => { 35 | const usingTokenizers = [ 36 | ...tokenizers.filter(v => tokenNames.includes(v.name)), 37 | ...tokenizerInternal.filter(v => tokenNames.includes(v.name)) 38 | ]; 39 | const tokens = []; 40 | 41 | let tokenizing = text; 42 | let index = 0; 43 | while(tokenizing.length > 0) { 44 | let minimum = {token: null, length: 0, at: Infinity}; 45 | 46 | usingTokenizers.forEach(tokenizer => { 47 | const result = tokenizer.tokenize(tokenizing, text, index); 48 | if(result.token && result.at < minimum.at) { 49 | minimum = result; 50 | } 51 | }); 52 | 53 | if(!isFinite(minimum.at)) { 54 | tokens.push({ 55 | name: 'Text', 56 | content: tokenizing 57 | }); 58 | break; 59 | } 60 | 61 | const textContent = tokenizing.slice(0, minimum.at); 62 | if(textContent.length > 0) { 63 | tokens.push({ 64 | index, 65 | name: 'Text', 66 | content: textContent 67 | }); 68 | } 69 | 70 | minimum.token.index = index + textContent.length; 71 | 72 | tokens.push(minimum.token); 73 | tokenizing = tokenizing.slice(minimum.at + minimum.length); 74 | index += minimum.at + minimum.length; 75 | } 76 | 77 | return tokens; 78 | }; 79 | 80 | module.exports = tokenize; 81 | module.exports.tokenizers = tokenizers; 82 | -------------------------------------------------------------------------------- /src/remover.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | const LT = `\u{E2E2}NW_BOT_LT_MARK\u{EE22}`; 4 | const GT = `\u{E2E2}NW_BOT_RT_MARK\u{EE22}`; 5 | const AMP = `\u{E2E2}NW_BOT_AMP_MARK\u{EE22}`; 6 | const QUOT = `\u{E2E2}NW_BOT_QUOT_MARK\u{EE22}`; 7 | 8 | const replaceMap = (text, map) => { 9 | Object.keys(map).forEach((k) => { 10 | text = text.split(k).join(map[k]); 11 | }); 12 | 13 | return text; 14 | }; 15 | 16 | const escapeHTML = (text) => replaceMap(text, { 17 | '&': '&', 18 | '<': '<', 19 | '>': '>', 20 | '"': '"' 21 | }); 22 | 23 | const escapeNW = (text) => replaceMap(text, { 24 | '&': AMP, 25 | '<': LT, 26 | '>': GT, 27 | '"': QUOT 28 | }); 29 | 30 | const unescapeNWMap = {}; 31 | unescapeNWMap[AMP] = '&'; 32 | unescapeNWMap[LT] = '<'; 33 | unescapeNWMap[GT] = '>'; 34 | unescapeNWMap[QUOT] = '"'; 35 | 36 | const unescapeNW = (text) => replaceMap(text, unescapeNWMap); 37 | 38 | const {fixedURIencode} = require('./Utils'); 39 | 40 | class Remover{ 41 | constructor(){ 42 | 43 | } 44 | 45 | async remove(){ 46 | throw new Error("Undefined method called!"); 47 | } 48 | } 49 | 50 | class MacroRemover extends Remover { 51 | constructor(macroName) { 52 | super(); 53 | 54 | this.regex = new RegExp("\\[" + macroName + "(?:\\s*\\((.*?)\\)\\s*)?\\]", 'ig'); 55 | } 56 | 57 | async remove(type, text, ctx) { 58 | return text.replace(this.regex, (match, args) => { 59 | console.log(this.replace); 60 | return this.replace(type, match, args, ctx); 61 | }); 62 | } 63 | 64 | replace(type, match) { 65 | return match; 66 | } 67 | } 68 | 69 | class AgeRemover extends MacroRemover{ 70 | constructor() { 71 | super('age'); 72 | } 73 | 74 | replace(type, match, args) { 75 | switch(type) { 76 | case 'whole': return ''; 77 | case 'replace': 78 | const regex = /^\s*(\d{4,})-(\d{1,2})-(\d{1,2})\s*$/; 79 | if(!regex.test(args)) return; 80 | 81 | const [, year, month, date] = args.match(regex); 82 | 83 | let age; 84 | 85 | const today = new Date(); 86 | const todayMonth = d.getMonth() + 1; 87 | const todayDate = d.getDate(); 88 | 89 | age = d.getFullYear() - year; 90 | 91 | if (todayMonth < month || (todayMonth === month && todayDate < date)) { 92 | age--; 93 | } 94 | 95 | return age; 96 | } 97 | 98 | return match; 99 | } 100 | } 101 | 102 | //attachment:주소 형식의 이미지 제거 103 | class AttachmentRemover extends Remover{ 104 | constructor(){ 105 | super(); 106 | this.regex = /^attachment[ ]*:[ ]*(.*\..*)$/mg; 107 | } 108 | 109 | async remove(type, text){ 110 | switch(type){ 111 | case 'replace': 112 | text = text.replace(this.regex, (match, p1) => { 113 | return escapeNW(`이미지`); 114 | }); 115 | break; 116 | 117 | case 'tag': 118 | text = text.replace(this.regex, (match, p1) => fixedURIencode(p1)); 119 | break; 120 | 121 | case 'whole': 122 | text = text.replace(this.regex, ''); 123 | break; 124 | } 125 | 126 | return text; 127 | } 128 | } 129 | 130 | class BraceRemover extends Remover{ 131 | constructor(tag){ 132 | super(); 133 | this.tag = tag; 134 | } 135 | 136 | async remove(type, text){ 137 | switch(type){ 138 | case 'tag': 139 | return text.replace(new RegExp("{{{" + this.tag, 'g'), '').replace(/}}}/g, ''); 140 | 141 | case 'whole': 142 | return text.replace(new RegExp("{{{" + this.tag + "[^]*?}}}", 'g'), ''); 143 | } 144 | 145 | return text; 146 | } 147 | } 148 | 149 | class DateRemover extends MacroRemover { 150 | constructor(macroName) { 151 | super(macroName); 152 | } 153 | 154 | replace(type, match) { 155 | switch(type) { 156 | case 'replace': 157 | const date = new Date(); 158 | const pad2 = (str) => { 159 | while(str.toString().length < 2) str = `0${str}`; 160 | 161 | return str; 162 | }; 163 | 164 | return `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}` + 165 | ` ${pad2(date.getHours())}:${pad2(date.getMinutes())}:${pad2(date.getSeconds())}`; 166 | 167 | case 'whole': return ''; 168 | } 169 | 170 | return match; 171 | } 172 | } 173 | 174 | class FootnoteRemover extends Remover{ 175 | constructor(){ 176 | super(); 177 | this.regex = /\[\*[^ ]*[ ]*(.+?)[^\]][\]]{1}(?!\]+)/g; 178 | } 179 | 180 | async remove(type, text){ 181 | switch(type){ 182 | case 'tag': 183 | return escapeNW(text.replace(this.regex, (match, p1) => escapeHTML(p1))); 184 | 185 | case 'whole': 186 | return text.replace(this.regex, ''); 187 | } 188 | 189 | return text; 190 | } 191 | } 192 | 193 | class HyperlinkRemover extends Remover{ 194 | constructor(){ 195 | super(); 196 | this.regex = /\[\[([^\[\]\|]*?)(?:\|([^\[\]]*?))?\]\]/g; 197 | } 198 | 199 | async remove(param, text, ctx) { 200 | const links = []; 201 | const split = param.split("|"); 202 | const type = split[0]; 203 | const paragraph = split[1]; 204 | 205 | const addToLink = (link) => { 206 | if(!links.includes(link)) { 207 | links.push(link); 208 | } 209 | }; 210 | 211 | if(paragraph === 'noparagraph') { 212 | const regex = /\[\[(#s-\d+(?:\.\d+)*)(?:\|(.*))?\]\]/g; 213 | switch(type) { 214 | case 'whole': 215 | text = text.replace(regex, ''); 216 | break; 217 | 218 | case 'replace': 219 | text = text.replace(regex, (match, p1, p2) => { 220 | if(!p2) p2 = '§'; 221 | 222 | return escapeNW(`§ ${escapeHTML(p2)}`); 223 | }); 224 | break; 225 | 226 | case 'latter': 227 | text = text.replace(regex, '$2'); 228 | break; 229 | } 230 | } 231 | 232 | switch(type){ 233 | case 'whole': 234 | text = text.replace(/\[\[[^\[\]]*\]\]/g, ''); 235 | break; 236 | 237 | case 'replace': 238 | text = text.replace(this.regex, (match, p1, p2) => { 239 | if(p1.startsWith(':파일:')) p1 = p1.replace(':파일:', 'https://namu.wiki/w/파일:'); 240 | 241 | const anchorSplit = p1.split('#'); 242 | const url = anchorSplit[0]; 243 | const anchor = escapeHTML(anchorSplit[1] ? `#${anchorSplit[1]}` : ''); 244 | 245 | const isExternal = /^(http|https):\/\/[^]+/.test(p1); 246 | 247 | if(!p2){ 248 | if(!isExternal) { 249 | addToLink(url); 250 | return escapeNW( 251 | `` + 252 | escapeHTML(url) + 253 | `` 254 | ); 255 | } 256 | 257 | return escapeNW(`外 외부링크`); 258 | } 259 | 260 | if(!isExternal) { 261 | addToLink(url); 262 | return escapeNW( 263 | `` + 264 | escapeHTML(`${p2}(${p1})`) + 265 | `` 266 | ); 267 | } 268 | 269 | return escapeNW(`外 ${escapeHTML(p2)}`); 270 | }); 271 | break; 272 | 273 | case 'former': 274 | text = text.replace(this.regex, (match, p1) => { 275 | if(p1.startsWith(':파일:')) p1 = p1.replace(':파일:', 'https://namu.wiki/file/'); 276 | return p1; 277 | }); 278 | break; 279 | 280 | case 'latter': 281 | text = text.replace(this.regex, (match, p1, p2) => { 282 | if(!p2){ 283 | if(p1.startsWith(':파일:')) p1 = p1.replace(':파일:', 'https://namu.wiki/file/'); 284 | return p1; 285 | } 286 | return p2; 287 | }); 288 | break; 289 | 290 | case 'tag': 291 | text = text.replace(/\[\[/g, '').replace(/\]\]/g, ''); 292 | break; 293 | } 294 | 295 | return {text, links}; 296 | } 297 | } 298 | 299 | //링크만 있는 이미지 제거 300 | class ImageRemover extends Remover{ 301 | constructor(){ 302 | super(); 303 | this.regex = /((https|http)?:\/\/[^ ]+\.(jpg|jpeg|png|gif))(?:\?([^ ]+))?/ig; 304 | } 305 | 306 | async remove(type, text){ 307 | switch(type){ 308 | case 'whole': return text.replace(this.regex, ''); 309 | case 'replace': return text.replace(this.regex, (match, p1) => { 310 | return escapeNW(`이미지`); 311 | }); 312 | } 313 | 314 | return text; 315 | } 316 | } 317 | 318 | class LineBreakRemover extends MacroRemover{ 319 | constructor(){ 320 | super('br'); 321 | } 322 | 323 | replace(type){ 324 | switch(type){ 325 | case "whole": return ''; 326 | case "replace": return '\n'; 327 | } 328 | 329 | return text; 330 | } 331 | } 332 | 333 | class MultipleDefinitionRemover extends Remover{ 334 | constructor(){ 335 | super(); 336 | this.removers = arguments; 337 | } 338 | 339 | async remove(type, text){ 340 | for(let remover of this.removers) { 341 | text = await remover.remove(type, text); 342 | } 343 | 344 | return text; 345 | } 346 | } 347 | 348 | //[[파일:이미지]] 형식의 이미지 제거 349 | class NamuImageRemover extends Remover{ 350 | constructor(){ 351 | super(); 352 | this.regex = /\[\[파일:([^\[\]]*?)\]\]/g; 353 | } 354 | 355 | async remove(type, text){ 356 | switch(type){ 357 | case 'whole': 358 | return text = text.replace(this.regex, ''); 359 | 360 | case 'replace': 361 | return text = text.replace(this.regex, (match, p1) => { 362 | return escapeNW(`이미지`); 363 | }); 364 | } 365 | 366 | return text; 367 | } 368 | } 369 | 370 | class NicovideoRemover extends Remover { 371 | constructor() { 372 | super(); 373 | this.regex = /\[nicovideo\(([sm0-9]+)\)\]/gi; 374 | } 375 | 376 | async remove(type, text) { 377 | switch(type) { 378 | case 'whole': 379 | return text.replace(this.regex, ''); 380 | 381 | case 'replace': 382 | return text.replace( 383 | this.regex, 384 | (match, p1) => escapeNW(`동영상`) 385 | ); 386 | } 387 | 388 | return text; 389 | } 390 | } 391 | 392 | class PageCountRemover extends MacroRemover { 393 | constructor() { 394 | super('pagecount'); 395 | } 396 | 397 | replace(type, match) { 398 | switch(type) { 399 | case 'replace': 400 | //TODO handle 401 | return '?'; 402 | 403 | case 'whole': return ''; 404 | } 405 | 406 | return match; 407 | } 408 | } 409 | 410 | class QuoteRemover extends Remover{ 411 | constructor(){ 412 | super(); 413 | } 414 | 415 | async remove(type, text, cb){ 416 | switch(type){ 417 | case 'replace': 418 | return text.replace(/^>(.*)$/gm, (match, p1) => escapeNW(`${escapeHTML(p1)}`)); 419 | 420 | case 'tag': 421 | return text.replace(/^>/gm, ''); 422 | 423 | case 'whole': 424 | return text.replace(/^>.*$/gm, ''); 425 | } 426 | 427 | return text; 428 | } 429 | } 430 | 431 | class SimpleMacroRemover extends MacroRemover{ 432 | constructor(macroName) { 433 | super(macroName); 434 | } 435 | 436 | replace(type, match) { 437 | if(type === 'whole') return ''; 438 | 439 | return match; 440 | } 441 | } 442 | 443 | class SimpleTagRemover extends Remover{ 444 | constructor(tag, polyfill){ 445 | super(); 446 | this.tag = tag; 447 | this.polyfill = polyfill; 448 | } 449 | 450 | async remove(type, text) { 451 | switch(type){ 452 | case 'replace': 453 | return text.replace(new RegExp("(" + this.tag + ")", 'ig'), this.polyfill); 454 | 455 | case 'tag': 456 | return text.replace(new RegExp(this.tag, 'g'), ''); 457 | 458 | case 'whole': 459 | return text.replace(new RegExp(this.tag + ".*?" + this.tag, 'g'), ''); 460 | } 461 | 462 | return text; 463 | } 464 | } 465 | 466 | class SimpleTagHTMLRemover extends Remover { 467 | constructor(tag, htmlTagName) { 468 | super(); 469 | this.tag = tag; 470 | this.html = htmlTagName; 471 | } 472 | 473 | async remove(type, text) { 474 | switch(type) { 475 | case 'replace': 476 | /* 477 | 1. Template is escaped. ([lt]b[gt]$1[lt]/b[gt]) 478 | 2. Replaced ([lt]b[gt]blah<>blah[lt]/b[gt]) 479 | 3. HTML chars are escaped. ([lt]b[gt]blah<>blah[lt]/b[gt]) (by Finalizer) 480 | 4. NW chars are unescaped.(blah<>blah) (by Finalizer) 481 | */ 482 | return text.replace( 483 | new RegExp(this.tag + '([^]*?)' + this.tag, 'ig'), 484 | (match, p1) => { 485 | return escapeNW(`<${this.html}>${escapeHTML(p1)}`); 486 | } 487 | ); 488 | 489 | case 'tag': 490 | return text.replace(new RegExp(this.tag, 'g'), ''); 491 | 492 | case 'whole': 493 | return text.replace(new RegExp(this.tag + ".*?" + this.tag, 'g'), ''); 494 | } 495 | 496 | return text; 497 | } 498 | } 499 | 500 | class TableRemover extends Remover{ 501 | constructor(){ 502 | super(); 503 | } 504 | 505 | async remove(type, text){ 506 | switch(type){ 507 | case 'tag': 508 | text = text 509 | .replace(/<#[a-fA-F0-9]{3,6}?>/g, '') //<#000000> 꼴 제거 510 | .replace(/\|\|/g, ' ') // || 변환 511 | .replace(/<\|[0-9]+>/g, '') //<|숫자> 꼴 제거 512 | .replace(/<-[0-9]+>/g, '') //<-숫자> 꼴 제거 513 | .replace(//g, '') // 꼴 제거 514 | .replace(//g, '') // 515 | .replace(/<\)>/g, '') //<)> 제거 516 | .replace(/<\(>/g, '') //<(> 제거 517 | .replace(/<:>/g, '') //<:> 제거 518 | .replace(/<(bgcolor|rowbgcolor|width|height)=.*?>/g, '') // 꼴 제거 519 | .replace(/\|.*?\|/g, ''); //캡션 520 | } 521 | 522 | return text; 523 | } 524 | } 525 | 526 | class YoutubeRemover extends Remover { 527 | constructor() { 528 | super(); 529 | this.regex = /\[youtube\(([a-zA-Z0-9_-]+)(?:,.*)*\)\]/gi; 530 | } 531 | 532 | async remove(type, text) { 533 | switch(type) { 534 | case 'whole': 535 | return text.replace(this.regex, ''); 536 | 537 | case 'replace': 538 | return text.replace( 539 | this.regex, 540 | (match, p1) => escapeNW(`동영상`) 541 | ); 542 | } 543 | 544 | return text; 545 | } 546 | } 547 | 548 | class Finalizer extends Remover { 549 | constructor() { 550 | super(); 551 | } 552 | 553 | async remove(type, text) { 554 | if(type) { 555 | text = unescapeNW(escapeHTML(text)); 556 | text = text.replace(/\n+/g, '\n'); 557 | } 558 | 559 | return text; 560 | } 561 | } 562 | 563 | module.exports = { 564 | bold: new SimpleTagHTMLRemover("'''", 'b'), 565 | italic: new SimpleTagHTMLRemover("''", 'i'), 566 | underline: new SimpleTagRemover("__"), 567 | striken: new MultipleDefinitionRemover(new SimpleTagRemover("--", "~~"), new SimpleTagRemover("~~", "~~")), 568 | 569 | superscript: new SimpleTagRemover("\\^\\^"), 570 | subscript: new SimpleTagRemover(",,"), 571 | 572 | html: new BraceRemover("#!html"), 573 | syntax: new BraceRemover("#!syntax"), 574 | wiki: new BraceRemover("#!wiki"), 575 | size: new BraceRemover("\\+[0-5]"), 576 | color: new BraceRemover("#[a-zA-Z0-9]+"), 577 | nomarkup: new BraceRemover(""), 578 | 579 | attachment: new AttachmentRemover(), 580 | image: new ImageRemover(), 581 | namuimage: new NamuImageRemover(), 582 | 583 | hyperlink: new HyperlinkRemover(), 584 | 585 | quote: new QuoteRemover(), 586 | line: new LineBreakRemover(), 587 | youtube: new YoutubeRemover(), 588 | nicovideo: new NicovideoRemover(), 589 | table: new TableRemover(), 590 | include: new SimpleMacroRemover('include'), 591 | math: new SimpleMacroRemover('math'), 592 | anchor: new SimpleMacroRemover('anchor'), 593 | toc: new MultipleDefinitionRemover(new SimpleMacroRemover('목차'), new SimpleMacroRemover('tableofcontents')), 594 | footnote_macro: new MultipleDefinitionRemover(new SimpleMacroRemover('각주'), new SimpleMacroRemover('footnote')), 595 | age: new AgeRemover(), 596 | //TODO dday, ruby 597 | date: new MultipleDefinitionRemover(new DateRemover('date'), new DateRemover('datetime')), 598 | pagecount: new PageCountRemover(), 599 | footnote: new FootnoteRemover(), 600 | finalizer: new Finalizer() 601 | }; 602 | --------------------------------------------------------------------------------