+ // emphasis or code span can start after new-line or space only
+ // and of cause after another emphasis markup
+ //TODO this condition looks ugly
+ if(i == c ||
+ iswspace(*(i - 1)) ||
+ ((iswspace(*(i - 1)) || *(i - 1) == L'*' || *(i - 1) == L'_') &&
+ ((i - 1) == c || iswspace(*(i - 2)))) ||
+ *i == L'\\') {
+
+ // url in pandoc style
+ if ((*i == L'[' && wcschr(i, L']')) ||
+ (*i == L'!' && *(i + 1) == L'[' && wcschr(i, L']'))) {
+
+ if (*i == L'!') i++;
+
+ if (wcschr(i, L']')[1] == L'(' && wcschr(i, L')')) {
+ i++;
+
+ // turn higlighting and underlining on
+ if (colors)
+ wattron(window, COLOR_PAIR(CP_BLUE));
+ wattron(window, A_UNDERLINE);
+
+ start_link_name = i;
+
+ // print the content of the label
+ // the label is printed as is
+ do {
+ waddnwstr(window, i, 1);
+ i++;
+ } while (*i != L']');
+
+ length_link_name = i - 1 - start_link_name;
+
+ i++;
+ i++;
+
+ start_url = i;
+
+ while (*i != L')') i++;
+
+ url_num = url_add(start_link_name, length_link_name, start_url, i - start_url, 0, 0);
+
+ wprintw(window, " [%d]", url_num);
+
+ // turn highlighting and underlining off
+ wattroff(window, A_UNDERLINE);
+ wattron(window, COLOR_PAIR(CP_WHITE));
+
+ } else {
+ wprintw(window, "[");
+ }
+
+ } else switch(*i) {
+ // enable highlight
+ case L'*':
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_RED));
+ break;
+ // enable underline
+ case L'_':
+ wattron(window, A_UNDERLINE);
+ break;
+ // enable inline code
+ case L'`':
+ if(colors)
+ wattron(window, COLOR_PAIR(CP_BLACK));
+ break;
+ // do nothing for backslashes
+ }
+
+ // push special char to stack
+ (stack->push)(stack, *i);
+
+ } else {
+ waddnwstr(window, i, 1);
+ }