forked from CryHavoc/dottes
Convert Markdown in N and H fields. Fix up .abc links.
This commit is contained in:
parent
169520d254
commit
d9d4e3c157
20
abcfield.py
20
abcfield.py
|
@ -18,6 +18,8 @@
|
|||
#
|
||||
|
||||
import optparse
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
accentedletters = {
|
||||
|
@ -153,6 +155,20 @@ def convertKeyToDisplay(t):
|
|||
mode = mode.strip().lower()
|
||||
return letter + accidental + ' ' + abckeys.get(mode, "Major")
|
||||
|
||||
# Convert input string from Markdown to HTML or LaTeX. Fix up link
|
||||
# targets so any 'foo.abc' target links to the tune with that name.
|
||||
def convertMarkdown(t, latex):
|
||||
if latex:
|
||||
target = "--to=latex"
|
||||
else:
|
||||
target = "--to=html"
|
||||
res = subprocess.check_output(['pandoc', '--from=markdown', target], input=t, universal_newlines=True)
|
||||
if latex:
|
||||
res = re.sub(r'\\href{(.*).abc}', r'\\hyperlink{\1}', res)
|
||||
else:
|
||||
res = re.sub(r'href="(.*).abc"', r'href="\1.html"', res)
|
||||
return res
|
||||
|
||||
# Return the raw text for a given field. Optionally the nth field is taken,
|
||||
# or the field data must start with a designated string to be recognised.
|
||||
def getFieldText(inf, field, n = 1, starts = None):
|
||||
|
@ -187,11 +203,13 @@ def getFieldText(inf, field, n = 1, starts = None):
|
|||
def getFieldDisplayText(inf, field, n = 1, starts = None, latex = False):
|
||||
res = getFieldText(inf, field, n, starts)
|
||||
if res:
|
||||
res = convertAccents(res, latex)
|
||||
if field.upper() == "T":
|
||||
res = convertTitleToDisplay(res)
|
||||
elif field.upper() == "K":
|
||||
res = convertKeyToDisplay(res)
|
||||
res = convertAccents(res, latex)
|
||||
elif field.upper() in ["H", "N"]:
|
||||
res = convertMarkdown(res, latex)
|
||||
return res
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue