From e4b2778d60acbe7aff650f64b5d05f5716f861c4 Mon Sep 17 00:00:00 2001 From: Stuart Sears Date: Fri, 23 Feb 2024 12:44:31 +0000 Subject: [PATCH 1/3] Add support for Singers' notes (in <>) --- ukedown/patterns.py | 3 +++ ukedown/udn.py | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/ukedown/patterns.py b/ukedown/patterns.py index b2b0e80..278eea3 100644 --- a/ukedown/patterns.py +++ b/ukedown/patterns.py @@ -45,3 +45,6 @@ # pattern to pickup and "boldify" repetitions REPEATS = r"(x\d+)" + +# Singers' instructions/notes now in angled brackets +SINGER = r"<([^<]+)>" diff --git a/ukedown/udn.py b/ukedown/udn.py index 010fe41..2cbac51 100644 --- a/ukedown/udn.py +++ b/ukedown/udn.py @@ -98,6 +98,13 @@ def handleMatch(self, m, data): el.text = m.group(1) return el, m.start(0), m.end(0) +class SingerProcessor(InlineProcessor): + def handleMatch(self, m, data): + el = etree.Element("span") + el.set("class", "singer") + el.text = m.group(1) + return el, m.start(0), m.end(0) + class RepeatsProcessor(InlineProcessor): def handleMatch(self, m, data): @@ -263,6 +270,7 @@ def __init__(self, **kwargs): "inline_element": ["span", "HTML element for inline items"], "chord_pattern": [patterns.CHORD, "regex matching chords"], "vox_pattern": [patterns.VOX, "regex matching backing vocals"], + "singer_pattern": [patterns.SINGER, "regex matching singers' notes"], "notes_pattern": [ patterns.NOTES, "regex matching notes/instructions", @@ -304,6 +312,10 @@ def extendMarkdown(self, md): VoxProcessor(self.getConfig("vox_pattern"), md), "vox", 177 ) + md.inlinePatterns.register( + SingerProcessor(self.getConfig("singer_pattern"), md), "singer", 177 + ) + md.inlinePatterns.register( NotesProcessor(self.getConfig("notes_pattern"), md), "notes", 176 ) From 2301d1dc3709d08f9dec840f46f2b5c349222cd8 Mon Sep 17 00:00:00 2001 From: Stuart Sears Date: Fri, 23 Feb 2024 13:17:45 +0000 Subject: [PATCH 2/3] Linting of test patterns --- tests/test_patterns.py | 67 +++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/tests/test_patterns.py b/tests/test_patterns.py index c02b541..01e2751 100644 --- a/tests/test_patterns.py +++ b/tests/test_patterns.py @@ -7,16 +7,18 @@ def pytest_generate_tests(metafunc: pytest.Metafunc): metafunc.parametrize( - 'case', - getattr(metafunc.cls, metafunc.function.__name__.replace('test_', ''), []), - scope='class' + "case", + getattr(metafunc.cls, metafunc.function.__name__.replace("test_", ""), []), + scope="class", ) class Base: @property def pattern(self) -> re.Pattern: - return re.compile(getattr(patterns, self.__class__.__name__.replace('Test', '').upper())) + return re.compile( + getattr(patterns, self.__class__.__name__.replace("Test", "").upper()) + ) def test_matches(self, case: str): assert self.pattern.match(case) @@ -27,73 +29,76 @@ def test_failures(self, case: str): class TestChord(Base): matches = [ - '(C)', - '(C#)', - '(Cb)', - '(Dm)', + "(C)", + "(C#)", + "(Cb)", + "(Dm)", ] failures = [ - '(H)', + "(H)", ] class TestHyphens(Base): matches = [ - '-', - '- ', - ' -', - ' - ', - '—', + "-", + "- ", + " -", + " - ", + "—", ] failures = [ - '_', + "_", ] class TestVox(Base): matches = [ - '(I can mash potato)', - '(I can (Bb)mash po(C)tato)', + "(I can mash potato)", + "(I can (Bb)mash po(C)tato)", + """(G) I'll be (C)there for (D)you (when the rain starts to +(G)Pour) I'll be (C)there for (D)you (like I've been there +Be(G)fore) I'll be (C)there for (D)you ('Cause you're there for me (F)too)""", ] class TestNotes(Base): matches = [ - '{repeat x2}', - '{demented choir noises}', + "{repeat x2}", + "{demented choir noises}", ] class TestBox(Base): matches = [ - '| {repeat x2}', + "| {repeat x2}", # New paragraph within box? - '| |', + "| |", ] failures = [ # TODO: These should (probably) not fail? # https://github.com/birdcolour/ukulele-wednesdays/issues/24 - '| (D) (D) (D) (F) | (D) (D) (D) (F)', - '| (C) (C) (A7sus4) (A7sus4) | (G) (G) (F) (F)', - '| (D) (D) (D) (F) | (D) (D) (D) (F) |', - '| (C) (C) (A7sus4) (A7sus4) | (G) (G) (F) (F) |', + "| (D) (D) (D) (F) | (D) (D) (D) (F)", + "| (C) (C) (A7sus4) (A7sus4) | (G) (G) (F) (F)", + "| (D) (D) (D) (F) | (D) (D) (D) (F) |", + "| (C) (C) (A7sus4) (A7sus4) | (G) (G) (F) (F) |", # https://github.com/birdcolour/ukulele-wednesdays/issues/25 - '|', - '| ', + "|", + "| ", ] class TestHeader(Base): matches = [ - '[chorus]', - '[bridge]', + "[chorus]", + "[bridge]", ] class TestRepeats(Base): matches = [ - 'x2', + "x2", ] failures = [ - 'x 3', + "x 3", ] From 99c31275daf50a113f56b06b5b63c118ebb46ad1 Mon Sep 17 00:00:00 2001 From: Stuart Sears Date: Fri, 23 Feb 2024 13:19:17 +0000 Subject: [PATCH 3/3] Add test case for singers' notes --- tests/test_patterns.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_patterns.py b/tests/test_patterns.py index 01e2751..2030bfd 100644 --- a/tests/test_patterns.py +++ b/tests/test_patterns.py @@ -87,6 +87,12 @@ class TestBox(Base): "| ", ] +class TestSinger(Base): + matches = [ + "", + "", + ] + class TestHeader(Base): matches = [