Skip to content

Commit

Permalink
fix(config) replace admonition markup in help texts
Browse files Browse the repository at this point in the history
Signed-off-by: David Edler <david.edler@canonical.com>
  • Loading branch information
edlerd committed Jan 31, 2024
1 parent 2bddb69 commit c035e6b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/util/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ describe("toConfigFields and replaceDocLinks", () => {
'the value of <a href="https://docs.example.org/reference/storage_zfs/#storage-zfs-volume-conf:zfs.block_mode" target="_blank" rel="noreferrer">zfs.block_mode</a>,<br>the specified',
);
});

it("converts admonition markup to html bold tag", () => {
const input = "Foo bar baz. ```{important} Some important addition.```";

const result = configDescriptionToHtml(
input,
"https://docs.example.org",
objectsInvTxt.split("\n"),
);

expect(result).toBe(
"Foo bar baz. <b>Important</b> Some important addition.",
);
});
});

const objectsInvTxt =
Expand Down
10 changes: 5 additions & 5 deletions src/util/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const configDescriptionToHtml = (
.replaceAll(">", "&gt;")
.replaceAll("\n", "<br>");

// replace admonition markup
result = result
.replaceAll("```", "")
.replaceAll("{important}", "<b>Important</b>");

// documentation links
if (objectsInvTxt) {
// tags like {ref}`instance-options-qemu` can be in the input string
Expand Down Expand Up @@ -67,10 +72,5 @@ export const configDescriptionToHtml = (
result = result.replace("`", "<code>").replace("`", "</code>");
}

// remove invalid placeholders
result = result
.replaceAll("```", "")
.replaceAll("{{snapshot_pattern_detail}}", "");

return result;
};

0 comments on commit c035e6b

Please sign in to comment.