UNPKG

chordsong

Version:

ChordSong is a simple text format for the notation of lyrics with guitar chords, and an application that renders them to portable HTML pages.

36 lines 1.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); const path_1 = require("path"); const Renderer_1 = require("./Renderer"); function chordsong(text, renderMode = 'chordName', theme = 'default', html = true) { const renderer = new Renderer_1.Renderer(text, renderMode); const themeDir = (0, path_1.join)(__dirname, '..', 'themes', theme); const themeHtml = (0, fs_1.readFileSync)((0, path_1.join)(themeDir, 'index.html'), 'utf-8'); const cssFiles = (0, fs_1.readdirSync)(themeDir); const themeCss = cssFiles.map(cssFile => (0, fs_1.readFileSync)((0, path_1.join)(themeDir, cssFile), 'utf-8')).join('\n'); let title = renderer.title; const artist = renderer.artist; if (title !== '' && artist !== '') { title = `${artist} - ${title}`; } if (title === '') title = 'Chordsong'; const content = renderer.render(); if (html) { const chordsong = themeHtml .replace('{{TITLE}}', `${title}`) .replace('{{CHORDSONG}}', content) .replace('{{CSS}}', `<style type="text/css">\n${themeCss}</style>`); return chordsong; } else { return { title, content, css: themeCss }; } } exports.default = chordsong; //# sourceMappingURL=index.js.map