示例#1
0
文件: html.c 项目: JBondi/snudown
static int
rndr_codespan(struct buf *ob, const struct buf *text, void *opaque)
{
	BUFPUTSL(ob, "<code>");
	if (text) escape_html(ob, text->data, text->size);
	BUFPUTSL(ob, "</code>");
	return 1;
}
示例#2
0
文件: html.c 项目: apnadkarni/hoedown
static int
rndr_codespan(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data)
{
	HOEDOWN_BUFPUTSL(ob, "<code>");
	if (text) escape_html(ob, text->data, text->size);
	HOEDOWN_BUFPUTSL(ob, "</code>");
	return 1;
}
示例#3
0
文件: html.c 项目: apnadkarni/hoedown
static int
rndr_math(hoedown_buffer *ob, const hoedown_buffer *text, int displaymode, const hoedown_renderer_data *data)
{
	hoedown_buffer_put(ob, (const uint8_t *)(displaymode ? "\\[" : "\\("), 2);
	escape_html(ob, text->data, text->size);
	hoedown_buffer_put(ob, (const uint8_t *)(displaymode ? "\\]" : "\\)"), 2);
	return 1;
}
示例#4
0
static void
rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque)
{
	struct html_renderopt *options = opaque;

	if (ob->size) bufputc(ob, '\n');

	if (lang && lang->size) {
		size_t i, cls;
		if (options->flags & HTML_PRETTIFY) {
			BUFPUTSL(ob, "<pre><code class=\"prettyprint lang-");
			cls++;
		} else {
			BUFPUTSL(ob, "<pre><code class=\"");
		}

		for (i = 0, cls = 0; i < lang->size; ++i, ++cls) {
			while (i < lang->size && isspace(lang->data[i]))
				i++;

			if (i < lang->size) {
				size_t org = i;
				while (i < lang->size && !isspace(lang->data[i]))
					i++;

				if (lang->data[org] == '.')
					org++;

				if (cls) bufputc(ob, ' ');
				escape_html(ob, lang->data + org, i - org);
			}
		}

		BUFPUTSL(ob, "\">");
	} else if (options->flags & HTML_PRETTIFY) {
		BUFPUTSL(ob, "<pre><code class=\"prettyprint\">");
	} else {
		BUFPUTSL(ob, "<pre><code>");
	}

	if (text)
		escape_html(ob, text->data, text->size);

	BUFPUTSL(ob, "</code></pre>\n");
}
示例#5
0
LINES comment::get_save_format(){
	LINES returnval;
	returnval.push_back("<comment author='"+m_author+"' date=''>");
	for(LINES::const_iterator it=m_data.begin();it!=m_data.end();++it){
		returnval.push_back(escape_html(*it));
	}
	returnval.push_back("</comment>");
	return returnval;
}
示例#6
0
文件: html.c 项目: Anomareh/Hoep
static void
rndr_blockcode(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_buffer *lang, void *opaque)
{
	if (ob->size) hoedown_buffer_putc(ob, '\n');

	if (lang) {
		HOEDOWN_BUFPUTSL(ob, "<pre><code class=\"language-");
		escape_html(ob, lang->data, lang->size);
		HOEDOWN_BUFPUTSL(ob, "\">");
	} else {
		HOEDOWN_BUFPUTSL(ob, "<pre><code>");
	}

	if (text)
		escape_html(ob, text->data, text->size);

	HOEDOWN_BUFPUTSL(ob, "</code></pre>\n");
}
示例#7
0
文件: html.c 项目: mdietz/misaka
/********************
 * GENERIC RENDERER *
 ********************/
static int
rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque)
{
	struct html_renderopt *options = opaque;

	if (!link || !link->size)
		return 0;

	if ((options->flags & HTML_SAFELINK) != 0 &&
		!sd_autolink_issafe(link->data, link->size) &&
		type != MKDA_EMAIL)
		return 0;

	BUFPUTSL(ob, "<a href=\"");
	if (type == MKDA_EMAIL)
		BUFPUTSL(ob, "mailto:");
	escape_href(ob, link->data, link->size);

	if (options->link_attributes) {
		bufputc(ob, '\"');
		options->link_attributes(ob, link, opaque);
		bufputc(ob, '>');
	} else if (options->flags & HTML_NEW_TAB_LINKS) {
    BUFPUTSL(ob, "\" target=\"_blank\">");
  } else {
		BUFPUTSL(ob, "\">");
	}

	/*
	 * Pretty printing: if we get an email address as
	 * an actual URI, e.g. `mailto:[email protected]`, we don't
	 * want to print the `mailto:` prefix
	 */
	if (bufprefix(link, "mailto:") == 0) {
		escape_html(ob, link->data + 7, link->size - 7);
	} else {
		escape_html(ob, link->data, link->size);
	}

	BUFPUTSL(ob, "</a>");

	return 1;
}
示例#8
0
文件: html.c 项目: Anomareh/Hoep
static int
rndr_image(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *alt, void *opaque)
{
	hoedown_html_renderer_state *state = opaque;
	if (!link || !link->size) return 0;

	HOEDOWN_BUFPUTSL(ob, "<img src=\"");
	escape_href(ob, link->data, link->size);
	HOEDOWN_BUFPUTSL(ob, "\" alt=\"");

	if (alt && alt->size)
		escape_html(ob, alt->data, alt->size);

	if (title && title->size) {
		HOEDOWN_BUFPUTSL(ob, "\" title=\"");
		escape_html(ob, title->data, title->size); }

	hoedown_buffer_puts(ob, USE_XHTML(state) ? "\"/>" : "\">");
	return 1;
}
示例#9
0
文件: html.c 项目: beingryu/sundown
static int
rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque)
{
	struct html_renderopt *options = opaque;
	if (!link || !link->size) return 0;

	BUFPUTSL(ob, "<img src=\"");
	escape_href(ob, link->data, link->size);
	BUFPUTSL(ob, "\" alt=\"");

	if (alt && alt->size)
		escape_html(ob, alt->data, alt->size);

	if (title && title->size) {
		BUFPUTSL(ob, "\" title=\"");
		escape_html(ob, title->data, title->size); }

	bufputs(ob, USE_XHTML(options) ? "\"/>" : "\">");
	return 1;
}
示例#10
0
文件: html.c 项目: Anomareh/Hoep
/********************
 * GENERIC RENDERER *
 ********************/
static int
rndr_autolink(hoedown_buffer *ob, const hoedown_buffer *link, enum hoedown_autolink type, void *opaque)
{
	hoedown_html_renderer_state *state = opaque;

	if (!link || !link->size)
		return 0;

	if ((state->flags & HOEDOWN_HTML_SAFELINK) != 0 &&
		!hoedown_autolink_is_safe(link->data, link->size) &&
		type != HOEDOWN_AUTOLINK_EMAIL)
		return 0;

	HOEDOWN_BUFPUTSL(ob, "<a href=\"");
	if (type == HOEDOWN_AUTOLINK_EMAIL)
		HOEDOWN_BUFPUTSL(ob, "mailto:");
	escape_href(ob, link->data, link->size);

	if (state->link_attributes) {
		hoedown_buffer_putc(ob, '\"');
		state->link_attributes(ob, link, opaque);
		hoedown_buffer_putc(ob, '>');
	} else {
		HOEDOWN_BUFPUTSL(ob, "\">");
	}

	/*
	 * Pretty printing: if we get an email address as
	 * an actual URI, e.g. `mailto:[email protected]`, we don't
	 * want to print the `mailto:` prefix
	 */
	if (hoedown_buffer_prefix(link, "mailto:") == 0) {
		escape_html(ob, link->data + 7, link->size - 7);
	} else {
		escape_html(ob, link->data, link->size);
	}

	HOEDOWN_BUFPUTSL(ob, "</a>");

	return 1;
}
示例#11
0
static int
rndr_codespan(struct buf *ob, const struct buf *text, void *opaque)
{
	struct html_renderopt *options = opaque;
	if (options->flags & HTML_PRETTIFY)
		BUFPUTSL(ob, "<code class=\"prettyprint\">");
	else
		BUFPUTSL(ob, "<code>");
	if (text) escape_html(ob, text->data, text->size);
	BUFPUTSL(ob, "</code>");
	return 1;
}
示例#12
0
文件: html.c 项目: beingryu/sundown
static int
rndr_mathspan(struct buf *ob, const struct buf *text, void *opaque)
{
	BUFPUTSL(ob, "<span class=\"mathjax-preview\">");
	if (text)
		escape_html(ob, text->data, text->size);
	BUFPUTSL(ob, "</span>");
	BUFPUTSL(ob, "<script type=\"math/tex\">");
	if (text)
	    bufput(ob, text->data, text->size);
	BUFPUTSL(ob, "</script>");
	return 1;
}
示例#13
0
static int
rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque)
{
	struct html_renderopt *options = opaque;

	if (link != NULL && (options->flags & HTML_SAFELINK) != 0 && !sd_autolink_issafe(link->data, link->size))
		return 0;

	BUFPUTSL(ob, "<img src=\"");
	escape_href(ob, link->data, link->size);
	BUFPUTSL(ob, "\" alt=\"");

	if (alt && alt->size)
		escape_html(ob, alt->data, alt->size);

	if (title && title->size) {
		BUFPUTSL(ob, "\" title=\"");
		escape_html(ob, title->data, title->size); }

	bufputs(ob, USE_XHTML(options) ? "\"/>" : "\">");
	return 1;
}
示例#14
0
文件: html.c 项目: Knagis/CommonMark
// Convert an inline list to HTML.  Returns 0 on success, and sets result.
static void inlines_to_plain_html(strbuf *html, node_inl* ils)
{
	node_inl* children;
	bool visit_children;
	render_stack* rstack = NULL;

	while(ils != NULL) {
		visit_children = false;
		switch(ils->tag) {
		case INL_STRING:
		case INL_CODE:
		case INL_RAW_HTML:
			escape_html(html, ils->content.literal.data, ils->content.literal.len);
			break;

		case INL_LINEBREAK:
		case INL_SOFTBREAK:
			strbuf_putc(html, '\n');
			break;

		case INL_LINK:
		case INL_IMAGE:
			children = ils->content.linkable.label;
			visit_children = true;
			rstack = push_inline(rstack, ils->next, "");
			break;

		case INL_STRONG:
		case INL_EMPH:
			children = ils->content.inlines;
			visit_children = true;
			rstack = push_inline(rstack, ils->next, "");
			break;
		}
		if (visit_children) {
			ils = children;
		} else {
			ils = ils->next;
		}
		while (ils == NULL && rstack != NULL) {
			strbuf_puts(html, rstack->literal);
			ils = rstack->next_sibling.inl;
			rstack = pop_render_stack(rstack);
		}
	}

	free_render_stack(rstack);
}
示例#15
0
void PostDataChecker::validate_comment(apr_pool_t *pool, const char **comment,
                                       const char *code_pat)
{
    apr_size_t escaped_length;

    if (strlen(*comment) == 0) {
        return;
    }

    // 不正なシーケンスを排除
    *comment = CharCodeConverter::convert
        (pool, *comment,
         reinterpret_cast<const unsigned char *>(code_pat));

    escape_html(pool, *comment, strlen(*comment), comment, &escaped_length);
}
示例#16
0
int bee_user_msg(bee_t *bee, bee_user_t *bu, const char *msg, int flags)
{
	char *buf = NULL;
	int st;

	if ((bu->ic->flags & OPT_DOES_HTML) && (g_strncasecmp(msg, "<html>", 6) != 0)) {
		buf = escape_html(msg);
		msg = buf;
	} else {
		buf = g_strdup(msg);
	}

	st = bu->ic->acc->prpl->buddy_msg(bu->ic, bu->handle, buf, flags);
	g_free(buf);

	return st;
}
示例#17
0
文件: html.c 项目: JBondi/snudown
static int
rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque)
{
    struct html_renderopt *options = opaque;
    char** whitelist = options->html_element_whitelist;
    int i, tagtype;

    /* Items on the whitelist ignore all other flags and just output */
    if (((options->flags & HTML_ALLOW_ELEMENT_WHITELIST) != 0) && whitelist) {
        for (i = 0; whitelist[i]; i++) {
            tagtype = sdhtml_is_tag(text->data, text->size, whitelist[i]);
            if (tagtype != HTML_TAG_NONE) {
                rndr_html_tag(ob, text, opaque,
                              whitelist[i],
                              options->html_attr_whitelist,
                              tagtype);
                return 1;
            }
        }
    }

    /* HTML_ESCAPE overrides SKIP_HTML, SKIP_STYLE, SKIP_LINKS and SKIP_IMAGES
    * It doens't see if there are any valid tags, just escape all of them. */
    if((options->flags & HTML_ESCAPE) != 0) {
        escape_html(ob, text->data, text->size);
        return 1;
    }

    if ((options->flags & HTML_SKIP_HTML) != 0)
        return 1;

    if ((options->flags & HTML_SKIP_STYLE) != 0 &&
        sdhtml_is_tag(text->data, text->size, "style"))
        return 1;

    if ((options->flags & HTML_SKIP_LINKS) != 0 &&
        sdhtml_is_tag(text->data, text->size, "a"))
        return 1;

    if ((options->flags & HTML_SKIP_IMAGES) != 0 &&
        sdhtml_is_tag(text->data, text->size, "img"))
        return 1;

    bufput(ob, text->data, text->size);
    return 1;
}
示例#18
0
文件: html.c 项目: beingryu/sundown
static void
rndr_blockmath(struct buf *ob, const struct buf *text, void *opaque)
{
	if (ob->size) bufputc(ob, '\n');

	BUFPUTSL(ob, "<div class=\"mathjax-preview\">");
	if (text)
		escape_html(ob, text->data, text->size);
	BUFPUTSL(ob, "</div>");

	BUFPUTSL(ob, "<script type=\"math/tex; mode=display\">");

	if (text)
		bufput(ob, text->data, text->size);

	BUFPUTSL(ob, "</script>");
}
示例#19
0
文件: html.c 项目: apnadkarni/hoedown
static int
rndr_raw_html(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_renderer_data *data)
{
	hoedown_html_renderer_state *state = data->opaque;

	/* ESCAPE overrides SKIP_HTML. It doesn't look to see if
	 * there are any valid tags, just escapes all of them. */
	if((state->flags & HOEDOWN_HTML_ESCAPE) != 0) {
		escape_html(ob, text->data, text->size);
		return 1;
	}

	if ((state->flags & HOEDOWN_HTML_SKIP_HTML) != 0)
		return 1;

	hoedown_buffer_put(ob, text->data, text->size);
	return 1;
}
示例#20
0
static void
toc_header(struct buf *ob, const struct buf *text, int level, void *opaque)
{
	struct html_renderopt *options = opaque;

	if (level <= options->toc_data.nesting_level) {
		/* set the level offset if this is the first header
		 * we're parsing for the document */
		if (options->toc_data.current_level == 0)
			options->toc_data.level_offset = level - 1;

		level -= options->toc_data.level_offset;

		if (level > options->toc_data.current_level) {
			while (level > options->toc_data.current_level) {
				BUFPUTSL(ob, "<ul>\n<li>\n");
				options->toc_data.current_level++;
			}
		} else if (level < options->toc_data.current_level) {
			BUFPUTSL(ob, "</li>\n");
			while (level < options->toc_data.current_level) {
				BUFPUTSL(ob, "</ul>\n</li>\n");
				options->toc_data.current_level--;
			}
			BUFPUTSL(ob,"<li>\n");
		} else {
			BUFPUTSL(ob,"</li>\n<li>\n");
		}

		bufprintf(ob, "<a href=\"#");
		rndr_header_anchor(ob, text);
		BUFPUTSL(ob, "\">");

		if (text) {
			if (options->flags & HTML_ESCAPE)
				escape_html(ob, text->data, text->size);
			else
				bufput(ob, text->data, text->size);
		}

		BUFPUTSL(ob, "</a>\n");
	}
}
示例#21
0
文件: html.c 项目: JBondi/snudown
static void
toc_header(struct buf *ob, const struct buf *text, int level, void *opaque)
{
	struct html_renderopt *options = opaque;

	/* set the level offset if this is the first header
	 * we're parsing for the document */
	if (options->toc_data.current_level == 0) {
		BUFPUTSL(ob, "<div class=\"toc\">\n");
		options->toc_data.level_offset = level - 1;
	}
	level -= options->toc_data.level_offset;

	if (level > options->toc_data.current_level) {
		while (level > options->toc_data.current_level) {
			BUFPUTSL(ob, "<ul>\n<li>\n");
			options->toc_data.current_level++;
		}
	} else if (level < options->toc_data.current_level) {
		BUFPUTSL(ob, "</li>\n");
		while (level < options->toc_data.current_level) {
			BUFPUTSL(ob, "</ul>\n</li>\n");
			options->toc_data.current_level--;
		}
		BUFPUTSL(ob,"<li>\n");
	} else {
		BUFPUTSL(ob,"</li>\n<li>\n");
	}

	BUFPUTSL(ob, "<a href=\"#");

	if (options->toc_id_prefix) {
		bufputs(ob, options->toc_id_prefix);
	}

	bufprintf(ob, "toc_%d\">", options->toc_data.header_count++);
	if (text)
		escape_html(ob, text->data, text->size);
	BUFPUTSL(ob, "</a>\n");
}
示例#22
0
static VALUE rb_escape_html(VALUE self, VALUE str) {
    Check_Type(str, T_STRING);

    VALUE rb_output_buf;
    unsigned char *inBuf = (unsigned char*)RSTRING_PTR(str);
    size_t len = RSTRING_LEN(str), new_len = 0;

    // this is the max size the string could be
    // TODO: we should try to be more intelligent about this
    unsigned char *outBuf = (unsigned char *)malloc(sizeof(unsigned char *)*(len*5));

    // perform our escape, returning the new string's length
    new_len = escape_html(outBuf, inBuf, len);

    // create our new ruby string
    rb_output_buf = rb_str_new((char *)outBuf, new_len);

    // free the temporary C string
    free(outBuf);

    return rb_output_buf;
}
示例#23
0
static void
rndr_normal_text(struct buf *ob, const struct buf *text, void *opaque)
{
	if (text)
		escape_html(ob, text->data, text->size);
}
示例#24
0
文件: dot2.hpp 项目: riverans/ironbee
void to_dot2_base(
    std::ostream& out,
    Iterator      begin,
    Iterator      end,
    root_namer_t  root_namer,
    node_hook_t   node_hook
)
{
    typedef std::set<node_cp> node_cset_t;
    node_clist_t queue;
    node_cset_t skip;

    copy(begin, end, std::back_inserter(queue));

    // Header
    out << "digraph G {" << std::endl;
    out << "  ordering = out;" << std::endl;
    out << "  edge [arrowsize=0.5, fontsize=9];" << std::endl;
    out << "  node [fontname=Courier, penwidth=0.2, shape=rect, height=0.4];"
        << std::endl;

    // Body
    while (! queue.empty()) {
        node_cp node = queue.front();
        queue.pop_front();
        if (skip.count(node)) {
            continue;
        }
        skip.insert(node);

        // If node is a literal...
        if (node->is_literal()) {
            render_literal(out, node);
        }
        else {
            boost::shared_ptr<const Call> call =
                boost::dynamic_pointer_cast<const Call>(node);
            assert(call);
            std::string extra;

            // Let node hook run.
            if (node_hook) {
                node_hook(out, extra, node);
            }

            // Otherwise node is a call.
            if (node->children().size() > 8) {
                // High degree nodes, have no absorbption.
                render_node(out, node,
                            "label=<" + escape_html(call->name()) + ">"
                           );
                BOOST_FOREACH(const node_cp& child, node->children()) {
                    render_edge(out, node, child);
                    queue.push_back(child);
                }
            }
            else {
                // Try to absorb children.
                std::vector<std::string> name;
                name.push_back("<b>" + call->name() + "</b>");
                unsigned int placeholder = 0;

                BOOST_FOREACH(const node_cp& child, node->children()) {
                    if (is_absorbable(child, root_namer)) {
                        if (child->to_s()[0] == '\'') {
                            name.push_back(
                                "<i>" + escape_html(child->to_s()) + "</i>"
                            );
                        }
                        else {
                            name.push_back(
                                "<font>" + escape_html(child->to_s()) +
                                "</font>"
                            );
                        }
                    }
                    else {
                        ++placeholder;
                        name.push_back(
                            "<font>" + circle_n(placeholder) + "</font>"
                        );
                        render_edge(out, node, child, circle_n(placeholder));
                        queue.push_back(child);
                    }
                }
                render_node(out, node,
                            "label=<" +
                            boost::algorithm::join(name, " ") + ">" +
                            extra
                           );
            }
        }
示例#25
0
void document_propertiest::doit()
{
  typedef std::map<source_locationt, doc_claimt> claim_sett;
  claim_sett claim_set;

  forall_goto_functions(f_it, goto_functions)
  {
    const goto_programt &goto_program=f_it->second.body;

    forall_goto_program_instructions(i_it, goto_program)
    {
      if(i_it->is_assert())
      {
        source_locationt new_source_location;

        new_source_location.set_file(i_it->source_location.get_file());
        new_source_location.set_line(i_it->source_location.get_line());
        new_source_location.set_function(i_it->source_location.get_function());

        claim_set[new_source_location].comment_set.
          insert(i_it->source_location.get_comment());
      }
    }
  }

  for(claim_sett::const_iterator it=claim_set.begin();
      it!=claim_set.end(); it++)
  {
    std::string code;
    const source_locationt &source_location=it->first;

    get_code(source_location, code);

    switch(format)
    {
    case LATEX:
      out << "\\claimlocation{File "
          << escape_latex(source_location.get_string("file"), false)
          << " function "
          << escape_latex(source_location.get_string("function"), false)
          << "}" << std::endl;

      out << std::endl;

      for(std::set<irep_idt>::const_iterator
          s_it=it->second.comment_set.begin();
          s_it!=it->second.comment_set.end();
          s_it++)
        out << "\\claim{" << escape_latex(id2string(*s_it), false)
            << "}" << std::endl;

      out << std::endl;

      out << "\\begin{alltt}\\claimcode\n"
          << code
          << "\\end{alltt}\n";

      out << std::endl;
      out << std::endl;
      break;

    case HTML:
      out << "<div class=\"claim\">" << std::endl
          << "<div class=\"location\">File "
          << escape_html(source_location.get_string("file"))
          << " function "
          << escape_html(source_location.get_string("function"))
          << "</div>" << std::endl;

      out << std::endl;

      for(std::set<irep_idt>::const_iterator
          s_it=it->second.comment_set.begin();
          s_it!=it->second.comment_set.end();
          s_it++)
        out << "<div class=\"description\">" << std::endl
            << escape_html(id2string(*s_it)) << std::endl
            << "</div>" << std::endl;

      out << std::endl;

      out << "<div class=\"code\">\n"
          << code
          << "</div> <!-- code -->" << std::endl;

      out << "</div> <!-- claim -->" << std::endl;
      out << std::endl;
      break;
    }
  }
}
示例#26
0
void document_propertiest::get_code(
  const source_locationt &source_location,
  std::string &dest)
{
  dest="";

  const irep_idt &file=source_location.get_file();
  const irep_idt &line=source_location.get_line();

  if(file=="" || line=="") return;

  std::ifstream in(id2string(file));

  if(!in)
  {
    dest+="ERROR: unable to open ";
    dest+=id2string(file);
    dest+="\n";
    return;
  }

  int line_int=unsafe_string2int(id2string(line));

  int line_start=line_int-3,
      line_end=line_int+3;

  if(line_start<=1) line_start=1;

  // skip line_start-1 lines

  for(int l=0; l<line_start-1; l++)
  {
    std::string tmp;
    std::getline(in, tmp);
  }

  // read till line_end

  std::list<linet> lines;

  for(int l=line_start; l<=line_end && in; l++)
  {
    lines.push_back(linet());

    std::string &line=lines.back().text;
    std::getline(in, line);

    if(!line.empty() && line[line.size()-1]=='\r')
      line.resize(line.size()-1);

    lines.back().line_number=l;
  }

  // remove empty lines at the end and at the beginning

  for(std::list<linet>::iterator it=lines.begin();
      it!=lines.end();)
  {
    if(is_empty(it->text))
      it=lines.erase(it);
    else
      break;
  }

  for(std::list<linet>::iterator it=lines.end();
      it!=lines.begin();)
  {
    it--;

    if(is_empty(it->text))
      it=lines.erase(it);
    else
      break;
  }

  // strip space
  strip_space(lines);

  // build dest

  for(std::list<linet>::iterator it=lines.begin();
      it!=lines.end(); it++)
  {
    std::string line_no=std::to_string(it->line_number);

    std::string tmp;

    switch(format)
    {
    case LATEX:
      while(line_no.size()<4)
        line_no=" "+line_no;

      line_no+"  ";

      tmp+=escape_latex(it->text, true);

      if(it->line_number==line_int)
        tmp="{\\ttb{}"+tmp+"}";

      break;

    case HTML:
      while(line_no.size()<4)
        line_no="&nbsp;"+line_no;

      line_no+"&nbsp;&nbsp;";

      tmp+=escape_html(it->text);

      if(it->line_number==line_int)
        tmp="<em>"+tmp+"</em>";

      break;
    }

    dest+=tmp+"\n";
  }
}
示例#27
0
文件: html.c 项目: JBondi/snudown
static void
rndr_html_tag(struct buf *ob, const struct buf *text, void *opaque,
             char* tagname, char** whitelist, int tagtype)
{
    size_t i, x, z, in_str = 0, seen_equals = 0, done = 0, done_attr = 0, reset = 0;
    struct buf *attr;
    struct buf *value;
    char c;

    bufputc(ob, '<');

    if(tagtype == HTML_TAG_CLOSE) {
        bufputc(ob, '/');
        bufputs(ob, tagname);
        bufputc(ob, '>');
        return;
    }

    bufputs(ob, tagname);
    i = 1 + strlen(tagname);

    attr = bufnew(16);
    value = bufnew(16);

    for(; i < text->size && !done; i++) {
        c = text->data[i];
        done = 0;
        reset = 0;
        done_attr = 0;

        switch(c) {
            case '>':
                done = 1;
                break;
            case '\'':
            case '"':
                if(!seen_equals) {
                    reset = 1;
                } else if(!in_str) {
                    in_str = c;
                } else if(in_str == c) {
                    in_str = 0;
                    done_attr = 1;
                } else {
                    bufputc(value, c);
                }
                break;
            case ' ':
                if (in_str) {
                    bufputc(value, ' ');
                } else {
                    reset = 1;
                }
                break;
            case '=':
                if(seen_equals) {
                    reset = 1;
                    break;
                }
                seen_equals = 1;
                break;
            default:
                if(seen_equals && in_str || !seen_equals) {
                    bufputc(seen_equals ? value : attr, c);
                }
                break;
        }

        if(done_attr) {
            int valid = 0;
            for(z = 0; whitelist[z]; z++) {
                if(strlen(whitelist[z]) != attr->size) {
                    continue;
                }
                for(x = 0; x < attr->size; x++) {
                    if(tolower(whitelist[z][x]) != tolower(attr->data[x])) {
                        break;
                    }
                }
                if(x == attr->size) {
                    valid = 1;
                    break;
                }
            }
            if(valid && value->size && attr->size) {
                bufputc(ob, ' ');
                escape_html(ob, attr->data, attr->size);
                bufputs(ob, "=\"");
                escape_html(ob, value->data, value->size);
                bufputc(ob, '"');
            }
            reset = 1;
        }

        if(reset) {
            seen_equals = 0;
            in_str = 0;
            bufreset(attr);
            bufreset(value);
        }
    }

    bufrelease(attr);
    bufrelease(value);

    bufputc(ob, '>');
}
示例#28
0
文件: html.c 项目: Anomareh/Hoep
static void
rndr_normal_text(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque)
{
	if (text)
		escape_html(ob, text->data, text->size);
}
示例#29
0
文件: html.c 项目: apnadkarni/hoedown
static void
rndr_normal_text(hoedown_buffer *ob, const hoedown_buffer *content, const hoedown_renderer_data *data)
{
	if (content)
		escape_html(ob, content->data, content->size);
}
示例#30
0
文件: html.c 项目: lowks/cmark.ex
static int
S_render_node(cmark_node *node, cmark_event_type ev_type,
              struct render_state *state, int options)
{
	cmark_node *parent;
	cmark_node *grandparent;
	cmark_strbuf *html = state->html;
	char start_header[] = "<h0";
	char end_header[] = "</h0";
	bool tight;

	bool entering = (ev_type == CMARK_EVENT_ENTER);

	if (state->plain == node) { // back at original node
		state->plain = NULL;
	}

	if (state->plain != NULL) {
		switch(node->type) {
		case CMARK_NODE_TEXT:
		case CMARK_NODE_CODE:
		case CMARK_NODE_INLINE_HTML:
			escape_html(html, node->as.literal.data,
			            node->as.literal.len);
			break;

		case CMARK_NODE_LINEBREAK:
		case CMARK_NODE_SOFTBREAK:
			cmark_strbuf_putc(html, ' ');
			break;

		default:
			break;
		}
		return 1;
	}

	switch (node->type) {
	case CMARK_NODE_DOCUMENT:
		break;

	case CMARK_NODE_BLOCK_QUOTE:
		if (entering) {
			cr(html);
			cmark_strbuf_puts(html, "<blockquote");
			S_render_sourcepos(node, html, options);
			cmark_strbuf_puts(html, ">\n");
		} else {
			cr(html);
			cmark_strbuf_puts(html, "</blockquote>\n");
		}
		break;

	case CMARK_NODE_LIST: {
		cmark_list_type list_type = node->as.list.list_type;
		int start = node->as.list.start;

		if (entering) {
			cr(html);
			if (list_type == CMARK_BULLET_LIST) {
				cmark_strbuf_puts(html, "<ul");
				S_render_sourcepos(node, html, options);
				cmark_strbuf_puts(html, ">\n");
			} else if (start == 1) {
				cmark_strbuf_puts(html, "<ol");
				S_render_sourcepos(node, html, options);
				cmark_strbuf_puts(html, ">\n");
			} else {
				cmark_strbuf_printf(html,
				                    "<ol start=\"%d\"",
				                    start);
				S_render_sourcepos(node, html, options);
				cmark_strbuf_puts(html, ">\n");
			}
		} else {
			cmark_strbuf_puts(html,
			                  list_type == CMARK_BULLET_LIST ?
			                  "</ul>\n" : "</ol>\n");
		}
		break;
	}

	case CMARK_NODE_ITEM:
		if (entering) {
			cr(html);
			cmark_strbuf_puts(html, "<li");
			S_render_sourcepos(node, html, options);
			cmark_strbuf_putc(html, '>');
		} else {
			cmark_strbuf_puts(html, "</li>\n");
		}
		break;

	case CMARK_NODE_HEADER:
		if (entering) {
			cr(html);
			start_header[2] = '0' + node->as.header.level;
			cmark_strbuf_puts(html, start_header);
			S_render_sourcepos(node, html, options);
			cmark_strbuf_putc(html, '>');
		} else {
			end_header[3] = '0' + node->as.header.level;
			cmark_strbuf_puts(html, end_header);
			cmark_strbuf_puts(html, ">\n");
		}
		break;

	case CMARK_NODE_CODE_BLOCK:
		cr(html);

		if (!node->as.code.fenced || node->as.code.info.len == 0) {
			cmark_strbuf_puts(html, "<pre");
			S_render_sourcepos(node, html, options);
			cmark_strbuf_puts(html, "><code>");
		} else {
			int first_tag = 0;
			while (first_tag < node->as.code.info.len &&
			       node->as.code.info.data[first_tag] != ' ') {
				first_tag += 1;
			}

			cmark_strbuf_puts(html, "<pre");
			S_render_sourcepos(node, html, options);
			cmark_strbuf_puts(html, "><code class=\"language-");
			escape_html(html, node->as.code.info.data, first_tag);
			cmark_strbuf_puts(html, "\">");
		}

		escape_html(html, node->as.code.literal.data,
		            node->as.code.literal.len);
		cmark_strbuf_puts(html, "</code></pre>\n");
		break;

	case CMARK_NODE_HTML:
		cr(html);
		cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len);
		break;

	case CMARK_NODE_HRULE:
		cr(html);
		cmark_strbuf_puts(html, "<hr");
		S_render_sourcepos(node, html, options);
		cmark_strbuf_puts(html, " />\n");
		break;

	case CMARK_NODE_PARAGRAPH:
		parent = cmark_node_parent(node);
		grandparent = cmark_node_parent(parent);
		if (grandparent != NULL &&
		    grandparent->type == CMARK_NODE_LIST) {
			tight = grandparent->as.list.tight;
		} else {
			tight = false;
		}
		if (!tight) {
			if (entering) {
				cr(html);
				cmark_strbuf_puts(html, "<p");
				S_render_sourcepos(node, html, options);
				cmark_strbuf_putc(html, '>');
			} else {
				cmark_strbuf_puts(html, "</p>\n");
			}
		}
		break;

	case CMARK_NODE_TEXT:
		escape_html(html, node->as.literal.data, node->as.literal.len);
		break;

	case CMARK_NODE_LINEBREAK:
		cmark_strbuf_puts(html, "<br />\n");
		break;

	case CMARK_NODE_SOFTBREAK:
		if (options & CMARK_OPT_HARDBREAKS) {
			cmark_strbuf_puts(html, "<br />\n");
		} else {
			cmark_strbuf_putc(html, '\n');
		}
		break;

	case CMARK_NODE_CODE:
		cmark_strbuf_puts(html, "<code>");
		escape_html(html, node->as.literal.data, node->as.literal.len);
		cmark_strbuf_puts(html, "</code>");
		break;

	case CMARK_NODE_INLINE_HTML:
		cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len);
		break;

	case CMARK_NODE_STRONG:
		if (entering) {
			cmark_strbuf_puts(html, "<strong>");
		} else {
			cmark_strbuf_puts(html, "</strong>");
		}
		break;

	case CMARK_NODE_EMPH:
		if (entering) {
			cmark_strbuf_puts(html, "<em>");
		} else {
			cmark_strbuf_puts(html, "</em>");
		}
		break;

	case CMARK_NODE_LINK:
		if (entering) {
			cmark_strbuf_puts(html, "<a href=\"");
			if (node->as.link.url)
				escape_href(html, node->as.link.url, -1);

			if (node->as.link.title) {
				cmark_strbuf_puts(html, "\" title=\"");
				escape_html(html, node->as.link.title, -1);
			}

			cmark_strbuf_puts(html, "\">");
		} else {
			cmark_strbuf_puts(html, "</a>");
		}
		break;

	case CMARK_NODE_IMAGE:
		if (entering) {
			cmark_strbuf_puts(html, "<img src=\"");
			if (node->as.link.url)
				escape_href(html, node->as.link.url, -1);

			cmark_strbuf_puts(html, "\" alt=\"");
			state->plain = node;
		} else {
			if (node->as.link.title) {
				cmark_strbuf_puts(html, "\" title=\"");
				escape_html(html, node->as.link.title, -1);
			}

			cmark_strbuf_puts(html, "\" />");
		}
		break;

	default:
		assert(false);
		break;
	}

	// cmark_strbuf_putc(html, 'x');
	return 1;
}