Commit 30df421b authored by Matt Mascarenhas's avatar Matt Mascarenhas

hmml_to_html.c: Category styling

Also upgrade hmml.a for lower-cased markers
parent 769c79b0
No preview for this file type
#if 0
ctime -begin ${0%.*}.ctm
clang -g -Wall -Wno-unused-variable -fsanitize=address -std=c99 $0 -o ${0%.*} hmml.a
#gcc -g -Wall -Wno-unused-variable -fsanitize=address -std=c99 $0 -o ${0%.*} hmml.a
gcc -g -Wall -fsanitize=address -std=c99 $0 -o ${0%.*} hmml.a
ctime -end ${0%.*}.ctm
exit
#endif
......@@ -28,6 +29,8 @@ typedef struct
char *RefTitle;
} ref_info;
#define ArrayCount(A) sizeof(A)/sizeof(*(A))
void
ClaimBuffer(char *MemoryArena, int *ClaimedMemory, buffer *Buffer, int Size)
{
......@@ -158,6 +161,48 @@ StringToColourHash(char *String)
return Result / i;
}
int
StringLength(char *String)
{
int i = 0;
while(String[i])
{
++i;
}
return i;
}
char *
SanitisePunctuation(char *String)
{
char *Ptr = String;
while(*Ptr)
{
if(*Ptr == ' ')
{
*Ptr = '_';
}
if((*Ptr < '0' || *Ptr > '9') &&
(*Ptr < 'a' || *Ptr > 'z') &&
(*Ptr < 'A' || *Ptr > 'Z'))
{
*Ptr = '-';
}
++Ptr;
}
return String;
}
char *CategoryMedium[] =
{
"blackboard",
"Blackboard",
"research",
"Research",
"run",
"Run",
};
int
main(int ArgC, char **Args)
{
......@@ -224,6 +269,7 @@ main(int ArgC, char **Args)
for(int AnnotationIndex = 0; AnnotationIndex < HMML.annotation_count; ++AnnotationIndex)
{
bool HasCategory = FALSE;
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationHeader, 256);
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, 128);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, 1024 * 4);
......@@ -235,7 +281,6 @@ TimecodeToSeconds(HMML.annotations[AnnotationIndex].time));
CopyStringToBuffer(&AnnotationClass,
" class=\"marker");
#if 0
if(HMML.annotations[AnnotationIndex].author)
{
CopyStringToBuffer(&AnnotationClass, " authored");
......@@ -244,18 +289,102 @@ TimecodeToSeconds(HMML.annotations[AnnotationIndex].time));
StringToColourHash(HMML.annotations[AnnotationIndex].author),
HMML.annotations[AnnotationIndex].author);
}
#endif
InPtr = HMML.annotations[AnnotationIndex].text;
//TODO(matt): Replace this CopyStringToBuffer() with real stuff!
CopyStringToBuffer(&Text, HMML.annotations[AnnotationIndex].text);
int MarkerIndex = 0, RefIndex = 0;
while(*InPtr)
{
if(MarkerIndex < HMML.annotations[AnnotationIndex].marker_count &&
InPtr - HMML.annotations[AnnotationIndex].text == HMML.annotations[AnnotationIndex].markers[MarkerIndex].offset)
{
char *Readable = HMML.annotations[AnnotationIndex].markers[MarkerIndex].parameter
? HMML.annotations[AnnotationIndex].markers[MarkerIndex].parameter
: HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker;
if(HMML.annotations[AnnotationIndex].markers[MarkerIndex].type == HMML_MEMBER)
{
CopyStringToBuffer(&Text,
"<a href=\"https://handmade.network/m/%s\" target=\"blank\" style=\"color: #%X; text-decoration: none\">%s</a>",
HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker,
StringToColourHash(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker),
Readable);
InPtr += StringLength(Readable);
}
else if(HMML.annotations[AnnotationIndex].markers[MarkerIndex].type == HMML_PROJECT)
{
CopyStringToBuffer(&Text,
"<a href=\"https://%s.handmade.network/\" target=\"blank\" style=\"color: #%X; text-decoration: none\">%s</a>",
HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker,
StringToColourHash(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker),
Readable);
InPtr += StringLength(Readable);
}
else if(HMML.annotations[AnnotationIndex].markers[MarkerIndex].type == HMML_CATEGORY)
{
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
{
if(!StringsDiffer(CategoryMedium[i], HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker))
{
CopyStringToBuffer(&AnnotationClass, " %s", SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker));
goto NextCategory;
}
}
if(!HasCategory)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, 256);
CopyStringToBuffer(&Category, "<span class=\"categories\"><div class=\"category %s\"></div>",
SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker));
HasCategory = TRUE;
}
else
{
CopyStringToBuffer(&Category, "<div class=\"category %s\"></div>",
SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker));
}
CopyStringToBuffer(&AnnotationClass, " cat_%s",
SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker));
}
NextCategory: ++MarkerIndex;
}
if(RefIndex < HMML.annotations[AnnotationIndex].reference_count &&
InPtr - HMML.annotations[AnnotationIndex].text == HMML.annotations[AnnotationIndex].references[RefIndex].offset)
{
++RefIndex;
}
if(*InPtr)
{
*Text.Ptr++ = *InPtr++;
}
}
while(MarkerIndex < HMML.annotations[AnnotationIndex].marker_count)
{
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
{
if(!StringsDiffer(CategoryMedium[i], HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker))
{
CopyStringToBuffer(&AnnotationClass, " %s", SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker));
goto NextCategoryInNode;
}
}
if(!HasCategory)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, 256);
CopyStringToBuffer(&Category, "<span class=\"categories\"><div class=\"category %s\"></div>",
SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker));
HasCategory = TRUE;
}
else
{
CopyStringToBuffer(&Category, "<div class=\"category %s\"></div>",
SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker));
}
CopyStringToBuffer(&AnnotationClass, " cat_%s",
SanitisePunctuation(HMML.annotations[AnnotationIndex].markers[MarkerIndex].marker));
NextCategoryInNode: ++MarkerIndex;
}
CopyStringToBuffer(&AnnotationClass, "\"");
CopyBuffer(&AnnotationClass, &AnnotationHeader);
......@@ -268,6 +397,14 @@ HMML.annotations[AnnotationIndex].author);
" <div class=\"content\"><span class=\"timecode\">%s</span>",
HMML.annotations[AnnotationIndex].time);
if(HasCategory)
{
CopyStringToBuffer(&Category, "</span>");
CopyBuffer(&Category, &Text);
}
*Text.Ptr = '\0';
CopyBuffer(&Text, &Annotation);
CopyStringToBuffer(&Annotation, "</div>\n"
......@@ -309,7 +446,7 @@ HMML.annotations[AnnotationIndex].time);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, 1024 * 512);
CopyStringToBuffer(&Master,
"<!DOCTYPE html>\n"
"<html>\n"
" <head>\n"
" <meta charset=\"UTF-8\">\n"
"\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment