/** * Copyright (c) 2022, Timothy Stack * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of Timothy Stack nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef lnav_md2attr_line_hh #define lnav_md2attr_line_hh #include "base/attr_line.hh" #include "ghc/filesystem.hpp" #include "md4cpp.hh" class md2attr_line : public md4cpp::typed_event_handler { public: md2attr_line() { this->ml_blocks.resize(1); } md2attr_line& with_source_path(nonstd::optional path) { this->ml_source_path = path; return *this; } Result enter_block(const block& bl) override; Result leave_block(const block& bl) override; Result enter_span(const span& bl) override; Result leave_span(const span& sp) override; Result text(MD_TEXTTYPE tt, const string_fragment& sf) override; attr_line_t get_result() override { return this->ml_blocks.back(); } private: struct table_t { struct row_t { std::vector r_columns; }; std::vector t_headers; std::vector t_rows; }; struct cell_lines { cell_lines(std::vector lines) : cl_lines(std::move(lines)) { } std::vector cl_lines; }; using list_block_t = mapbox::util::variant; void append_url_footnote(std::string href); void flush_footnotes(); nonstd::optional ml_source_path; std::vector ml_blocks; std::vector ml_list_stack; std::vector ml_tables; std::vector ml_span_starts; std::vector ml_html_span_starts; std::vector ml_footnotes; int32_t ml_code_depth{0}; }; #endif