Skip to content
Merged
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
7 changes: 6 additions & 1 deletion backend/doc/markdown_transforms/link_regexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import re


# Handle TW wikilink inner text
TW_RC_LINK_RE = re.compile(
(
Expand Down Expand Up @@ -185,3 +184,9 @@
BC_MARKDOWN_LINK_RE = re.compile(
r"\[(?P<link_text>.+?)\] *\(\.\.\/(?P<link_ref>articles.+?)\)"
)


SEE_PARENTHETICAL_RE = re.compile(
r"\((?P<prefix_text>[^\s():]+:)\s*.*?\)",
re.IGNORECASE,
)
16 changes: 15 additions & 1 deletion backend/doc/markdown_transforms/markdown_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from doc.domain.model import ResourceRequest
from doc.markdown_transforms.link_regexes import (
RC_QUESTION_LINK_RE,
SEE_PARENTHETICAL_RE,
TA_MARKDOWN_HTTPS_LINK_RE,
TA_PREFIXED_MARKDOWN_HTTPS_LINK_RE,
TA_PREFIXED_MARKDOWN_LINK_RE,
Expand All @@ -34,7 +35,6 @@
from doc.utils.file_utils import read_file
from doc.utils.tw_utils import localized_translation_word


logger = settings.logger(__name__)

TRANSLATION_WORD_ANCHOR_LINK_FMT_STR: str = "[{}](#{}-{})"
Expand Down Expand Up @@ -124,6 +124,8 @@ def transform_tw_links(
source = transform_rc_obe_tw_links(
source, lang_code, resource_requests, translation_words_dict
)

source = remove_see_colon_prefixed_parenthicals(source)
return source


Expand Down Expand Up @@ -158,6 +160,7 @@ def transform_ta_and_tn_links(
source = transform_tn_missing_book_code_markdown_links_no_paren(source)
source = transform_tn_obs_markdown_links(source)
source = transform_rc_question_links(source)
source = remove_see_colon_prefixed_parenthicals(source)
return source


Expand Down Expand Up @@ -1045,3 +1048,14 @@ def wiki_link_parser(
for link in finditer(wiki_link_re, source)
]
return links


def remove_see_colon_prefixed_parenthicals(
source: str,
see_parenthetical_re: re.Pattern[str] = SEE_PARENTHETICAL_RE,
) -> str:
"""
Remove any parenthetical string beginning with localized '(See:'.
Example: '(Veja: foobar)' -> ''
"""
return see_parenthetical_re.sub("", source)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend adding some unit tests to demonstrate that this function is behaving as intended. I think it should remove e.g.

  • (See: [[rc://...]])
  • (See: Altar)

but should not remove e.g.:

  • "devour one another (Galatians 5:15)."
  • "precious in his sight (Isaiah 43:4)."
  • "keep provisions (see 2 Chronicles 8:3)."

Of course, PO gets final say.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test data

38 changes: 8 additions & 30 deletions frontend/tests/e2e/doc_test_3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ test('ordering of books in document title(s) and body', async ({ page }) => {
await page.getByPlaceholder('Search Heart Languages').fill('ont')
await page.getByText('Ontenu').click()
await page.getByRole('button', { name: 'Next' }).click()
await page.getByText('Matyu').click({ timeout: 32_000 })
await page.getByText('Mak').click()
await page.getByText('Luk', { exact: true }).click()
await page.getByText('Efesus').click({ timeout: 32_000 })
await page.getByRole('button', { name: 'Next' }).click()
await page.getByText('Unlocked Literal Bible').first().click()
await page.getByText('Regular').click()
Expand All @@ -82,44 +80,24 @@ test('ordering of books in document title(s) and body', async ({ page }) => {
const page1 = await page1Promise
// Perform text expectations on the popup page
await expect(page1.locator('body')).toContainText(
'Tok Pisin (Tok Pisin): Unlocked Literal Bible for Matyu, Mak, Luk'
)
await expect(page1.locator('body')).toContainText(
'Ontenu (Ontenu): Regular for Matthew, Maki, Luk'
'Tok Pisin (Tok Pisin): Unlocked Literal Bible for Efesus'
)
await expect(page1.locator('body')).toContainText('Ontenu (Ontenu): Regular for Efeses')

// Order assertions
const headings = await page1.locator('h2').allTextContents()
// Ensure expected headings are present
expect(headings).toContain('Matyu')
expect(headings).toContain('Matthew')
expect(headings).toContain('Mak')
expect(headings).toContain('Maki')
expect(headings).toContain('Luk')
expect(headings).toContain('Efesus')
expect(headings).toContain('Efeses')

// Order assertions
// Find the positions of each
const index1 = headings.indexOf('Matyu')
const index2 = headings.indexOf('Matthew')
const index3 = headings.indexOf('Mak')
const index4 = headings.indexOf('Maki')
const index5 = headings.indexOf('Luk')
const index1 = headings.indexOf('Efesus')
const index2 = headings.indexOf('Efeses')

// Ensure all were found
expect(index1).not.toBe(-1)
expect(index2).not.toBe(-1)
expect(index3).not.toBe(-1)
expect(index4).not.toBe(-1)
expect(index5).not.toBe(-1)

// Check the order
expect(index1).toBeLessThan(index2)
expect(index1).toBeLessThan(index3)
expect(index2).toBeLessThan(index3)
expect(index1).toBeLessThan(index4)
expect(index2).toBeLessThan(index4)
expect(index3).toBeLessThan(index4)
expect(index1).toBeLessThan(index5)
expect(index2).toBeLessThan(index5)
expect(index3).toBeLessThan(index5)
expect(index4).toBeLessThan(index5)
})
13 changes: 13 additions & 0 deletions tests/unit/test_markdown_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,16 @@ def test_remove_pagination_symbols_from_commentary() -> None:
"""
source = markdown_transformer.remove_pagination_symbols(source)
assert expected == source


def test_remove_localized_see_colon_patterns_only() -> None:
source = """Nullam eu ante vel est convallis dignissim. Fusce suscipit, wisi nec facilisis facilisis, est dui fermentum leo, quis tempor ligula erat quis odio. Nunc porta vulputate tellus. Nunc rutrum turpis sed pede. Sed bibendum. Aliquam posuere. Nunc aliquet, augue nec adipiscing interdum, lacus tellus malesuada massa, quis varius mi purus non odio. Pellentesque condimentum, magna ut suscipit hendrerit, ipsum augue ornare nulla, non luctus diam neque sit amet urna. Curabitur vulputate vestibulum lorem. Fusce sagittis, libero non molestie mollis, magna orci ultrices dolor, at vulputate neque nulla lacinia eros. Sed id ligula quis est convallis tempor precious in his sight (Isaiah 43:4). Curabitur lacinia pulvinar nibh keep provisions (see 2 Chronicles 8:3). Nam a sapien devour one another (Galatians 5:15).
(See: [[rc://...]])
(Veja: Altar)
"""
expected = """Nullam eu ante vel est convallis dignissim. Fusce suscipit, wisi nec facilisis facilisis, est dui fermentum leo, quis tempor ligula erat quis odio. Nunc porta vulputate tellus. Nunc rutrum turpis sed pede. Sed bibendum. Aliquam posuere. Nunc aliquet, augue nec adipiscing interdum, lacus tellus malesuada massa, quis varius mi purus non odio. Pellentesque condimentum, magna ut suscipit hendrerit, ipsum augue ornare nulla, non luctus diam neque sit amet urna. Curabitur vulputate vestibulum lorem. Fusce sagittis, libero non molestie mollis, magna orci ultrices dolor, at vulputate neque nulla lacinia eros. Sed id ligula quis est convallis tempor precious in his sight (Isaiah 43:4). Curabitur lacinia pulvinar nibh keep provisions (see 2 Chronicles 8:3). Nam a sapien devour one another (Galatians 5:15).


"""
source = markdown_transformer.remove_see_colon_prefixed_parenthicals(source)
assert expected == source
Loading