p->next = NULL;
p->type = type;
+ if(type == MD_BLOCK_H) {
+ MD_BLOCK_H_DETAIL *heading = detail;
+ p->heading = heading->level;
+ }
+
if(!data->doc->content) {
data->doc->content = p;
} else {
}
static int md_leave_block(MD_BLOCKTYPE type, void* detail, void* userdata) {
-
return 0;
}
MDNode *node = md_node_create(data);
node->type = type;
+ if(type == MD_SPAN_A) {
+ MD_SPAN_A_DETAIL *link = detail;
+ if(link && link->href.size > 0) {
+ node->link = cx_strdup_a(data->a, cx_strn(link->href.text, link->href.size));
+ }
+ }
+
return 0;
}
switch(n->type) {
case MD_SPAN_EM: return EDITOR_STYLE_EMPHASIS;
case MD_SPAN_STRONG: return EDITOR_STYLE_STRONG;
+ case MD_SPAN_A: return EDITOR_STYLE_LINK;
}
return NULL;
}
sec.pos = start_pos;
sec.length = buf->pos - start_pos;
sec.style = node_style(n);
+ sec.link = n->link.ptr;
cxListAdd(sections, &sec);
}
}
static const char* paragraph_style(MDPara *p) {
// TODO: implement all styles
switch(p->type) {
- case MD_BLOCK_H: return EDITOR_STYLE_HEADING1;
+ case MD_BLOCK_H: {
+ switch(p->heading) {
+ default: return EDITOR_STYLE_HEADING1;
+ case 2: return EDITOR_STYLE_HEADING2;
+ case 3: return EDITOR_STYLE_HEADING3;
+ case 4: return EDITOR_STYLE_HEADING4;
+ case 5: return EDITOR_STYLE_HEADING5;
+ case 6: return EDITOR_STYLE_HEADING6;
+ }
+ }
default: return EDITOR_STYLE_PARAGRAPH;
}
}
#define EDITOR_STYLE_CODE "code"
#define EDITOR_STYLE_EMPHASIS "emphasis"
#define EDITOR_STYLE_STRONG "strong"
+#define EDITOR_STYLE_LINK "link"
#define MD_MAX_DEPTH 50
MD_BLOCKTYPE type;
MDNode *content;
MDPara *next;
+ int heading;
};
struct MDNode {
int pos;
int length;
const char *style;
+ const char *link;
};
void editor_init(UiText *text);
tag = gtk_text_tag_new(EDITOR_STYLE_STRONG);
g_object_set(tag, "weight", PANGO_WEIGHT_BOLD, NULL);
gtk_text_tag_table_add(table, tag);
+
+ tag = gtk_text_tag_new(EDITOR_STYLE_LINK);
+ g_object_set(tag, "foreground", "blue", NULL);
+ gtk_text_tag_table_add(table, tag);
}
void editor_apply_styles(UiText *text, CxList /* MDDocStyleSection */ *styles) {
GtkTextBuffer *buffer = text->data1;
+ GtkTextTagTable *tagtable = gtk_text_buffer_get_tag_table(buffer);
CxIterator i = cxListIterator(styles);
cx_foreach(MDDocStyleSection*, sec, i) {
if(sec->style) {
gtk_text_buffer_apply_tag_by_name(buffer, sec->style, &begin, &end);
}
+ if(sec->link) {
+ GtkTextTag *linktag = gtk_text_tag_new(NULL);
+ char *link = strdup(sec->link);
+ g_object_set_data(G_OBJECT(linktag), "link", link);
+ // TODO: destroy handler
+ gtk_text_tag_table_add(tagtable, linktag);
+ gtk_text_buffer_apply_tag(buffer, linktag, &begin, &end);
+ }
}
}