[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)
Paul Kirth via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 17 10:08:43 PDT 2025
================
@@ -514,17 +514,21 @@ writeFileDefinition(const Location &L,
Node->Children.emplace_back(std::make_unique<TextNode>("Defined at line "));
auto LocNumberNode =
std::make_unique<TagNode>(HTMLTag::TAG_A, std::to_string(L.LineNumber));
- // The links to a specific line in the source code use the github /
- // googlesource notation so it won't work for all hosting pages.
- // FIXME: we probably should have a configuration setting for line number
- // rendering in the HTML. For example, GitHub uses #L22, while googlesource
- // uses #22 for line numbers.
- LocNumberNode->Attributes.emplace_back(
- "href", (FileURL + "#" + std::to_string(L.LineNumber)).str());
+
+ std::string LineAnchor = "#";
+
+ if (RepositoryLinePrefix)
+ LineAnchor += RepositoryLinePrefix.value().str();
+
+ LineAnchor += std::to_string(L.LineNumber);
+
+ LocNumberNode->Attributes.emplace_back("href", (FileURL + LineAnchor).str());
----------------
ilovepi wrote:
I think at this point we may want to consider one of the format functions to avoid excessive string copies. There's probably a way to spell this all directly w/ `Twine` here in the call, but that may be harder and is probably unnecessary.
https://llvm.org/docs/ProgrammersManual.html#formatting-strings-the-formatv-function has more info on our formatting function.
https://github.com/llvm/llvm-project/pull/131280
More information about the cfe-commits
mailing list