Пример #1
0
    void operator()(html::ast const& node, int const depth) {
        if (indent_) indent(depth);
        if (node.get_name() == "pre") indent_ = false;

        auto& attributes = node.get_attributes();
        stream_ << '<' << node.get_name();

        if (node.get_name() == "code") {
            auto fileIt = node.get_attributes().find("file");
            if (fileIt != node.get_attributes().end()) {
                if (! node.get_children().empty()) {
                    std::cerr << "code block with file attribute may not have child nodes\n";
                }
                else {
                    stream_ << '>';
                    auto typeIt = node.get_attributes().find("source");
                    if (typeIt == node.get_attributes().end())
                        write_code_file(fileIt->second, range());
                    else
                        write_code_file(fileIt->second, typeIt->second);
                    stream_ << "</" << node.get_name() << ">";
                    if (indent_) stream_ << std::endl;
                    return;
                }
            }
        }
        else if (! attributes.empty()) {
            stream_ << ' ';
            auto it = attributes.begin();
            if (node.get_class_name().empty()) {
                stream_ << it->first << "=\"" << it->second << "\"";
                ++it;
            }
            else stream_ << "class=\"" << node.get_class_name() << "\"";

            while (it != attributes.end()) {
                stream_ << " " << it->first << "=\"" << it->second << "\"";
                ++it;
            }
        }
        else if (! node.get_class_name().empty()) {
            stream_ << " class=\"" << node.get_class_name() << "\"";
        }
        stream_ << '>';
        if (node.get_children().empty()) stream_ << "</" << node.get_name() << ">";
        if (indent_) stream_ << std::endl;
    }
Пример #2
0
/* Write out the code to a file, execute the code, and delete the file. */
int code_execute(struct code_state *code, char **error)
{
	if (code->list_head == NULL)
		return STATUS_OK;	/* no code to execute */

	write_code_file(code);
	int result = execute_code_command_line(code, error);
	delete_code_file(code);
	return result;
}