+void adjust_line_length(line_t *line) {
+ int l = 0;
+ const static char *special = "\\*_`"; // list of interpreted chars
+ const char *c = &line->text->text[line->offset];
+ cstack_t *stack = cstack_init();
+
+ // for each char in line
+ for(; *c; c++) {
+ // if char is in special char list
+ if(strchr(special, *c)) {
+
+ // closing special char (or second backslash)
+ if((stack->top)(stack, *c)) {
+ if(*c == '\\') l++;
+ (stack->pop)(stack);
+
+ // treat special as regular char
+ } else if((stack->top)(stack, '\\')) {
+ l++;
+ (stack->pop)(stack);
+
+ // opening special char
+ } else {
+ (stack->push)(stack, *c);
+ }
+
+ } else {
+ // remove backslash from stack
+ if((stack->top)(stack, '\\'))
+ (stack->pop)(stack);
+ l++;
+ }
+ }
+
+ if(CHECK_BIT(line->bits, IS_H1_ATX))
+ l -= 2;
+ if(CHECK_BIT(line->bits, IS_H2_ATX))
+ l -= 3;
+
+ line->length = l;
+
+ (stack->delete)(stack);
+}
+
+bool is_utf8(char ch) {
+ return (ch & 0x80) != 0x00;