<file_sep># ChordPro2HTML
 

## Basic Usage
convert chordpro lyrics into HTML-based songsheets.

## Syntax for writing songsheets

Example: [C]Twinkle, twinkle [F]little [C]star.
Translates to:
C                F      C
Twinkle, twinkle little star.

```python
from chordpro2html import Parser as p

p.to_html("""[C]Twinkle, twinkle [F]little [C]star.
           [F]How I [C]wonder [G7]what you [C]are.
           [C]Up [F]above the [C]world so [G7]high,
           [C]Like a [F]diamond [C]in the [G7]sky.
           [C]Twinkle, twinkle [F]little [C]star.
           [F]How I [C]wonder [G7]what you [C]are.""")
>>> HTML

```

## Limitations

Currently only the chord notation is supported when importing ChordPro text. It is advisable to remove any other directives before processing with ChordPro2HTML.

## Planned

- export as HTML file
- export as PDF file

## Motivation

I'm planning on creating a public website where users can submit their own songsheets and add various translations. Why? Because no good website exists for songsheets for J-POP/K-POP songs that support smooth transition between hiragana, kanji, romaji and hangui. PowerChord2HTML is the base parser for needed for that.<file_sep>TWINKLE = """[C]Twinkle, twinkle [F]little [C]star.
[F]How I [C]wonder [G7]what you [C]are.
[C]Up [F]above the [C]world so [G7]high,
[C]Like a [F]diamond [C]in the [G7]sky.
[C]Twinkle, twinkle [F]little [C]star.
[F]How I [C]wonder [G7]what you [C]are.
"""

LEAVES = """The falling [Gm7 C7]leaves   
Drift by the [Fmaj7 Bbmaj7]window   
The autumn [Em7b5 A7]leaves  
Of red and [Dm7 Dm6]gold
 
I see your [Gm7 C7]lips   
The summer [Fmaj7 Bbmaj7]kisses   
The sunburned [Em7b5 A7]hands  
I used to [Dm7 Dm6]hold
 
Since you [Em7b5]went [A7]away  
The days grow [Dm7 Dm6]long  
And soon I'll [Gm7 C7]hear   
Old winter's [Fmaj7 Bbmaj7]song   
But I [Em7b5]miss you most of [A7]all my [Dm7]darling
When [Em7b5]autumn [A7]leaves
Start to [Dm7]fall
"""

TENSHI = """
shiroi [Ab]hane ga hora [Bb]mieru desho?
[Gm]anata wo mitsu[Cm]mete'ru me [Ab]mo
amai koe mo yasashii te [Bb]mo [Eb Eb Eb Eb]

kimi ga [Ab]ai de [Gm]nayamu [Fm]koto ga aru [Eb]nara
[Ab]Pinchi [Gm]sain [Fm]dashite [Bb]matte mite [Eb]yo
 
koi wa [Ab]DOKI DOKI [Bb]suru kedo
ai ga [Gm]LOVE LOVE [Cm]suru nara
motto [Ab]GAN GAN [Bb]ikou yo
kitto [Gm]CHANSU wa [Cm]aru kara
ai [Ab]no tenshi [Bb]wa hohoende'ru [Eb Eb Eb Eb]yo

hon no sukoshi yuuki dashitara
anata wa kawareru hazu yo
jishin motte ganbatte yo
tsurai koto datte norikoete
anata ni wa dekiru hazu yo
hitori ja nai no yo

hito to aishiaeru koto ga dekitara
sore wa kitto tsuyoku nareru koto yo

koi ni UKI UKI shite'ru ne?
HATO RUN RUN shite'ru yo
anata KIRA KIRA shite kita
kare ni ATAKKU shiyou yo
ai no tenshi mo mimamotte'ru yo

kimi ga ai de nayamu koto ga aru nara
Pinchi sain dashite matte mite yo

koi wa DOKI DOKI suru kedo
ai ga LOVE LOVE suru nara
motto GAN GAN ikou yo
kitto CHANSU wa aru kara
ai no tenshi wa hohoende'ru yo
"""<file_sep>class Parser:
    def __init__(self):
        pass

    def to_html(self, input):
        # TODO: handle songs that start with lyrics but no chords (e. g. "I love you. do you love me to?[Am7]")
        lines = input.splitlines()
        result = ''
        for line in lines:
            n = 2
            tokens = line.split('[')
            pairs = []
            for token in tokens:
                temp = token.split(']')
                pairs.append(tuple(temp))
            print(pairs[1:])
            html = ''
            html += '<ruby>'
            for pair in pairs[1:]:
                html += f'<ruby  style="margin-right: 4px;">{pair[1][:1]}<rt>{pair[0]}</rt>{pair[1][1:]}</ruby>'
            html += '<br>'
            result += (html)
        print(result)
        return result
# <ruby>FIRST CHARACTER<rt>CHORD</rt>REST OF TOKEN

if __name__ == "__main__":
    parser = Parser()
    parser.to_html('[G7]hello [C]world. [G7]hello [C]world.')<file_sep>from flask import Flask
import sys
sys.path.append('../chordpro2html')
from chordpro2html import Parser
from songs import TWINKLE, LEAVES, TENSHI

p    = Parser()
song = TWINKLE

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return p.to_html(LEAVES) + p.to_html(TWINKLE) + p.to_html(TENSHI)

if __name__ == '__main__':
    app.run(debug=True)<file_sep>from setuptools import setup

with open('README.md', 'r') as file:
    long_description = file.read()

setup(name='ChordPro2HTML',
      version='0.1.0',
      description='Add chords to lyrics and export an HTML document out of it!',
      url='https://github.com/Zenahr/ChordPro2HTML',
      author='<NAME>',
      author_email='<EMAIL>',
      license='MIT',
      packages=['chordpro2html'],
      keywords=['chordpro',
                'lyrics',
                'chords',
                'music'
      ],
      python_requires='>=3.8.6',
      py_modules=["quicksample"],
      install_requires=[],
      classifiers=[
            'Development Status :: 3 - Alpha',
            'Intended Audience :: Developers',
            'Natural Language :: English',
            'License :: OSI Approved :: MIT License',
            'Operating System :: OS Independent',
            'Programming Language :: Python :: 3.8',
            'Topic :: Text Processing',
            'Topic :: Utilities'

      ],
      long_description=long_description,
      long_description_content_type='text/markdown',
      zip_safe=False)
<file_sep>import sys
sys.path.append('../chordpro2html')
from chordpro2html import Parser
from songs import TWINKLE

p = Parser()

html = p.to_html()

print(html)