summaryrefslogtreecommitdiffstats
path: root/yql/essentials/utils/docs/markdown.cpp
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-08-07 19:24:44 +0300
committerrobot-piglet <[email protected]>2025-08-07 19:36:57 +0300
commit319c53daa4d3137edd9f6938531c983331ae730e (patch)
treeb5bb9e6f5ec328a4547889f0c7f6e7b6813ace1b /yql/essentials/utils/docs/markdown.cpp
parentd74a3f4e813af8c964567dfd89f725ed81ee141c (diff)
Intermediate changes
commit_hash:da32df476c05ee8928d99ec0d784ed2e3b929624
Diffstat (limited to 'yql/essentials/utils/docs/markdown.cpp')
-rw-r--r--yql/essentials/utils/docs/markdown.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/yql/essentials/utils/docs/markdown.cpp b/yql/essentials/utils/docs/markdown.cpp
index ca0f555a815..fd13820b8c4 100644
--- a/yql/essentials/utils/docs/markdown.cpp
+++ b/yql/essentials/utils/docs/markdown.cpp
@@ -23,20 +23,24 @@ namespace NYql::NDocs {
void Parse(IInputStream& markdown, TMarkdownCallback&& onSection) {
for (TString line; markdown.ReadLine(line) != 0;) {
+ size_t depth = HeaderDepth(line);
if (IsSkipping_) {
- if (IsSectionHeader(line)) {
+ if (HeaderDepth_ == depth) {
ResetSection(std::move(line));
IsSkipping_ = false;
} else {
// Skip
}
} else {
- if (IsSectionHeader(line)) {
+ if (HeaderDepth_ == depth) {
onSection(std::move(Section_));
ResetSection(std::move(line));
- } else {
+ } else if (depth == 0 || HeaderDepth_ < depth) {
line.append('\n');
Section_.Body.append(std::move(line));
+ } else {
+ onSection(std::move(Section_));
+ IsSkipping_ = true;
}
}
}
@@ -64,11 +68,15 @@ namespace NYql::NDocs {
}
}
- bool IsSectionHeader(TStringBuf line) const {
- return HeaderDepth(line) == HeaderDepth_;
- }
-
size_t HeaderDepth(TStringBuf line) const {
+ while (line.StartsWith(' ') || line.StartsWith('\t')) {
+ line.Skip(1);
+ }
+
+ if (!line.StartsWith('#')) {
+ return 0;
+ }
+
size_t begin = line.find('#');
size_t end = line.find_first_not_of('#', begin);
return end != TStringBuf::npos ? (end - begin) : 0;