add codeblock

This commit is contained in:
Nishi 2026-09-16 03:29:42 +09:00
commit fe371ad89c
3 changed files with 36 additions and 1 deletions

View file

@ -35,6 +35,7 @@ int main() {
int i;
strcpy(text, "# Hello world!\nThis is a __test__ text...\n\n`Some monospace here`\n\n~~Removed~~");
strcat(text, "\n```\nint main(){\n printf(\"Hello, world!\\n\");\n}\n```");
for(i = 0; i < 10; i++) {
strcat(text, "\n\n**Lorem ipsum** dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
}

View file

@ -124,6 +124,7 @@ enum MwCHART {
enum MwDOCUMENT_LAYOUT {
MwDOCUMENT_TEXT = 0,
MwDOCUMENT_NEWLINE,
MwDOCUMENT_SPACE,
MwDOCUMENT_HEADER,
MwDOCUMENT_BOLD,
MwDOCUMENT_MONOSPACE,

View file

@ -156,6 +156,14 @@ static int enter_block(MD_BLOCKTYPE type, void* detail, void* userdata) {
arrput(d->layouts, l);
break;
}
case MD_BLOCK_CODE:
{
l.type = MwDOCUMENT_MONOSPACE;
l.integer = 1;
arrput(d->layouts, l);
break;
}
default:
break;
}
@ -187,6 +195,14 @@ static int leave_block(MD_BLOCKTYPE type, void* detail, void* userdata) {
arrput(d->layouts, l);
break;
}
case MD_BLOCK_CODE:
{
l.type = MwDOCUMENT_MONOSPACE;
l.integer = 0;
arrput(d->layouts, l);
break;
}
default:
break;
}
@ -311,12 +327,24 @@ static int text(MD_TEXTTYPE type, const MD_CHAR* text, MD_SIZE size, void* userd
next = strchr(str, ' ');
if(next != NULL) next[0] = 0;
if(strlen(str) > 0) {
if(strcmp(str, "\n") == 0) {
memset(&l, 0, sizeof(l));
l.type = MwDOCUMENT_NEWLINE;
arrput(d->layouts, l);
} else if(strlen(str) > 0) {
memset(&l, 0, sizeof(l));
l.type = MwDOCUMENT_TEXT;
l.text = MwStringDuplicate(str);
arrput(d->layouts, l);
} else {
memset(&l, 0, sizeof(l));
l.type = MwDOCUMENT_SPACE;
arrput(d->layouts, l);
}
@ -374,6 +402,11 @@ static void layout(MwWidget handle) {
x += t;
break;
}
case MwDOCUMENT_SPACE:
{
x += MwTextWidth(handle, TOPFONT, " ");
break;
}
case MwDOCUMENT_NEWLINE:
{
x = 0;