repo: geminiclient action: commit revision: path_from: revision_from: 1fc63013358c09dcb0964e1ee2eaf1ae4cfbfdd9: path_to: revision_to:
commit 1fc63013358c09dcb0964e1ee2eaf1ae4cfbfdd9 Author: epochDate: Sat Dec 4 10:55:50 2021 +0000 combined heading printing code to a single block. now outputs an ID in headings so you can link directly to them with fragment IDs. diff --git a/gemini2html.c b/gemini2html.c
--- a/gemini2html.c +++ b/gemini2html.c @@ -1,20 +1,24 @@ #include#include +#include #define LINE_ENDING "\r\n" int main(int argc,char *argv[]) { char line[65536];//65535+null + int h=0; char pre=0; char list=0; char *first; char *second; + char *t,*s; + int ln=0; if(argc >= 2) {//if there's an argument, we output the header too. printf(" %s %s",argv[1],LINE_ENDING); } - while(fgets(line,sizeof(line)-1,stdin)) { + for(ln=0;fgets(line,sizeof(line)-1,stdin);ln++) { //strip line endings ofc. if(first=strchr(line,'\r')) *first=0; if(first=strchr(line,'\n')) *first=0; @@ -30,19 +34,23 @@ int main(int argc,char *argv[]) { printf("%s",LINE_ENDING); list=0; } - if(!strncmp(line,"# ",2)) { - first=line+2; - printf("%s
%s",first,LINE_ENDING); - continue; - } - if(!strncmp(line,"## ",3)) { - first=line+3; - printf("%s
%s",first,LINE_ENDING); - continue; - } - if(!strncmp(line,"### ",4)) { - first=line+4; - printf("%s
%s",first,LINE_ENDING); + h=0; + if(!strncmp(line,"# ",2)) h=1; + if(!strncmp(line,"## ",3)) h=2; + if(!strncmp(line,"### ",4)) h=3; + if(h) { + first=""; + s=""; + t=strdup(line+h+1); + if(strchr(t,' ')) { + s=" "; + first=strchr(t,' '); + *first=0; + first++; + } + if(!ln) printf("%s %s",h,line+h+1,h,LINE_ENDING); + else printf("%s%s%s %s",h,t,t,t,s,first,h,LINE_ENDING); + free(t); continue; } if(!strncmp(line,"```",3)) {
-----END OF PAGE-----