1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
/* * lib.rs * * ftml - Convert Wikidot code to HTML * Copyright (C) 2019 Ammon Smith * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #![deny(missing_debug_implementations)] //! A library to convert Wikidot text source into HTML. //! //! This library aims to be a replacement of Wikidot's Text_Wiki //! module, but with the goals of providing more modular integration //! and standalone servicing. //! //! While backwards compatibility with Wikidot code is one of the aims //! of this library, there are constructions which are valid in Wikidot //! but deliberately invalid in ftml. The total scope of all Wikidot code //! that is valid would almost require a parser nearly identical to the one //! attempting to be rewritten to cover every edge case, even if supporting //! such a case is not very useful or sensible. //! //! For instance, the following is valid code: //! ```text //! > [[div class="test"] //! > A man, a plan, a canal, Panama. //! [[/div]] //! ``` //! //! However the actual extent of the blockquote intersects with the div, and //! it essentially is the HTML equivalent of //! ```text //! <div class="outer"> //! <p class="inner"> //! </div> //! </p> //! ``` //! //! Which is obviously invalid syntax, and can cause issues. //! //! Instead the library's parser defines a grammar, which is designed to be //! compatible with all common Wikidot constructions, or has extensions for //! situations that are not directly supported. This largely-overlapping but //! slightly dissimilar specification ("ftml code") aims at being able to //! _effectively_ replace Wikidot code with minor human involvement to //! replace malformed original sources. //! //! This crate also provides an executable to convert files from //! the command-line. See that file for usage documentation. extern crate arrayvec; extern crate chrono; extern crate either; #[macro_use] extern crate lazy_static; #[macro_use] extern crate log; extern crate percent_encoding; extern crate pest; #[macro_use] extern crate pest_derive; extern crate regex; #[macro_use] extern crate serde; #[macro_use] extern crate serde_repr; #[macro_use] extern crate str_macro; #[macro_use] extern crate thiserror; #[cfg(test)] extern crate serde_json; #[macro_use] mod macros; pub mod data; mod enums; mod error; mod filter; pub mod handle; mod info; mod parse; mod render; #[cfg(test)] mod test; pub use self::error::{Error, RemoteError}; pub use self::filter::prefilter; pub use self::handle::RemoteHandle; pub use self::info::{PageInfo, PageInfoOwned}; pub use self::parse::{parse, ImageArguments, Paragraph, SyntaxTree, Word}; pub use self::render::html; pub use self::render::{HtmlRender, Render, TreeRender}; pub mod prelude { pub use super::{data, handle, parse, prefilter}; pub use super::{ Error, HtmlRender, PageInfo, PageInfoOwned, Render, Result, StdResult, SyntaxTree, TreeRender, }; } pub type StdResult<T, E> = std::result::Result<T, E>; pub type Result<T> = StdResult<T, Error>; pub type RemoteResult<T> = StdResult<T, RemoteError>;