martijnversluis / ChordSheetJS

A JavaScript library for parsing and formatting ChordPro chord sheets
GNU General Public License v2.0
297 stars 49 forks source link

HtmlDivFormatter behaves differently than HtmlTableFormatter #1189

Open beltonk opened 1 month ago

beltonk commented 1 month ago

I recently switched from HtmlTableFormatter to HtmlDivFormatter, and seems there are some logical different, e.g. sot in HtmlDivFormatter renders .lyrics but not .literals? I'm not sure about other difference, just feel some nuances.

beltonk commented 1 month ago

seems comment directives not rendered as well.

martijnversluis commented 1 month ago

Hey @beltonk. What chord sheet and ChordSheetJS are you using?

I ran a small test:

import { ChordProParser, HtmlDivFormatter } from "https://esm.sh/chordsheetjs";

const chordProTestSong = `
{sot}
One
Two
Three
{eot}`;

const song = new ChordProParser().parse(chordProTestSong);
const output = new HtmlDivFormatter().format(song);
console.log(output);

The output is:

<div class='chord-sheet'>
  <div class='paragraph tab'>
    <div class='row'>
      <h3 class='label'>null</h3>
      <div class='literal'>
        One<br>
        Two<br>
        Three
      </div>
    </div>
  </div>
</div>

So it renders a .literal. I do spot a bug when rendering a null label.

beltonk commented 1 month ago

My fault... I assumed comment & literal are under columns, and mistakenly did some sanitization. Let me test again...

beltonk commented 1 month ago

I can reproduce the issue, whenever there is any other {c: }, {soc}, {sov} directives in the ChordPro, the tab will become lyrics lines instead of literal, no matter where these tags are.

For example,

const chordProTestSong = `
{sot}
One
Two
Three
{eot}
{c:Verse}
`;
const chordProTestSong = `
{c:Intro}
{sot}
One
Two
Three
{eot}
`;
const chordProTestSong = `
{sot}
One
Two
Three
{eot}
{sov}
...
{eov}
`;

Also tested {t:} {st:} has no effect on literal rendering