diff --git a/deeptutor/utils/bibtex_converter.py b/deeptutor/utils/bibtex_converter.py index fab5d0848..79aa430b5 100644 --- a/deeptutor/utils/bibtex_converter.py +++ b/deeptutor/utils/bibtex_converter.py @@ -204,7 +204,10 @@ def _read_fields(body: str) -> dict[str, str]: raise ValueError("empty BibTeX value") value = body[index:end] index = end - parts.append(value.strip()) + # Whitespace inside a quoted/braced fragment belongs to the value: + # trimming before concatenation would turn "Jane " # "Doe" into + # "JaneDoe". Display formatting normalizes the completed value. + parts.append(value) index = _skip_whitespace(body, index) if index < len(body) and body[index] == "#": index = _skip_whitespace(body, index + 1) diff --git a/tests/utils/test_bibtex_converter.py b/tests/utils/test_bibtex_converter.py index 6e50f394b..3cf3387eb 100644 --- a/tests/utils/test_bibtex_converter.py +++ b/tests/utils/test_bibtex_converter.py @@ -122,3 +122,37 @@ def test_bibtex_to_markdown_formats_jr_and_braced_author_names() -> None: result = bibtex_to_markdown(text) assert "**Authors:** Martin Luther King Jr., Food and Agriculture Organization" in result + + +def test_bibtex_to_markdown_preserves_spaces_in_concatenated_values() -> None: + text = """ + @article{joined, + title = "Attention " # {Is All } # "You Need", + author = "Doe, " # {Jane and } # "Smith, John", + abstract = {First sentence.} # " " # {Second sentence.}, + year = 20 # 26 + } + """ + + result = bibtex_to_markdown(text) + + assert "## 1. Attention Is All You Need" in result + assert "**Authors:** Jane Doe, John Smith" in result + assert "**Abstract:** First sentence. Second sentence." in result + assert "**Year:** 2026" in result + + +def test_bibtex_to_markdown_does_not_insert_spaces_between_joined_values() -> None: + text = """ + @article{joined, + title = "Sub" # {word}, + doi = "10.1000/" # "example", + year = 20 # 26 + } + """ + + result = bibtex_to_markdown(text) + + assert "## 1. Subword" in result + assert "**DOI:** 10.1000/example" in result + assert "**Year:** 2026" in result