Esempio n. 1
0
std::string formatSuperAndSubscripts(const std::string& str, DocumentFormat fmt) {
  if (fmt == DocumentFormat::LaTeX) {
    std::string wStr(str);
    wStr = boost::regex_replace(wStr, superscript(), "$1\\\\ensuremath{$2}");
    wStr = boost::regex_replace(wStr, subscript(), "$1\\\\ensuremath{$2}");
    return wStr;
  }
  if (fmt == DocumentFormat::XHTML) {
    std::string wStr(str);
    wStr = boost::regex_replace(wStr, superscript(), "$1<sup>$3$4</sup>");
    wStr = boost::regex_replace(wStr, subscript(), "$1<sub>$3$4</sub>");
    wStr = boost::regex_replace(wStr, underscore(), "_");
    return wStr;
  }
  return str;
}
Esempio n. 2
0
static void md_convert_hashes(cmark_iter *const iter) {
	for(;;) {
		cmark_event_type const event = cmark_iter_next(iter);
		if(CMARK_EVENT_DONE == event) break;
		if(CMARK_EVENT_EXIT != event) continue;
		cmark_node *const node = cmark_iter_get_node(iter);
		cmark_node_type const type = cmark_node_get_type(node);
		if(CMARK_NODE_LINK != type && CMARK_NODE_IMAGE != type) continue;

		char const *const URI = cmark_node_get_url(node);
		if(!URI) continue;
		if(0 != strncasecmp(URI, STR_LEN("hash:"))) continue;

		cmark_node *sup = superscript("#", HASH_INFO_MSG, URI);
		cmark_node_insert_after(node, sup);
		cmark_iter_reset(iter, sup, CMARK_EVENT_EXIT);

		char *escaped = QSEscape(URI, strlen(URI), true);
		size_t const elen = strlen(escaped);
		cmark_strbuf rel[1];
		char const qpfx[] = "/sources/";
		cmark_strbuf_init(&DEFAULT_MEM_ALLOCATOR, rel, sizeof(qpfx)-1+elen);
		cmark_strbuf_put(rel, (unsigned char const *)qpfx, sizeof(qpfx)-1);
		cmark_strbuf_put(rel, (unsigned char const *)escaped, elen);
		free(escaped); escaped = NULL;
		cmark_node_set_url(node, cmark_strbuf_cstr(rel));
		cmark_strbuf_free(rel);
	}
}
Esempio n. 3
0
static void md_autolink(cmark_iter *const iter) {
	regex_t linkify[1];
	// <http://daringfireball.net/2010/07/improved_regex_for_matching_urls>
	// Painstakingly ported to POSIX
	int rc = regcomp(linkify, "([a-z][a-z0-9_-]+:(/{1,3}|[a-z0-9%])|www[0-9]{0,3}[.]|[a-z0-9.-]+[.][a-z]{2,4}/)([^[:space:]()<>]+|\\(([^[:space:]()<>]+|(\\([^[:space:]()<>]+\\)))*\\))+(\\(([^[:space:]()<>]+|(\\([^[:space:]()<>]+\\)))*\\)|[^][[:space:]`!(){};:'\".,<>?«»“”‘’])", REG_ICASE | REG_EXTENDED);
	assert(0 == rc);

	for(;;) {
		cmark_event_type const event = cmark_iter_next(iter);
		if(CMARK_EVENT_DONE == event) break;
		if(CMARK_EVENT_ENTER != event) continue;
		cmark_node *const node = cmark_iter_get_node(iter);
		if(CMARK_NODE_TEXT != cmark_node_get_type(node)) continue;

		char const *const str = cmark_node_get_literal(node);
		char const *pos = str;
		regmatch_t match;
		while(0 == regexec(linkify, pos, 1, &match, 0)) {
			regoff_t const loc = match.rm_so;
			regoff_t const len = match.rm_eo - match.rm_so;

			char *pfx = strndup(pos, loc);
			char *link_abs = strndup(pos+loc, len);
			char *link_rel = aasprintf("/history/%s", link_abs);
			assert(pfx);
			assert(link_abs);
			assert(link_rel);

			cmark_node *text = cmark_node_new(CMARK_NODE_TEXT);
			cmark_node_set_literal(text, pfx);
			cmark_node *link = cmark_node_new(CMARK_NODE_LINK);
			cmark_node_set_url(link, link_rel);
			cmark_node *sup = superscript("^", "", link_abs);
			cmark_node *face = cmark_node_new(CMARK_NODE_TEXT);
			cmark_node_set_literal(face, link_abs);
			cmark_node_append_child(link, face);
			cmark_node_insert_before(node, text);
			cmark_node_insert_before(node, link);
			cmark_node_insert_before(node, sup);

			free(pfx); pfx = NULL;
			free(link_abs); link_abs = NULL;
			free(link_rel); link_rel = NULL;

			pos += loc+len;
		}

		if(str != pos) {
			cmark_node *text = cmark_node_new(CMARK_NODE_TEXT);
			cmark_node_set_literal(text, pos);
			cmark_node_insert_before(node, text);
			cmark_node_free(node);
		}

	}
	regfree(linkify);
}
Esempio n. 4
0
FontEffects& FontEffects::operator+=(const FontEffects& eff)
{
    effects_.fx.weight=std::max(weight(), eff.weight());
    effects_.fx.italic=(italic() || eff.italic());
    effects_.fx.isSmall=(isSmall() || eff.isSmall());
    effects_.fx.strike=(strikeOut() || eff.strikeOut());
    effects_.fx.superscript=(superscript() || eff.superscript());
    effects_.fx.subscript=(subscript() || eff.subscript());
    effects_.fx.underline=std::max(underline(), eff.underline());
    return *this;            
}
Esempio n. 5
0
 #ifndef HTML_ICON
   #define HTML_ICON(a) QIcon(a)
 #endif
#endif

struct html_editor::action_type
html_editor::m_action_definitions[] = {
#define QN QT_TR_NOOP
#define NA QWebPage::NoWebAction

  // {name, shortcut, icon, WebAction
  {QN("Bold"), QN("Ctrl+B"), "icon-bold.png", SLOT(bold()), NA }
  ,{QN("Italic"), QN("Ctrl+I"), "icon-italic.png", SLOT(italic()), NA }
  ,{QN("Underline"), QN("Ctrl+U"), "icon-underline.png", SLOT(underline()), NA }
  ,{QN("Strike through"), QN("Ctrl+S"), "icon-strikethrough.png", SLOT(strikethrough()) , NA}
  ,{QN("Superscript"), NULL, "icon-superscript.png", SLOT(superscript()), NA }
  ,{QN("Subscript"), NULL, "icon-subscript.png", SLOT(subscript()), NA }

  // separator before 6
  ,{QN("Set foreground color"), NULL, "icon-foreground-color.png", SLOT(foreground_color()), NA }
  ,{QN("Set background color"), NULL, "icon-background-color.png", SLOT(background_color()), NA }
  ,{QN("Insert image"), NULL, "icon-image.png", SLOT(insert_image()), NA }
  ,{QN("Insert link"), NULL, "icon-link.png", SLOT(insert_link()), NA }
  ,{QN("Insert horizontal rule"), NULL, "icon-hr.png", SLOT(insert_hr()), NA }
  ,{QN("Insert unordered list"), NULL, "icon-bullet-list.png", SLOT(insert_unordered_list()), NA }
  ,{QN("Insert ordered list"), NULL, "icon-ordered-list.png", SLOT(insert_ordered_list()), NA }
  ,{QN("Remove format"), NULL, "icon-eraser.png", SLOT(remove_format()), NA }
  ,{QN("Cut"), NULL, "icon-cut.png", NULL, QWebPage::Cut }
  ,{QN("Copy"), NULL, "icon-copy.png", NULL, QWebPage::Copy }
  ,{QN("Paste"), NULL, "icon-paste.png", NULL, QWebPage::Paste }
  ,{QN("Undo"), QN("Ctrl+Z"), "icon-undo.png", NULL, QWebPage::Undo }