3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-07-31 00:13:18 +00:00

cmdref: codeblock language now works

Add `options` map for setting `ContentListing` options with key:val pairs; currently only used with `ContentListing::codeblock()` language arg.
Fix generated codeblock rst to print each line of code with indentation, and change it to use explicit an `code-block` so we can set a language on it.
This commit is contained in:
Krystine Sherwin 2025-03-21 10:28:48 +13:00
parent fb944ca0fb
commit b1c9097a12
No known key found for this signature in database
4 changed files with 17 additions and 5 deletions

View file

@ -27,6 +27,7 @@ Json ContentListing::to_json() {
if (body.length()) object["body"] = body;
if (strcmp(source_file, "unknown") != 0) object["source_file"] = source_file;
if (source_line != 0) object["source_line"] = source_line;
object["options"] = Json(options);
Json::array content_array;
for (auto child : _content) content_array.push_back(child->to_json());
object["content"] = content_array;
@ -52,6 +53,7 @@ void ContentListing::codeblock(const string &code, const string &language,
const source_location location)
{
add_content("code", code, location);
back()->set_option("language", language);
}
void ContentListing::paragraph(const string &text,

View file

@ -32,12 +32,14 @@ public:
string body;
const char* source_file;
int source_line;
std::map<string, string> options;
ContentListing(
string type = "root", string body = "",
const char* source_file = "unknown", int source_line = 0
) : type(type), body(body), source_file(source_file), source_line(source_line) {
_content = {};
options = {};
}
ContentListing(string type, string body, source_location location) :
@ -61,6 +63,10 @@ public:
return _content.back();
}
void set_option(string key, string val = "") {
options[key] = val;
}
void usage(
const string &usage,
const source_location location = source_location::current()