Revise Markdown handling of character entities.
Ideally I'd like the ABC character entities to survive Markdown and then get converted. But because they start with '\', they don't. So I have no alternative but to convert them to HTML entities, which Markdown then converts to UTF-8.
This commit is contained in:
parent
f267b21c21
commit
52e3d1cde8
14
abcfield.py
14
abcfield.py
|
@ -178,15 +178,17 @@ def convertMarkdown(t, latex):
|
||||||
|
|
||||||
# Implement a custom Markdown shorthand for referencing ABC files.
|
# Implement a custom Markdown shorthand for referencing ABC files.
|
||||||
# <foo.abc> will expand to ['title of foo'](foo.abc).
|
# <foo.abc> will expand to ['title of foo'](foo.abc).
|
||||||
def expandCustomMarkdown(t, dir, latex):
|
def expandCustomMarkdown(t, dir):
|
||||||
# Given a match to (foo.abc), return a markdown link to the tune with the
|
# Given a match to (foo.abc), return a markdown link to the tune with the
|
||||||
# title (and subtitle, if present) of the tune as the text of the link.
|
# title (and subtitle, if present) of the tune as the text of the link.
|
||||||
|
# Because we're going through Markdown, character entities must be
|
||||||
|
# HTML. Pandoc will convert them to UTF-8.
|
||||||
def getTitleLink(m):
|
def getTitleLink(m):
|
||||||
fname = m.group(1) + ".abc"
|
fname = m.group(1) + ".abc"
|
||||||
path = pathlib.Path(dir, fname)
|
path = pathlib.Path(dir, fname)
|
||||||
with path.open() as f:
|
with path.open() as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
return "[" + getFullTitle(lines, dir, latex=latex) + "](" + fname + ")"
|
return "[" + getFullTitle(lines, dir) + "](" + fname + ")"
|
||||||
return re.sub(r'<(.*?).abc>', getTitleLink, t)
|
return re.sub(r'<(.*?).abc>', getTitleLink, t)
|
||||||
|
|
||||||
# Return the raw text for a given field. Optionally the nth field is taken,
|
# Return the raw text for a given field. Optionally the nth field is taken,
|
||||||
|
@ -223,13 +225,15 @@ def getFieldText(lines, field, n = 1, starts = None):
|
||||||
def getFieldDisplayText(lines, dir, field, n = 1, starts = None, latex = False):
|
def getFieldDisplayText(lines, dir, field, n = 1, starts = None, latex = False):
|
||||||
res = getFieldText(lines, field, n, starts)
|
res = getFieldText(lines, field, n, starts)
|
||||||
if res:
|
if res:
|
||||||
res = convertAccents(res, latex)
|
# Fields that go through Markdown must have HTML entities.
|
||||||
|
mdfield = field.upper() in ['H', 'N'];
|
||||||
|
res = convertAccents(res, False if mdfield else latex)
|
||||||
if field.upper() == "T":
|
if field.upper() == "T":
|
||||||
res = convertTitleToDisplay(res)
|
res = convertTitleToDisplay(res)
|
||||||
elif field.upper() == "K":
|
elif field.upper() == "K":
|
||||||
res = convertKeyToDisplay(res)
|
res = convertKeyToDisplay(res)
|
||||||
elif field.upper() in ["H", "N"]:
|
elif mdfield:
|
||||||
res = convertMarkdown(expandCustomMarkdown(res, dir, latex), latex)
|
res = convertMarkdown(expandCustomMarkdown(res, dir), latex)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
# Return full title (title + [" (" + subtitle + ")"] if subtitle exists).
|
# Return full title (title + [" (" + subtitle + ")"] if subtitle exists).
|
||||||
|
|
Loading…
Reference in New Issue