Support one- and two-column layouts. Transposing keys doesn't start a new section.

This commit is contained in:
2025-04-26 11:40:48 -05:00
parent a57aed0715
commit 73bdb97881
4 changed files with 89 additions and 64 deletions

View File

@@ -22,10 +22,8 @@ const DEFAULT_STYLESHEET* = """
html { font-family: sans-serif; }
.page-contents {
column-width: 336px;
column-width: 3.5in;
}
.one-column .page-contents { column-count: 1; }
.two-column .page-contents { column-count: 2; }
.column-break { margin-bottom: auto; }
@@ -49,6 +47,8 @@ h3 .section-text {
margin: 0 0.5em;
}
.artist { font-style: italic; }
.line {
display: flex;
flex-direction: row;
@@ -73,10 +73,17 @@ h3 .section-text {
white-space: nowrap;
}
.chord > * {
display: inline-block;
height: 1.2em;
}
.chord .flavor {
font-variant-position: super;
}
.note { margin-right: 1em; }
.song-order h3 {
font-style: italic;
font-weight: normal;
@@ -90,10 +97,6 @@ h3 .section-text {
@media screen {
body { margin: 1em; }
}
@media print {
.page-contents { column-count: 2; }
}
</style>
"""
@@ -110,10 +113,8 @@ html {
font-size: 1.5em;
}
.page-contents {
column-width: 336px;
column-width: 3.5in;
}
.one-column .page-contents { column-count: 1; }
.two-column .page-contents { column-count: 2; }
.column-break { margin-bottom: auto; }
@@ -137,6 +138,8 @@ h3 .section-text {
margin: 0 0.5em;
}
.artist { font-style: italic; }
.line {
display: flex;
flex-direction: row;
@@ -165,10 +168,17 @@ h3 .section-text {
margin-right: 0.5em;
}
.chord > * {
display: inline-block;
height: 1.2em;
}
.chord .flavor {
font-variant-position: super;
}
.note { margin-right: 1em; }
.song-order h3 {
font-style: italic;
font-weight: normal;
@@ -182,10 +192,6 @@ h3 .section-text {
@media screen {
body { margin: 1em; }
}
@media print {
.page-contents { column-count: 2; }
}
</style>
"""
@@ -310,10 +316,7 @@ proc toHtml(ctx: var FormatContext, node: ChordChartNode, indent: string): strin
of ccnkTransposeKey:
ctx.currentKey = ctx.currentKey + node.transposeSteps
let headingVal = indent & "<h4 class=note>Key Change: " & $ctx.currentKey & "</h4>"
if ctx.currentSection.kind == ccnkNone: result &= headingVal
else:
result &= "</section><section>" & headingVal & "</section><section>"
result &= indent & "<h4 class=note>Key Change: " & $ctx.currentKey & "</h4>"
of ccnkRedefineKey:
let oldKey = ctx.currentKey
@@ -361,7 +364,12 @@ proc toHtml*(
elif fileExists(sc): result &= "<script>\p" & readFile(sc) & "\p</script>"
else: warn "cannot read script file '" & sc & "'"
result &= " </head>\p <body>"
result &= " </head>\p"
if cc.metadata.contains("columns") and cc.metadata["columns"] == "1":
result &= " <body class='one-column'>"
else:
result &= " <body class='two-column'>"
var indent = " "
@@ -378,6 +386,9 @@ proc toHtml*(
result &= indent & "<h2>" & metadataPieces.join(" | ") & "</h2>\p"
if cc.metadata.contains("artist"):
result &= indent & "<div class=artist>" & cc.metadata["artist"] & "</div>\p"
result &= "<div class=page-contents>"
result &= join(cc.nodes --> map(ctx.toHtml(it, indent & " ")), "\p")