Skip to content

Commit a733cbc

Browse files
eamonnmcmanusgoogle-java-format Team
authored andcommitted
Add a giant TODO comment listing the remaining Markdown cases we don't handle well.
Also add test methods that currently illustrate the incorrect handling. As we fix each issue, we can delete it from the comment and ensure that its test method produces the expected result. PiperOrigin-RevId: 897161602
1 parent 3e290d1 commit a733cbc

File tree

1 file changed

+185
-1
lines changed

1 file changed

+185
-1
lines changed

core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java

Lines changed: 185 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,187 @@ class Test {}
17751775
doFormatTest(input, expected);
17761776
}
17771777

1778+
@Test
1779+
public void markdownBackslashes() {
1780+
assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();
1781+
String input =
1782+
"""
1783+
/// \\<br> is not a break.
1784+
/// \\&#42; is not an HTML entity.
1785+
/// foo\\
1786+
/// bar
1787+
class Test {}
1788+
""";
1789+
// TODO: the <br> should not cause a line break, and the end-of-line backslash should.
1790+
// I don't think anything changes if we do or do not respect the \& backslash.
1791+
String expected =
1792+
"""
1793+
/// \\<br>
1794+
/// is not a break. \\&#42; is not an HTML entity. foo\\ bar
1795+
class Test {}
1796+
""";
1797+
doFormatTest(input, expected);
1798+
}
1799+
1800+
@Test
1801+
public void markdownThematicBreaks() {
1802+
assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();
1803+
String input =
1804+
"""
1805+
/// foo
1806+
/// ***
1807+
/// bar
1808+
class Test {}
1809+
""";
1810+
// TODO: the line break before `***` should be preserved.
1811+
// It's OK to introduce a blank line before `bar` since it is a new paragraph.
1812+
String expected =
1813+
"""
1814+
/// foo ***
1815+
///
1816+
/// bar
1817+
class Test {}
1818+
""";
1819+
doFormatTest(input, expected);
1820+
}
1821+
1822+
@Test
1823+
public void markdownSetextHeadings() {
1824+
assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();
1825+
String input =
1826+
"""
1827+
/// Heading
1828+
/// =======
1829+
/// Phoebe B. Peabody-Beebe
1830+
///
1831+
/// Subheading
1832+
/// ----------
1833+
class Test {}
1834+
""";
1835+
// TODO: the line breaks before the lines of repeated characters should be preserved.
1836+
// Or, we could rewrite this style of heading as `# Heading`.
1837+
String expected =
1838+
"""
1839+
/// Heading =======
1840+
///
1841+
/// Phoebe B. Peabody-Beebe
1842+
///
1843+
/// Subheading ----------
1844+
class Test {}
1845+
""";
1846+
doFormatTest(input, expected);
1847+
}
1848+
1849+
@Test
1850+
public void markdownIndentedCodeBlocks() {
1851+
assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();
1852+
String input =
1853+
"""
1854+
/// code block
1855+
/// is indented
1856+
class Test {}
1857+
""";
1858+
// TODO: the evil indented code block should be preserved.
1859+
String expected =
1860+
"""
1861+
/// code block is indented
1862+
class Test {}
1863+
""";
1864+
doFormatTest(input, expected);
1865+
}
1866+
1867+
@Test
1868+
public void markdownLinkReferenceDefinitions() {
1869+
assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();
1870+
String input =
1871+
"""
1872+
/// [foo]
1873+
/// [foo]: /url "title"
1874+
class Test {}
1875+
""";
1876+
String expected =
1877+
"""
1878+
/// [foo] [foo]: /url "title"
1879+
class Test {}
1880+
""";
1881+
doFormatTest(input, expected);
1882+
}
1883+
1884+
@Test
1885+
public void markdownLooseLists() {
1886+
assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();
1887+
String input =
1888+
"""
1889+
/// - item 1
1890+
///
1891+
/// - item 2
1892+
class Test {}
1893+
""";
1894+
// TODO: the line break between items should be preserved, and there should not be a blank line
1895+
// before the list.
1896+
String expected =
1897+
"""
1898+
///
1899+
/// - item 1
1900+
/// - item 2
1901+
class Test {}
1902+
""";
1903+
doFormatTest(input, expected);
1904+
}
1905+
1906+
@Test
1907+
public void markdownBlockQuotes() {
1908+
assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();
1909+
String input =
1910+
"""
1911+
/// > foo
1912+
/// > bar
1913+
class Test {}
1914+
""";
1915+
// TODO: the block quote should be preserved, and ideally bar would be joined to foo.
1916+
String expected =
1917+
"""
1918+
/// >
1919+
///
1920+
/// foo > bar
1921+
class Test {}
1922+
""";
1923+
doFormatTest(input, expected);
1924+
}
1925+
1926+
@Test
1927+
public void markdownCodeSpans() {
1928+
assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();
1929+
String input =
1930+
"""
1931+
/// `<ul>` should not trigger list handling.
1932+
class Test {}
1933+
""";
1934+
// TODO: the <ul> should not be recognized as a list, so `<ul>` should be preserved.
1935+
// TODO: test that text with `...` is subject to line wrapping, including joining short lines.
1936+
String expected =
1937+
"""
1938+
/// `<ul>
1939+
/// ` should not trigger list handling.
1940+
class Test {}
1941+
""";
1942+
doFormatTest(input, expected);
1943+
}
1944+
1945+
@Test
1946+
public void markdownAutolinks() {
1947+
assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue();
1948+
String input =
1949+
"""
1950+
/// <http://example.com> should be preserved.
1951+
class Test {}
1952+
""";
1953+
// TODO: find a test case that will break if autolinks are not handled correctly.
1954+
// Probably something like: <http://{@code>this should not be handled like a code span}
1955+
String expected = input;
1956+
doFormatTest(input, expected);
1957+
}
1958+
17781959
// TODO: b/346668798 - Test the following Markdown constructs, and make the tests work as needed.
17791960
// We can assume that the CommonMark parser correctly handles Markdown, so the question is whether
17801961
// they are subsequently mishandled by our formatting logic. So for example the CommonMark parser
@@ -1821,7 +2002,10 @@ class Test {}
18212002
// inside a list. https://spec.commonmark.org/0.31.2/#block-quotes
18222003
//
18232004
// - Code spans
1824-
// `<ul>` should not trigger list handling. https://spec.commonmark.org/0.31.2/#code-spans
2005+
// `<ul>` should not trigger list handling.
2006+
// Text within `...` should still be subject to line wrapping, both splitting long lines and
2007+
// joining short lines. https://spec.commonmark.org/0.31.2/#code-spans
2008+
//
18252009
//
18262010
// - Autolinks
18272011
// <http://example.com> should be preserved. https://spec.commonmark.org/0.31.2/#autolink

0 commit comments

Comments
 (0)