Annotation-System/hmml_to_html/hmml_to_html.c

827 lines
26 KiB
C
Raw Normal View History

#if 0
ctime -begin ${0%.*}.ctm
#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
2017-03-23 00:34:59 +00:00
typedef unsigned int bool;
#define TRUE 1
#define FALSE 0
2017-03-23 00:34:59 +00:00
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2017-03-23 00:34:59 +00:00
#include "hmmlib.h"
typedef struct
{
char *Location;
char *Ptr;
int Size;
} buffer;
typedef struct
{
char Timecode[8];
int Identifier;
} identifier;
typedef struct
{
char ID[1024];
char RefTitle[512];
char URL[372];
char Source[128];
identifier Identifier[12];
int IdentifierCount;
} ref_info;
#define ArrayCount(A) sizeof(A)/sizeof(*(A))
void
ClaimBuffer(char *MemoryArena, int *ClaimedMemory, buffer *Buffer, int Size)
{
Buffer->Location = MemoryArena + *ClaimedMemory;
Buffer->Size = Size;
*ClaimedMemory += Buffer->Size;
Buffer->Ptr = Buffer->Location;
}
#if 0
//TODO(matt): Rewrite me
ref_info
ParseRef(HMML_Reference RefInput)
{
ref_info Info;
if(RefInput.author)
{
Info.Source = RefInput.author;
Info.RefTitle = RefInput.title;
return Info;
}
else if(RefInput.page)
{
Info.Source = RefInput.site;
Info.RefTitle = RefInput.page;
return Info;
}
else
{
Info.Source = "";
Info.RefTitle = RefInput.site;
return Info;
}
}
#endif
// TODO(matt): MakeReference()
int
TimecodeToSeconds(char *Timecode)
{
int HMS[3] = { 0, 0, 0 }; // 0 == Seconds; 1 == Minutes; 2 == Hours
int Colons = 0;
while(*Timecode)
{
if((*Timecode < '0' || *Timecode > '9') && *Timecode != ':') { return FALSE; }
if(*Timecode == ':')
{
++Colons;
if(Colons > 2) { return FALSE; }
for(int i = 0; i < Colons; ++i)
{
HMS[Colons - i] = HMS[Colons - (i + 1)];
}
HMS[0] = 0;
}
else
{
HMS[0] = HMS[0] * 10 + *Timecode - '0';
}
++Timecode;
}
if(HMS[0] > 59 || HMS[1] > 59 || Timecode[-1] == ':') { return FALSE; }
return HMS[2] * 60 * 60 + HMS[1] * 60 + HMS[0];
}
void
CopyBuffer(buffer *Dest, buffer *Src)
{
Src->Ptr = Src->Location;
while(*Src->Ptr)
{
*Dest->Ptr++ = *Src->Ptr++;
}
}
void
CopyString(char Dest[], char *Src)
{
int i = 0;
while(*Src)
{
Dest[i] = *Src++;
++i;
}
Dest[i] = '\0';
}
__attribute__ ((format (printf, 2, 3)))
void
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(buffer *Dest, char *Format, ...)
{
2017-03-23 00:34:59 +00:00
va_list Args;
va_start(Args, Format);
int Length = vsprintf(Dest->Ptr, Format, Args);
va_end(Args);
Dest->Ptr += Length;
}
int
StringsDiffer(char *A, char *B)
{
while(*A && *B && *A == *B)
{
++A, ++B;
}
return *A - *B;
}
2017-03-18 02:04:13 +00:00
int
CharToColour(char Char)
{
if(Char >= 'a' && Char <= 'z')
{
return (((float)Char - 'a') / ('z' - 'a') * 0xFFFFFF);
}
else if(Char >= 'A' && Char <= 'Z')
{
return (((float)Char - 'A') / ('Z' - 'A') * 0xFFFFFF);
}
else if(Char >= '0' && Char <= '9')
{
return (((float)Char - '0') / ('9' - '0') * 0xFFFFFF);
}
else
{
return 0x777777;
}
}
int
StringToColourHash(char *String)
{
int Result = 0;
int i;
for(i = 0; String[i]; ++i)
{
Result += CharToColour(String[i]);
}
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",
"owl",
"rant",
"research",
"run",
};
void
BuildCategories(buffer *AnnotationClass, buffer *Category, int *MarkerIndex, bool *HasCategory, char *Marker)
{
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
{
if(!StringsDiffer(CategoryMedium[i], Marker))
{
CopyStringToBuffer(AnnotationClass, " %s", SanitisePunctuation(Marker));
++*MarkerIndex;
return;
}
}
if(*HasCategory == FALSE)
{
CopyStringToBuffer(Category, "<span class=\"categories\">");
*HasCategory = TRUE;
}
CopyStringToBuffer(Category, "<div class=\"category %s\"></div>",
SanitisePunctuation(Marker));
CopyStringToBuffer(AnnotationClass, " cat_%s",
SanitisePunctuation(Marker));
++*MarkerIndex;
return;
}
void
GenerateTopicColours(char *Topic)
{
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
{
if(!StringsDiffer(Topic, CategoryMedium[i]))
{
return;
}
}
FILE *TopicsFile;
char *TopicsBuffer;
char *TopicsPtr;
int PersistentLength = 89;
if((TopicsFile = fopen("topics.css", "r")))
{
fseek(TopicsFile, 0, SEEK_END);
int TopicsLength = ftell(TopicsFile);
fseek(TopicsFile, 0, SEEK_SET);
if(!(TopicsBuffer = malloc(TopicsLength + StringLength(Topic) + PersistentLength)))
{
perror("hmml_to_html");
return;
}
fread(TopicsBuffer, TopicsLength, 1, TopicsFile);
fclose(TopicsFile);
TopicsPtr = TopicsBuffer;
while(TopicsPtr - TopicsBuffer < TopicsLength)
{
TopicsPtr += 39;
if(!strncmp(SanitisePunctuation(Topic), TopicsPtr, StringLength(Topic)))
{
free(TopicsBuffer);
return;
}
while(TopicsPtr - TopicsBuffer < TopicsLength && *TopicsPtr != '\n')
{
++TopicsPtr;
}
++TopicsPtr;
}
}
else
{
if(!(TopicsBuffer = malloc(StringLength(Topic) + PersistentLength)))
{
perror("hmml_to_html");
return;
}
TopicsPtr = TopicsBuffer;
}
int PrintLength = sprintf(TopicsPtr, ".marker .content .categories .category.%s { border-color: #%X; background: #%X; }\n",
SanitisePunctuation(Topic), StringToColourHash(Topic), StringToColourHash(Topic));
TopicsPtr += PrintLength;
TopicsFile = fopen("topics.css", "w");
fwrite(TopicsBuffer, TopicsPtr - TopicsBuffer, 1, TopicsFile);
fclose(TopicsFile);
free(TopicsBuffer);
}
int
main(int ArgC, char **Args)
{
if(ArgC < 2)
{
fprintf(stderr, "Usage: %s filename(s)\n", Args[0]);
return 1;
}
// NOTE(matt): Init MemoryArena
char *MemoryArena;
int ArenaSize = 1024 * 1024;
if(!(MemoryArena = calloc(ArenaSize, 1)))
{
perror(Args[0]);
return 1;
}
int ClaimedMemory = 0;
// NOTE(matt): Setup buffers and ptrs
char *InPtr;
buffer Title;
buffer QuoteMenu;
buffer ReferenceMenu;
buffer Player;
buffer Annotation;
buffer AnnotationHeader;
buffer AnnotationClass;
buffer AnnotationData;
buffer Text;
buffer Category;
buffer Master;
for(int FileIndex = 1; FileIndex < ArgC; ++FileIndex)
{
FILE *InFile;
if(!(InFile = fopen(Args[FileIndex], "r")))
{
perror(Args[0]);
free(MemoryArena);
return 1;
}
HMML_Output HMML = hmml_parse_file(InFile);
fclose(InFile);
if(HMML.well_formed)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &Title, 1024 * 16);
ref_info ReferencesArray[200];
memset(ReferencesArray, 0, sizeof(ReferencesArray));
ClaimBuffer(MemoryArena, &ClaimedMemory, &Player, 1024 * 256);
bool HasQuoteMenu = FALSE;
bool HasReferenceMenu = FALSE;
int QuoteIdentifier = 0x3b1;
int RefIdentifier = 1;
int UniqueRefs = 0;
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&Title,
" <div class=\"title\">\n"
" <span class=\"episode_name\">%s</span>\n", HMML.metadata.title);
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&Player,
" <div class=\"player_container\">\n"
" <div class=\"video_container\" data-videoId=\"%s\"></div>\n"
" <div class=\"markers_container\">\n", HMML.metadata.id);
for(int AnnotationIndex = 0; AnnotationIndex < HMML.annotation_count; ++AnnotationIndex)
{
HMML_Annotation *Anno = HMML.annotations + AnnotationIndex;
bool HasCategory = FALSE;
bool HasQuote = FALSE;
bool HasReference = FALSE;
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationHeader, 512);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, 256);
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, 256);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Text, 1024 * 4);
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&AnnotationHeader,
" <div data-timestamp=\"%d\"",
TimecodeToSeconds(Anno->time));
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&AnnotationClass,
" class=\"marker");
2017-03-23 00:34:59 +00:00
if(Anno->author)
2017-03-23 00:34:59 +00:00
{
CopyStringToBuffer(&AnnotationClass, " authored");
CopyStringToBuffer(&Text,
"<span class=\"author\" style=\"color: #%X;\">%s</span> ",
StringToColourHash(Anno->author),
Anno->author);
2017-03-23 00:34:59 +00:00
}
InPtr = Anno->text;
int MarkerIndex = 0, RefIndex = 0;
while(*InPtr || RefIndex < Anno->reference_count)
{
if(MarkerIndex < Anno->marker_count &&
InPtr - Anno->text == Anno->markers[MarkerIndex].offset)
{
char *Readable = Anno->markers[MarkerIndex].parameter
? Anno->markers[MarkerIndex].parameter
: Anno->markers[MarkerIndex].marker;
if(Anno->markers[MarkerIndex].type == HMML_MEMBER)
{
CopyStringToBuffer(&Text,
"<a href=\"https://handmade.network/m/%s\" target=\"blank\" style=\"color: #%X; text-decoration: none\">%.*s</a>",
Anno->markers[MarkerIndex].marker,
StringToColourHash(Anno->markers[MarkerIndex].marker),
StringLength(Readable), InPtr);
InPtr += StringLength(Readable);
++MarkerIndex;
}
else if(Anno->markers[MarkerIndex].type == HMML_PROJECT)
{
CopyStringToBuffer(&Text,
"<a href=\"https://%s.handmade.network/\" target=\"blank\" style=\"color: #%X; text-decoration: none\">%s</a>",
Anno->markers[MarkerIndex].marker,
StringToColourHash(Anno->markers[MarkerIndex].marker),
Readable);
InPtr += StringLength(Readable);
++MarkerIndex;
}
else if(Anno->markers[MarkerIndex].type == HMML_CATEGORY)
{
GenerateTopicColours(Anno->markers[MarkerIndex].marker);
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, Anno->markers[MarkerIndex].marker);
}
}
if(RefIndex < Anno->reference_count &&
InPtr - Anno->text == Anno->references[RefIndex].offset)
{
HMML_Reference *CurrentRef = Anno->references + RefIndex;
if(!HasReferenceMenu)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &ReferenceMenu, 1024 * 16);
CopyStringToBuffer(&ReferenceMenu,
" <div class=\"refs_container\">\n"
" <span>References &#9660;</span>\n"
" <div class=\"mouse_catcher\"></div>\n"
" <div class=\"refs\">\n");
CopyString(ReferencesArray[RefIdentifier - 1].ID, CurrentRef->editor);
CopyString(ReferencesArray[RefIdentifier - 1].RefTitle, "Title");
CopyString(ReferencesArray[RefIdentifier - 1].URL, "http://example.com/");
CopyString(ReferencesArray[RefIdentifier - 1].Source, "Source");
CopyString(ReferencesArray[RefIdentifier - 1].Identifier[ReferencesArray[RefIdentifier - 1].IdentifierCount].Timecode, Anno->time);
ReferencesArray[RefIdentifier - 1].Identifier[ReferencesArray[RefIdentifier - 1].IdentifierCount].Identifier = RefIdentifier;
++ReferencesArray[RefIdentifier - 1].IdentifierCount;
++UniqueRefs;
HasReferenceMenu = TRUE;
}
else
{
for(int i = 0; i < UniqueRefs; ++i)
{
if(!StringsDiffer(CurrentRef->editor, ReferencesArray[i].ID))
{
CopyString(ReferencesArray[i].Identifier[ReferencesArray[i].IdentifierCount].Timecode, Anno->time);
ReferencesArray[i].Identifier[ReferencesArray[i].IdentifierCount].Identifier = RefIdentifier;
++ReferencesArray[i].IdentifierCount;
goto AppendedIdentifier;
}
}
CopyString(ReferencesArray[UniqueRefs].ID, CurrentRef->editor);
CopyString(ReferencesArray[UniqueRefs].RefTitle, "Title");
CopyString(ReferencesArray[UniqueRefs].URL, "http://example.com/");
CopyString(ReferencesArray[UniqueRefs].Source, "Source");
CopyString(ReferencesArray[UniqueRefs].Identifier[ReferencesArray[UniqueRefs].IdentifierCount].Timecode, Anno->time);
ReferencesArray[UniqueRefs].Identifier[ReferencesArray[UniqueRefs].IdentifierCount].Identifier = RefIdentifier;
++ReferencesArray[UniqueRefs].IdentifierCount;
++UniqueRefs;
}
AppendedIdentifier:
if(!HasReference)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, 128);
CopyStringToBuffer(&AnnotationData, " data-ref=\"%s", CurrentRef->editor);
HasReference = TRUE;
}
else
{
CopyStringToBuffer(&AnnotationData, ",%s", CurrentRef->editor);
}
CopyStringToBuffer(&Text, "<sup>%d</sup>", RefIdentifier);
++RefIndex;
++RefIdentifier;
}
if(*InPtr)
{
*Text.Ptr++ = *InPtr++;
}
}
if(Anno->is_quote)
{
if(!HasQuoteMenu)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &QuoteMenu, 1024 * 16);
CopyStringToBuffer(&QuoteMenu,
" <div class=\"refs_container\">\n"
" <span>Quotes &#9660;</span>\n"
" <div class=\"mouse_catcher\"></div>\n"
" <div class=\"refs\">\n");
HasQuoteMenu = TRUE;
}
if(!HasReference)
{
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationData, 32);
CopyStringToBuffer(&AnnotationData, " data-ref=\"&#%d;", QuoteIdentifier);
}
else
{
CopyStringToBuffer(&AnnotationData, ",&#%d;", QuoteIdentifier);
}
HasQuote = TRUE;
CopyStringToBuffer(&QuoteMenu,
" <span data-id=\"&#%d;\" class=\"ref\">\n"
" <span class=\"ref_content\">\n"
" <div class=\"source\">#%d • %s</div>\n"
" <div class=\"ref_title\">%s</div>\n"
" </span>\n"
" <div class=\"ref_indices\">\n"
" <span data-timestamp=\"%d\" class=\"timecode\"><span class=\"ref_index\">[&#%d;]</span><span class=\"time\">%s</span></span>\n"
" </div>\n"
" </span>\n",
QuoteIdentifier,
Anno->quote.id,
"Quote date",
"Quote text",
TimecodeToSeconds(Anno->time),
QuoteIdentifier,
Anno->time);
if(!Anno->text[0])
{
CopyStringToBuffer(&Text, "&#8220;Quote text&#8221;");
}
CopyStringToBuffer(&Text, "<sup>&#%d;</sup>", QuoteIdentifier);
++QuoteIdentifier;
}
while(MarkerIndex < Anno->marker_count)
{
GenerateTopicColours(Anno->markers[MarkerIndex].marker);
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, Anno->markers[MarkerIndex].marker);
}
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&AnnotationClass, "\"");
CopyBuffer(&AnnotationHeader, &AnnotationClass);
if(HasQuote || HasReference)
{
CopyStringToBuffer(&AnnotationData, "\"");
CopyBuffer(&AnnotationHeader, &AnnotationData);
}
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&AnnotationHeader, ">\n");
ClaimBuffer(MemoryArena, &ClaimedMemory, &Annotation, 1024 * 4);
CopyBuffer(&Annotation, &AnnotationHeader);
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&Annotation,
" <div class=\"content\"><span class=\"timecode\">%s</span>",
Anno->time);
if(HasCategory)
{
CopyStringToBuffer(&Category, "</span>");
CopyBuffer(&Text, &Category);
}
*Text.Ptr = '\0';
CopyBuffer(&Annotation, &Text);
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&Annotation, "</div>\n"
" <div class=\"progress faded\">\n"
" <div class=\"content\"><span class=\"timecode\">%s</span>",
Anno->time);
CopyBuffer(&Annotation, &Text);
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&Annotation, "</div>\n"
" </div>\n"
" <div class=\"progress main\">\n"
" <div class=\"content\"><span class=\"timecode\">%s</span>",
Anno->time);
CopyBuffer(&Annotation, &Text);
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&Annotation, "</div>\n"
" </div>\n"
2017-03-23 00:34:59 +00:00
" </div>\n");
CopyBuffer(&Player, &Annotation);
ClaimedMemory -= Text.Size;
ClaimedMemory -= AnnotationHeader.Size;
ClaimedMemory -= Category.Size;
ClaimedMemory -= AnnotationClass.Size;
ClaimedMemory -= Annotation.Size;
}
if(HasQuoteMenu)
{
CopyStringToBuffer(&QuoteMenu,
" </div>\n"
" </div>\n");
CopyBuffer(&Title, &QuoteMenu);
}
if(HasReferenceMenu)
{
for(int i = 0; i < UniqueRefs; ++i)
{
CopyStringToBuffer(&ReferenceMenu,
" <a data-id=\"%s\" href=\"%s\" target=\"_blank\" class=\"ref\">\n"
" <span class=\"ref_content\">\n"
" <div class=\"source\">%s</div>\n"
" <div class=\"ref_title\">%s</div>\n"
" </span>\n"
// TODO(matt): Fill the div class="ref_indices" with <= 3 span
// class="ref_index" and ensure to put these <=3 spans on the same line without
// a space between them
" <div class=\"ref_indices\">\n ",
ReferencesArray[i].ID,
"http://example.com/",
"Source",
"Title");
for(int j = 0; j < ReferencesArray[i].IdentifierCount; ++j)
{
CopyStringToBuffer(&ReferenceMenu,
"<span data-timestamp=\"%d\" class=\"timecode\"><span class=\"ref_index\">[%d]</span><span class=\"time\">%s</span></span>",
TimecodeToSeconds(ReferencesArray[i].Identifier[j].Timecode),
ReferencesArray[i].Identifier[j].Identifier,
ReferencesArray[i].Identifier[j].Timecode);
}
CopyStringToBuffer(&ReferenceMenu,
"\n </div>\n"
" </a>\n");
}
CopyStringToBuffer(&ReferenceMenu,
" </div>\n"
" </div>\n");
CopyBuffer(&Title, &ReferenceMenu);
}
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&Title,
" <span class=\"annotator_container\">Annotator: <span class=\"annotator\">%s</span></span>\n"
" </div>\n", HMML.metadata.annotator);
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&Player,
" </div>\n"
" </div>\n");
//NOTE(matt): Collate the buffers!
ClaimBuffer(MemoryArena, &ClaimedMemory, &Master, 1024 * 512);
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&Master,
"<html>\n"
" <head>\n"
" <meta charset=\"UTF-8\">\n"
"\n"
" <!-- Load the player -->\n"
" <script type=\"text/javascript\" src=\"player.js\"></script>\n"
" <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n"
" <link rel=\"stylesheet\" type=\"text/css\" href=\"topics.css\">\n"
" </head>\n"
" <body>\n");
//NOTE(matt): Here is where we do all our CopyBuffer() calls
CopyBuffer(&Master, &Title);
CopyBuffer(&Master, &Player);
//
2017-03-23 00:34:59 +00:00
CopyStringToBuffer(&Master,
" <script>\n"
" var player = new Player(document.querySelector(\".player_container\"), onRefChanged);\n"
" window.addEventListener(\"resize\", function() { player.updateSize(); });\n"
" document.addEventListener(\"keypress\", function(ev) {\n"
" switch (ev.key) {\n"
" case 'n':\n"
" case 'd':\n"
" case 's': {\n"
" player.jumpToNextMarker();\n"
" } break;\n"
"\n"
" case 'p':\n"
" case 'a':\n"
" case 'w': {\n"
" player.jumpToPrevMarker();\n"
" } break;\n"
" }\n"
"});\n"
"\n"
"var refTimecodes = document.querySelectorAll(\".refs .ref .timecode\");\n"
"for (var i = 0; i < refTimecodes.length; ++i) {\n"
" refTimecodes[i].addEventListener(\"click\", function(ev) {\n"
" if (player) {\n"
" var time = ev.currentTarget.getAttribute(\"data-timestamp\");\n"
" player.setTime(parseInt(time, 10));\n"
" player.play();\n"
" ev.preventDefault();\n"
" ev.stopPropagation();\n"
" return false;\n"
" }\n"
" });\n"
"}\n"
"\n"
"var refSources = document.querySelectorAll(\".refs .ref\");\n"
"for (var i = 0; i < refSources.length; ++i) {\n"
" refSources[i].addEventListener(\"click\", function(ev) {\n"
" if (player) {\n"
" player.pause();\n"
" }\n"
" });\n"
"}\n"
"\n"
"function onRefChanged(ref) {\n"
" var sourceMenus = document.querySelectorAll(\".refs_container\");\n"
" for (var MenuIndex = 0; MenuIndex < sourceMenus.length; ++MenuIndex)\n"
" {\n"
" var SetMenu = 0;\n"
" if (ref !== undefined && ref !== null) {\n"
" var refElements = sourceMenus[MenuIndex].querySelectorAll(\".refs .ref\");\n"
" var refs = ref.split(\",\");\n"
"\n"
" for (var i = 0; i < refElements.length; ++i) {\n"
" if (refs.includes(refElements[i].getAttribute(\"data-id\"))) {\n"
" refElements[i].classList.add(\"current\");\n"
" SetMenu = 1;\n"
" } else {\n"
" refElements[i].classList.remove(\"current\");\n"
" }\n"
" }\n"
" if(SetMenu) {\n"
" sourceMenus[MenuIndex].classList.add(\"current\");\n"
" } else {\n"
" sourceMenus[MenuIndex].classList.remove(\"current\");\n"
" }\n"
"\n"
" } else {\n"
" sourceMenus[MenuIndex].classList.remove(\"current\");\n"
" var refs = sourceMenus[MenuIndex].querySelectorAll(\".refs .ref\");\n"
" for (var i = 0; i < refs.length; ++i) {\n"
" refs[i].classList.remove(\"current\");\n"
" }\n"
" }\n"
" }\n"
"}\n"
" </script>\n"
" </body>\n"
"</html>\n");
FILE *OutFile;
if(!(OutFile = fopen("out.html", "w")))
{
perror(Args[0]);
return 1;
}
fwrite(Master.Location, Master.Ptr - Master.Location, 1, OutFile);
fclose(OutFile);
ClaimedMemory -= AnnotationData.Size;
ClaimedMemory -= QuoteMenu.Size;
ClaimedMemory -= ReferenceMenu.Size;
ClaimedMemory -= Title.Size;
ClaimedMemory -= Master.Size;
}
else
{
fprintf(stderr, "%s:%d: %s\n", Args[FileIndex], HMML.error.line, HMML.error.message);
}
hmml_free(&HMML);
}
free(MemoryArena);
}