commonmark / commonmark/commonmark-java
Preserve information about leading whitespace in paragraphs
未关闭
还没有人认领这个 Issue。
enhancement
help wanted
- 主要语言
- Java
- 星标
- 2.7k
- 派生
- 336
- PR 合并指标
- 30 天内没有已合并 PR
描述
When using DocumentParser with no enabled block types, the Text nodes do not include whitespaces at the beginning of a line.
For example, when we use a parser with no enabled block types and the input is:
- text 1
- text 2
the expected result is a document containing two Text nodes:
- Text("- text 1")
- Text(" - text 2")
but the second Text is "- text 2" (without preceding whitespaces)
To better illustrate here is a sample test that fails:
public class ParserTest {
...
@Test
public void noBlockTypes() {
String given = "- text 1\n - text 2";
Parser parser = Parser.builder().enabledBlockTypes(Collections.<Class<? extends Block>>emptySet()).build();
Node document = parser.parse(given);
Node child = document.getFirstChild();
assertThat(child, instanceOf(Paragraph.class));
child = child.getFirstChild();
assertThat(child, instanceOf(Text.class));
assertEquals("- text 1", ((Text) child).getLiteral());
child = child.getNext();
assertThat(child, instanceOf(SoftLineBreak.class));
child = child.getNext();
assertThat(child, instanceOf(Text.class));
assertEquals(" - text 2", ((Text) child).getLiteral());
}
}
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从失败的 ParserTest.noBlockTypes 场景开始,在禁用所有块类型的情况下检查 Parser.builder(),然后跟踪输入行如何变成 Text 节点。使用示例输入运行测试,并确认第二个 Text 节点保留其开头的两个空格。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100