[Mlir-commits] [mlir] [mlir][docgen] Add ops source link (PR #73657)
Rik Huijzer
llvmlistbot at llvm.org
Wed Nov 29 03:15:16 PST 2023
================
@@ -265,10 +265,24 @@ static void emitOpDoc(const Operator &op, raw_ostream &os) {
os << "\n";
}
+static void emitSourceLink(StringRef inputFilename, raw_ostream &os) {
+ size_t pathBegin = inputFilename.find("mlir/include/mlir/");
+ if (pathBegin == StringRef::npos)
+ return;
+
+ StringRef inputFromMlirInclude = inputFilename.substr(pathBegin);
+
+ os << "<span class=\"op-definitions-source-link\">\n";
+ os << " <a href=\"https://github.com/llvm/llvm-project/blob/main/"
+ << inputFromMlirInclude << "\">source</a>\n";
+ os << "</span>\n\n";
----------------
rikhuijzer wrote:
> Is HTML just valid in Markdown like that?
Yes. I've generated the code locally and it works there. By default this is disabled in Hugo, but MLIR has enabled raw HTML by setting goldmark unsafe (https://github.com/llvm/mlir-www/blob/c0925992314c8ac91be62adc8f1d9bddfd05098a/website/config.toml#L109-L113). The main attack that the "safe" mode defends against is attacks who insert arbitrary scripts inside the source files (but it doesn't protect against malicious Markdown links).
> Can we use markdown syntax for the link?
Yes that's possible. I've just locally changed the lines to
```cpp
os << "[source](https://github.com/llvm/llvm-project/blob/main/"
<< inputFromMlirInclude << ")\n\n";
```
This works, but introduces extra spacing:
![image](https://github.com/llvm/llvm-project/assets/20724914/48922e71-2c1d-4345-8389-e1e41a61a182)
because Hugo wraps the link inside paragraph `<p>` tags, whereas I wrapped it in `<span>` tags which have no spacing by default.
I don't mind much. Let me know what you prefer and I'll put it in 👍
https://github.com/llvm/llvm-project/pull/73657
More information about the Mlir-commits
mailing list