================
@@ -0,0 +1,182 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "MarkdownParser.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace clang::doc::markdown {
+
+namespace {
+
+/// A forward cursor over the lines of the input. Owns no storage; it points
+/// into a caller-provided array of lines and tracks the current position.
+/// Block parsers consume lines through this cursor instead of juggling a raw
+/// index, which keeps the parsing helpers free of manual bookkeeping.
+class LineCursor {
+public:
+  explicit LineCursor(llvm::ArrayRef<llvm::StringRef> Lines) : Lines(Lines) {}
+
+  bool atEnd() const { return Pos >= Lines.size(); }
+
+  /// The current line, trimmed of surrounding whitespace.
+  llvm::StringRef peek() const { return Lines[Pos].trim(); }
+
+  /// The current line as it appears in the source, without trimming.
+  llvm::StringRef peekRaw() const { return Lines[Pos]; }
+
+  void advance() { ++Pos; }
+
+private:
+  llvm::ArrayRef<llvm::StringRef> Lines;
+  size_t Pos = 0;
+};
+
+} // namespace
+
+static bool isListMarker(llvm::StringRef Line) {
+  return Line.starts_with("- ") || Line.starts_with("* ") ||
+         Line.starts_with("+ ");
+}
+
+static bool isThematicBreak(llvm::StringRef Line) {
+  if (Line.empty())
+    return false;
+  char Marker = Line.front();
+  if (Marker != '-' && Marker != '*' && Marker != '_')
+    return false;
+  llvm::SmallString<8> Allowed;
+  Allowed += Marker;
+  Allowed += ' ';
+  if (Line.find_first_not_of(Allowed) != llvm::StringRef::npos)
+    return false;
+  return Line.count(Marker) >= 3;
+}
+
+static bool isFence(llvm::StringRef Line) {
+  return Line.starts_with("```") || Line.starts_with("~~~");
+}
----------------
ilovepi wrote:

What if there's  4: "~~~~~"? 

https://github.com/llvm/llvm-project/pull/208003
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to