hmml_to_html.c: Introduce BuildQuote() [#20]

Also move some structural styling out to style.css
This commit is contained in:
Matt Mascarenhas 2017-04-23 03:47:42 +01:00
parent d34ad0a03a
commit b61fc1196c
4 changed files with 163 additions and 33 deletions

View File

@ -38,6 +38,12 @@ typedef struct
int IdentifierCount; int IdentifierCount;
} ref_info; } ref_info;
typedef struct
{
char Date[32];
char Text[512];
} quote_info;
#define ArrayCount(A) sizeof(A)/sizeof(*(A)) #define ArrayCount(A) sizeof(A)/sizeof(*(A))
void void
@ -337,6 +343,94 @@ BuildCategories(buffer *AnnotationClass, buffer *Category, int *MarkerIndex, boo
return; return;
} }
#define QUOTE_DIR "/home/matt/git/GitHub/insofaras/25fc16d58a297a486334"
int
StringToInt(char *String)
{
int Result = 0;
while(*String)
{
Result = Result * 10 + (*String - '0');
++String;
}
return Result;
}
int
BuildQuote(quote_info *Info, char *Speaker, int ID)
{
char Path[255] = {0};
sprintf(Path, "%s/#%s", QUOTE_DIR, Speaker);
FILE *File;
if(!(File = fopen(Path, "r")))
{
perror("hmml_to_html");
return 1;
}
fseek(File, 0, SEEK_END);
int Length = ftell(File);
fseek(File, 0, SEEK_SET);
char *Buffer;
if(!(Buffer = malloc(Length)))
{
perror("hmml_to_html");
}
fread(Buffer, Length, 1, File);
fclose(File);
char *InPtr = Buffer;
while(InPtr - Buffer < Length)
{
char InID[4] = {0};
char *OutPtr = InID;
while(*InPtr != ',')
{
*OutPtr++ = *InPtr++;
}
*OutPtr = '\0';
if(StringToInt(InID) == ID)
{
InPtr += 2;
OutPtr = Info->Date;
while(*InPtr != '"')
{
*OutPtr++ = *InPtr++;
}
*OutPtr = '\0';
InPtr += 3;
OutPtr = Info->Text;
while(*InPtr != '\n')
{
if(*InPtr == '\\')
{
++InPtr;
}
*OutPtr++ = *InPtr++;
}
*--OutPtr = '\0';
free(Buffer);
return 0;
}
else
{
while(*InPtr != '\n')
{
++InPtr;
}
++InPtr;
}
}
free(Buffer);
return 1;
}
void void
GenerateTopicColours(buffer *Colour, char *Topic) GenerateTopicColours(buffer *Colour, char *Topic)
{ {
@ -477,6 +571,8 @@ main(int ArgC, char **Args)
bool HasQuote = FALSE; bool HasQuote = FALSE;
bool HasReference = FALSE; bool HasReference = FALSE;
quote_info QuoteInfo = { 0 };
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationHeader, 512); ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationHeader, 512);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, 256); ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, 256);
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, 256); ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, 256);
@ -687,11 +783,25 @@ AppendedIdentifier:
HasQuote = TRUE; HasQuote = TRUE;
if(BuildQuote(&QuoteInfo, HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member, Anno->quote.id) == 1)
{
fprintf(stderr, "%s:%d: Quote #%s %d not found! Consider pulling the latest quotes\n",
Args[FileIndex],
Anno->line,
HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member,
Anno->quote.id);
hmml_free(&HMML);
free(MemoryArena);
return 1;
}
CopyStringToBuffer(&QuoteMenu, CopyStringToBuffer(&QuoteMenu,
" <span data-id=\"&#%d;\" class=\"ref\">\n" " <span data-id=\"&#%d;\" class=\"ref\">\n"
" <span class=\"ref_content\">\n" " <span class=\"ref_content\">\n"
" <div class=\"source\">#%d • %s</div>\n" " <div class=\"source\">Quote %d</div>\n"
" <div class=\"ref_title\">%s</div>\n" " <div class=\"ref_title\">%s</div>\n"
" <div class=\"quote_byline\">&mdash;%s, %s</div>\n"
" </span>\n" " </span>\n"
" <div class=\"ref_indices\">\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" " <span data-timestamp=\"%d\" class=\"timecode\"><span class=\"ref_index\">[&#%d;]</span><span class=\"time\">%s</span></span>\n"
@ -699,14 +809,15 @@ AppendedIdentifier:
" </span>\n", " </span>\n",
QuoteIdentifier, QuoteIdentifier,
Anno->quote.id, Anno->quote.id,
"Quote date", QuoteInfo.Text,
"Quote text", HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member,
QuoteInfo.Date,
TimecodeToSeconds(Anno->time), TimecodeToSeconds(Anno->time),
QuoteIdentifier, QuoteIdentifier,
Anno->time); Anno->time);
if(!Anno->text[0]) if(!Anno->text[0])
{ {
CopyStringToBuffer(&Text, "&#8220;Quote text&#8221;"); CopyStringToBuffer(&Text, "&#8220;%s&#8221;", QuoteInfo.Text);
} }
CopyStringToBuffer(&Text, "<sup>&#%d;</sup>", QuoteIdentifier); CopyStringToBuffer(&Text, "<sup>&#%d;</sup>", QuoteIdentifier);
++QuoteIdentifier; ++QuoteIdentifier;

View File

@ -7,7 +7,7 @@
.title.obbg { .title.obbg {
background-color: #EEE; background-color: #EEE;
color: #000; color: #000;
border-bottom: 1px solid #372F46; border-color: #372F46;
} }
.title.obbg .refs_container { .title.obbg .refs_container {
@ -25,12 +25,11 @@
.title.obbg .refs_container .refs { .title.obbg .refs_container .refs {
background-color: #EEE; background-color: #EEE;
border: 2px solid #372F46; border-color: #372F46;
border-top: none;
} }
.title.obbg .refs_container > .refs .ref { .title.obbg .refs_container > .refs .ref {
border-bottom: 1px solid #372F46; border-color: #372F46;
color: #000000; color: #000000;
} }
@ -40,17 +39,21 @@
} }
.title.obbg .refs_container > .refs .ref:hover { .title.obbg .refs_container > .refs .ref:hover {
background-color: #FFF8E7; background-color: #DDD;
} }
.title.obbg .refs_container > .refs .ref.current:hover { .title.obbg .refs_container > .refs .ref.current:hover {
background-color: rgba(55, 46, 65, 0.7); background-color: #68557E;
} }
.title.obbg .refs_container > .refs .ref .source { .title.obbg .refs_container > .refs .ref .source {
color: #888; color: #888;
} }
.title.obbg .refs_container > .refs .ref .quote_byline {
color: #888;
}
.title.obbg .refs_container > .refs .ref.current .source { .title.obbg .refs_container > .refs .ref.current .source {
color: #FFF8E7; color: #FFF8E7;
} }
@ -61,7 +64,7 @@
} }
.markers_container.obbg > .marker { .markers_container.obbg > .marker {
border-bottom: 1px solid #888; border-color: #888;
} }
.markers_container.obbg > .marker:hover > .content { .markers_container.obbg > .marker:hover > .content {

View File

@ -1,7 +1,7 @@
.title.riscy { .title.riscy {
background-color: #EEE; background-color: #EEE;
color: #000000; color: #000000;
border-bottom: 1px solid rgba(246, 178, 26, 0.8); border-color: rgba(246, 178, 26, 0.8);
} }
.title.riscy .refs_container { .title.riscy .refs_container {
@ -19,12 +19,11 @@
.title.riscy .refs_container .refs { .title.riscy .refs_container .refs {
background-color: #EEE; background-color: #EEE;
border: 2px solid rgba(246, 178, 26, 0.8); border-color: rgba(246, 178, 26, 0.8);
border-top: none;
} }
.title.riscy .refs_container > .refs .ref { .title.riscy .refs_container > .refs .ref {
border-bottom: 1px solid rgba(246, 178, 26, 0.8); border-color: rgba(246, 178, 26, 0.8);
color: #000000; color: #000000;
} }
@ -45,6 +44,10 @@
color: #888; color: #888;
} }
.title.riscy .refs_container > .refs .ref .quote_byline {
color: #888;
}
.title.riscy .refs_container > .refs .ref.current .source { .title.riscy .refs_container > .refs .ref.current .source {
color: #FFF8E7; color: #FFF8E7;
} }
@ -55,7 +58,7 @@
} }
.markers_container.riscy > .marker { .markers_container.riscy > .marker {
border-bottom: 1px solid rgba(246, 178, 26, 0.8); border-color: rgba(246, 178, 26, 0.8);
} }
.markers_container.riscy > .marker:hover > .content { .markers_container.riscy > .marker:hover > .content {

View File

@ -3,6 +3,7 @@
.title { .title {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
border-bottom: 1px solid;
} }
.title > * { .title > * {
@ -26,6 +27,8 @@
} }
.title .refs_container .refs { .title .refs_container .refs {
border: 2px solid;
border-top:none;
position: absolute; position: absolute;
top: 100%; top: 100%;
right: 0; right: 0;
@ -39,6 +42,7 @@
} }
.title .refs_container > .refs .ref { .title .refs_container > .refs .ref {
border-bottom: 1px solid;
padding: 10px; padding: 10px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -56,6 +60,31 @@
padding: 0; padding: 0;
} }
.title .refs_container > .refs .ref .timecode:hover .time {
text-decoration: underline;
}
.title .refs_container > .refs .ref .ref_content {
margin-bottom: 8px;
width: 100%;
}
.title .refs_container > .refs .ref .source {
font-size: 10px;
line-height: 8px;
}
.title .refs_container > .refs .ref .ref_title {
font-style: oblique;
}
.title .refs_container > .refs .ref .quote_byline {
font-size: 10px;
line-height: 8px;
text-align: right;
width: 100%;
}
.title .refs_container > .refs .ref .ref_indices { .title .refs_container > .refs .ref .ref_indices {
text-align: center; text-align: center;
} }
@ -74,23 +103,6 @@
margin: 0 4px; margin: 0 4px;
} }
.title .refs_container > .refs .ref .timecode:hover .time {
text-decoration: underline;
}
.title .refs_container > .refs .ref .ref_content {
width: 100%;
}
.title .refs_container > .refs .ref .source {
font-size: 10px;
line-height: 8px;
}
.title .refs_container > .refs .ref .ref_title {
font-style: oblique;
}
.title .refs_container > .refs .ref .timecode .ref_index { .title .refs_container > .refs .ref .timecode .ref_index {
margin-right: 4px; margin-right: 4px;
} }
@ -111,6 +123,7 @@
} }
.markers_container > .marker { .markers_container > .marker {
border-bottom: 1px solid;
position: relative; position: relative;
cursor: pointer; cursor: pointer;
} }