From 9ca5a1b99c71526208810e4757b2b37c21177b37 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard <jonathan@jdbernard.com> Date: Wed, 19 Jul 2023 13:23:59 -0500 Subject: [PATCH] Support additional text on the same lines as section headings. --- src/pco_chordspkg/ast.nim | 18 +++++++++++------- src/pco_chordspkg/html.nim | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/pco_chordspkg/ast.nim b/src/pco_chordspkg/ast.nim index 880d63e..149ceb2 100644 --- a/src/pco_chordspkg/ast.nim +++ b/src/pco_chordspkg/ast.nim @@ -35,6 +35,7 @@ type case kind: ChordChartNodeKind of ccnkSection: sectionName*: string + remainingSectionLine*: Option[string] sectionContents*: seq[ChordChartNode] of ccnkLine: line*: seq[ChordChartNode] @@ -267,12 +268,13 @@ proc parseMetadata(ctx: var ParserContext): ChordChartMetadata = const KNOWN_SECTION_NAMES = [ "chorus", "verse", "bridge", "breakdown", "vamp", "intstrumental", - "interlude", "intro", "outtro", "ending", "end", "tag" + "interlude", "intro", "outtro", "ending", "end", "tag", "prechorus", + "pre-chorus", "pre chorus" ] let SECTION_LINE_PAT = re( - "^((" & # case insensitive - "((?i)" & KNOWN_SECTION_NAMES.join("|") & ")" & # known names + "^((" & "((?i)" & # case insensitive + KNOWN_SECTION_NAMES.join("|") & ")" & # known names "|[[:upper:]]{3,}" & # all upper-case words ") ?\\d*)" & # numeric suffix (Verse 2) @@ -422,12 +424,14 @@ proc parseBody(ctx: var ParserContext): seq[ChordChartNode] = let captures = m.get.captures.toSeq ctx.curSection = ChordChartNode( kind: ccnkSection, - sectionName: if captures[0].isSome: captures[0].get.strip - else: raise ctx.makeError("unknown error parsing section header: " & line), + sectionName: + if captures[0].isSome: captures[0].get.strip + else: raise ctx.makeError("unknown error parsing section header: " & line), + remainingSectionLine: + if captures[3].isSome: some(captures[3].get.strip) + else: none[string](), sectionContents: @[]) result.add(ctx.curSection) - if captures[3].isSome: - ctx.curSection.sectionContents &= ctx.parseLineParts(captures[3].get) continue else: diff --git a/src/pco_chordspkg/html.nim b/src/pco_chordspkg/html.nim index b4aee10..6f0af24 100644 --- a/src/pco_chordspkg/html.nim +++ b/src/pco_chordspkg/html.nim @@ -40,6 +40,13 @@ h3 { text-decoration: underline; } +h3 .section-text { + font-style: italic; + font-size: 1em; + font-weight: normal; + margin: 0 0.5em; +} + .line { display: flex; flex-direction: row; @@ -108,7 +115,13 @@ proc toHtml(ctx: var FormatContext, node: ChordChartNode, indent: string): strin of ccnkSection: ctx.currentSection = node result &= indent & "<section>\p" & - indent & " " & "<h3>" & node.sectionName & "</h3>\p" + indent & " " & "<h3>" & node.sectionName + + if ctx.currentSection.remainingSectionLine.isSome: + result &= "<span class='section-text'>" & + ctx.currentSection.remainingSectionLine.get & "</span>" + + result &= "</h3>\p" var contents = newSeq[string]() for contentNode in node.sectionContents: