Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new LTag aliases: C# and V# for crag climbing routes #1860

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions c2corg_api/markdown/ltag.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def _get_ltag_pattern():
Build the big ugly fat regexp for L# numbering. It's based on named
patterns : (P?<pattern_name>pattern) and decomposed part by part.

C#/V# numbering is for crag routes (climb/voie)

Please have a look on
https://forum.camptocamp.org/t/question-l/207148/69
"""
Expand All @@ -53,7 +55,7 @@ def _get_ltag_pattern():
text_in_the_middle = p("text_in_the_middle", "~")
header = p("header", "=")

typ = p("type", "[LR]")
typ = p("type", "[LRVC]")

text = "(" + header + "|" + text_in_the_middle + "|" + numbering + ")"

Expand All @@ -78,14 +80,15 @@ class LTagNumbering(object):
FORMAT = ('<span class="pitch">'
'<span translate>{type}</span>'
'{text}</span>').format
FORMAT_CLIMB = ('<span class="pitch">{text}</span>').format
FORMAT_UNMATCHED = '<code>{}</code>'.format

def __init__(self, markdown):

self.get_placeholder = markdown.htmlStash.store

# Values for relative patterns
self.value = {"R": 0, "L": 0}
self.value = {"R": 0, "L": 0, "V": 0, "C": 0}

# One way switch
self.supported = True
Expand Down Expand Up @@ -178,7 +181,10 @@ def handle_multipitch(self, match, is_first_cell):

text = "".join((first_offset, label, "-", last_offset, label))

return self.FORMAT(type=typ, text=text)
if typ == "V" or typ == "C":
return self.FORMAT_CLIMB(text=text)
else:
return self.FORMAT(type=typ, text=text)

def handle_monopitch(self, match, row_type, is_first_cell):
"""
Expand All @@ -200,7 +206,10 @@ def handle_monopitch(self, match, row_type, is_first_cell):
if is_first_cell: # first cell impacts numbering
self.value[typ] = int(value)

return self.FORMAT(type=typ, text=value + label)
if typ == "V" or typ == "C":
return self.FORMAT_CLIMB(text=value + label)
else:
return self.FORMAT(type=typ, text=value + label)

elif len(value) == 0: # Simple use case : L#
self.allow_labels = False
Expand All @@ -212,7 +221,10 @@ def handle_monopitch(self, match, row_type, is_first_cell):
value += 1
self.value[typ] = value

return self.FORMAT(type=typ, text=str(value))
if typ == "V" or typ == "C":
return self.FORMAT_CLIMB(text=str(value))
else:
return self.FORMAT(type=typ, text=str(value))

else:
raise NotImplementedError("Should not happen")
Expand All @@ -225,7 +237,7 @@ class LTagProcessor(BlockProcessor):
and will be handled by TreeProcessor
"""

RE_TESTER = re.compile(r"(?:^|\n) {0,3}([LR]#)")
RE_TESTER = re.compile(r"(?:^|\n) {0,3}([LRVC]#)")
RE_PIPE_SAVER = re.compile(r'(\|)(?![^|]*\]\])')
CELL_SEPARATOR = '__--|--__'

Expand Down
44 changes: 44 additions & 0 deletions c2corg_api/tests/markdown/ltags/aliases.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<table c2c:role="ltag">
<tbody>
<tr>
<td><span class="pitch"><span translate="">L</span>1</span></td>
<td>5a</td>
<td><span class="pitch"><span translate="">L</span>2</span>&nbsp;and <span class="pitch"><span translate="">L</span>3</span>&nbsp;are joined to <span class="pitch"><span translate="">L</span>1</span></td>
</tr>
<tr>
<td><span class="pitch"><span translate="">L</span>4</span></td>
<td>5b+</td>
<td>Awesome pitch&#8239;!</td>
</tr>
<tr>
<td><span class="pitch"><span translate="">R</span>1</span></td>
<td>5a</td>
<td><span class="pitch"><span translate="">R</span>2</span>&nbsp;and <span class="pitch"><span translate="">R</span>3</span>&nbsp;are joined to <span class="pitch"><span translate="">R</span>1</span></td>
</tr>
<tr>
<td><span class="pitch"><span translate="">R</span>4</span></td>
<td>5b+</td>
<td>Awesome pitch&#8239;!</td>
</tr>
<tr>
<td><span class="pitch">1</span></td>
<td>5a</td>
<td><span class="pitch">2</span>&nbsp;and <span class="pitch">3</span>&nbsp;are joined to <span class="pitch">1</span></td>
</tr>
<tr>
<td><span class="pitch">4</span></td>
<td>5b+</td>
<td>Awesome pitch&#8239;!</td>
</tr>
<tr>
<td><span class="pitch">1</span></td>
<td>5a</td>
<td><span class="pitch">2</span>&nbsp;and <span class="pitch">3</span>&nbsp;are joined to <span class="pitch">1</span></td>
</tr>
<tr>
<td><span class="pitch">4</span></td>
<td>5b+</td>
<td>Awesome pitch&#8239;!</td>
</tr>
</tbody>
</table>
8 changes: 8 additions & 0 deletions c2corg_api/tests/markdown/ltags/aliases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
L# | 5a | L#2 and L#3 are joined to L#
L#4| 5b+ | Awesome pitch !
R# | 5a | R#2 and R#3 are joined to R#
R#4| 5b+ | Awesome pitch !
V# | 5a | V#2 and V#3 are joined to V#
V#4| 5b+ | Awesome pitch !
C# | 5a | C#2 and C#3 are joined to C#
C#4| 5b+ | Awesome pitch !