================
@@ -575,64 +631,18 @@ bool Paragraph::isHardLineBreakIndicator(llvm::StringRef
Rest) const {
return false;
}
-bool Paragraph::isHardLineBreakAfter(llvm::StringRef Line,
- llvm::StringRef Rest) const {
- // In Markdown, 2 spaces before a line break forces a line break.
- // Add a line break for plaintext in this case too.
+bool Paragraph::isHardLineBreakAfter(llvm::StringRef Line, llvm::StringRef
Rest,
+ bool IsMarkdown) const {
// Should we also consider whether Line is short?
- return Line.ends_with(" ") || punctuationIndicatesLineBreak(Line) ||
- isHardLineBreakIndicator(Rest);
+ return (punctuationIndicatesLineBreak(Line, IsMarkdown) ||
+ isHardLineBreakIndicator(Rest, IsMarkdown));
}
-void Paragraph::renderPlainText(llvm::raw_ostream &OS) const {
- bool NeedsSpace = false;
- std::string ConcatenatedText;
- ConcatenatedText.reserve(EstimatedStringSize);
-
- llvm::raw_string_ostream ConcatenatedOS(ConcatenatedText);
-
- for (auto &C : Chunks) {
-
- if (C.Kind == ChunkKind::PlainText) {
- if (C.SpaceBefore || NeedsSpace)
- ConcatenatedOS << ' ';
-
- ConcatenatedOS << C.Contents;
- NeedsSpace = llvm::isSpace(C.Contents.back()) || C.SpaceAfter;
- continue;
- }
-
- if (C.SpaceBefore || NeedsSpace)
- ConcatenatedOS << ' ';
- llvm::StringRef Marker = "";
- if (C.Preserve && C.Kind == ChunkKind::InlineCode)
- Marker = chooseMarker({"`", "'", "\""}, C.Contents);
- else if (C.Kind == ChunkKind::Bold)
- Marker = "**";
- else if (C.Kind == ChunkKind::Emphasized)
- Marker = "*";
- ConcatenatedOS << Marker << C.Contents << Marker;
- NeedsSpace = C.SpaceAfter;
- }
-
- // We go through the contents line by line to handle the newlines
- // and required spacing correctly.
- //
- // Newlines are added if:
- // - the line ends with 2 spaces and a newline follows
- // - the line ends with punctuation that indicates a line break (.:,;!?)
- // - the next line starts with a hard line break indicator (-@>#`, or a digit
- // followed by '.' or ')'), ignoring leading whitespace.
- //
- // Otherwise, newlines in the input are replaced with a single space.
- //
- // Multiple spaces are collapsed into a single space.
- //
- // Lines containing only whitespace are ignored.
+void Paragraph::renderNewlinesPlaintext(llvm::raw_ostream &OS,
+ std::string &ParagraphText) const {
----------------
kadircet wrote:
nit: `llvm::StringRef` instead of `std::string &`
https://github.com/llvm/llvm-project/pull/162029
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits