HTML¶
Chant objects (chant21.Chant
) objects can be exported to HTML. The music
will be shown in the Volpiano typeface, with
the lyrics aligned to it; the idea is borrowed from the Cantus website. HTML exports are used when showing chants in
Jupyter notebooks, but it can also be used to generate standalone HTML files for
chants. The module uses Jinja to
generate HTML from templates.
You can also export chant objects using their method chant21.Chant.toHTML()
:
>>> html1 = myChant.toHTML()
>>> html2 = toWidget(myChant)
>>> html1 == html2
True
>>> myChant.toHTML(filepath='mychant.html')
>>> toFile(myChant, filepath='mychant.html')
Or in a Jupyter notebook:
>>> chant.show('html')
-
chant21.html.
toWidget
(chant, showOptions=False, showSections=False, showWords=False, showSyllables=False, showNeumes=False, showMetadata=False, showMisalignments=True)¶ Export a chant to an HTML widget: a snippet displayed in Jupyter notebooks.
The structure of the chant can be highlighted visually using several flags:
showSections
,showWords
,showSyllables
andshowNeumes
. WhenshowOptions
is on, several checkboxes are shown that allow you to highlight these interactively.Parameters: - chant (chant21.Chant) – A chant object
- showOptions (bool, optional) – If True, several checkboxes are shown that allow you to highlight the structure of the chant interactively. Defaults to True.
- showSections (bool, optional) – Highlight sections? Defaults to False.
- showWords (bool, optional) – Highlight words? Defaults to False.
- showSyllables (bool, optional) – Highlight syllables? Defaults to False.
- showNeumes (bool, optional) – Highlight neumes?. Defaults to False.
- showMetadata (bool, optional) – Show a table with all metadata fields? Defaults to False.
- showMisalignments (bool, optional) – Highlight misaligned text and music?
Returns: a HTML string
Return type: str
-
chant21.html.
toFile
(chant, filepath=None, showOptions=True, showSections=False, showWords=False, showSyllables=False, showNeumes=False, showMetadata=False, showMisalignments=True)¶ Export a Chant to an HTML file.
Parameters: - chant (chant21.Chant) – A chant object
- filepath (string, optional) – If a filepath is passed, the html is written to that file, otherwise the HTML is returned. Defaults to None.
- **kwargs – you can highlight sections, words, syllables and
neumes by passing optional arguments; see
toWidget()
.
Returns: The HTML string is returned if no
filepath
is specified.Return type: str