From 0a75daceecb15eb1ac4ff1497ff005b017ce279b Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Fri, 25 Aug 2023 22:48:26 -0700 Subject: [PATCH] [doc] disable guidelines when sane indents are not detected --- src/document.sections.cc | 21 +++++++++++++++++++++ src/text_format.cc | 6 ++++++ src/text_format.hh | 4 ++++ 3 files changed, 31 insertions(+) diff --git a/src/document.sections.cc b/src/document.sections.cc index 70bcdf3f..f4b07896 100644 --- a/src/document.sections.cc +++ b/src/document.sections.cc @@ -453,6 +453,27 @@ public: this->sw_hier_stage->hn_parent = nullptr; } + if (!this->sw_indents.empty()) { + auto low_indent_iter = this->sw_indents.begin(); + + if (*low_indent_iter == 1) { + // adding guides for small indents is noisy, drop for now + this->sw_indents.clear(); + } else { + auto lcm = *low_indent_iter; + + for (auto indent_iter = this->sw_indents.begin(); + indent_iter != this->sw_indents.end();) + { + if ((*indent_iter % lcm) == 0) { + ++indent_iter; + } else { + indent_iter = this->sw_indents.erase(indent_iter); + } + } + } + } + mb.mb_root_node = std::move(this->sw_hier_stage); mb.mb_intervals = std::move(this->sw_intervals); mb.mb_type_intervals = std::move(this->sw_type_intervals); diff --git a/src/text_format.cc b/src/text_format.cc index 4a109db2..e86c34d7 100644 --- a/src/text_format.cc +++ b/src/text_format.cc @@ -64,6 +64,7 @@ detect_text_format(string_fragment sf, static const auto XML_EXT = ghc::filesystem::path(".xml"); static const auto YAML_EXT = ghc::filesystem::path(".yaml"); static const auto YML_EXT = ghc::filesystem::path(".yml"); + static const auto MAKEFILE_STEM = ghc::filesystem::path("Makefile"); static const auto MD_EXT = ghc::filesystem::path(".md"); static const auto MARKDOWN_EXT = ghc::filesystem::path(".markdown"); @@ -124,6 +125,7 @@ detect_text_format(string_fragment sf, path = path->stem(); } + auto stem = path->stem(); auto ext = path->extension(); if (ext == MD_EXT || ext == MARKDOWN_EXT) { return text_format_t::TF_MARKDOWN; @@ -156,6 +158,10 @@ detect_text_format(string_fragment sf, if (ext == XML_EXT) { return text_format_t::TF_XML; } + + if (stem == MAKEFILE_STEM) { + return text_format_t::TF_MAKEFILE; + } } { diff --git a/src/text_format.hh b/src/text_format.hh index a923fb36..9a7a05eb 100644 --- a/src/text_format.hh +++ b/src/text_format.hh @@ -47,6 +47,7 @@ enum class text_format_t { TF_JAVA, TF_JSON, TF_LOG, + TF_MAKEFILE, TF_MAN, TF_MARKDOWN, TF_PYTHON, @@ -95,6 +96,9 @@ struct formatter : formatter { case text_format_t::TF_JSON: name = "application/json"; break; + case text_format_t::TF_MAKEFILE: + name = "text/x-makefile"; + break; case text_format_t::TF_MAN: name = "text/man"; break;