Skip to content

Commit

Permalink
improve markdown generator (#40)
Browse files Browse the repository at this point in the history
* docs: improve generate sheet doc

* Include markdown files as source for --all

* Add basic stylesheet and support html tags

* Improve the markdown test song (include table)

* Improve the markdown test song (include pre)
  • Loading branch information
laenzlinger authored May 20, 2024
1 parent 298ffba commit 121c73a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
5 changes: 4 additions & 1 deletion cmd/generate_sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ var sheetCmd = &cobra.Command{
Long: `Generates a cheat sheet for a Gig or for all songs.
Currently supports pdf sheets.
The pdf sheets are optionally generated for odf files.
The pdf sheets are (optionally) generated for odf or markdown files.
If a .pdf file already exists, but is older than the source (.odf or .md) file,
the .pdf file is reg-enerated and overwritten.
`,
Run: func(cmd *cobra.Command, args []string) {
band := config.NewBand()
Expand Down
5 changes: 4 additions & 1 deletion docs/setlist_generate_sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Generate a cheat sheet
Generates a cheat sheet for a Gig or for all songs.

Currently supports pdf sheets.
The pdf sheets are optionally generated for odf files.
The pdf sheets are (optionally) generated for odf or markdown files.

If a .pdf file already exists, but is older than the source (.odf or .md) file,
the .pdf file is reg-enerated and overwritten.


```
Expand Down
21 changes: 17 additions & 4 deletions internal/html/template/songsheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@
<meta charset='utf-8'>
<style>
@page {
margin: 0;
padding: 0;
margin: 0;
padding: 0;
}
html, body {
font-size: 20px;
font-family: Tahoma, Geneva, sans-serif;
font-size: 28px;
font-family: Tahoma, Geneva, sans-serif;
}
table, th, td {
border: 1px solid;
border-color: DarkGray;
border-collapse: collapse;
}
table {
width: 100%;
}
h1 {
font-size: 14px;
text-align: right;
}

article {
}
</style>
Expand Down
14 changes: 10 additions & 4 deletions internal/sheet/sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/renderer/html"
)

type Sheet struct {
Expand All @@ -41,7 +42,7 @@ func AllForBand(band config.Band) error {
for _, file := range files {
extraw := filepath.Ext(file.Name())
ext := strings.ToLower(extraw)
if !file.IsDir() && (ext == ".pdf" || ext == ".odt") {
if !file.IsDir() && (ext == ".pdf" || ext == ".odt" || ext == ".md") {
songs[strings.TrimSuffix(filepath.Base(file.Name()), ext)] = true
}
}
Expand Down Expand Up @@ -204,9 +205,14 @@ func (s *Sheet) generateFromMarkdown() error {
return fmt.Errorf("failed to read Gig: %w", err)
}

md := goldmark.New(goldmark.WithExtensions(
extension.GFM,
))
md := goldmark.New(
goldmark.WithExtensions(
extension.GFM,
),
goldmark.WithRendererOptions(
html.WithUnsafe(),
),
)

var buf bytes.Buffer
if err = md.Convert(content, &buf); err != nil {
Expand Down
21 changes: 19 additions & 2 deletions test/Repertoire/Band/Songs/Her Song.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Her Song
```
Lyrics of Her Song

Lyrics of Her Song
Are great to sing along

<table>
<tr>
<td>
You can sing<br>
a tabular song
</td>
<td>
That greatly helps<br>
to use all the real estate
</td>
</tr>
</table>

```
Amin7 D7 Gmaj7
Add some Chords to the Lyrics
```

0 comments on commit 121c73a

Please sign in to comment.