From ca5ff169a6e01820ee7ee752987481200c2f10b9 Mon Sep 17 00:00:00 2001 From: Philip Nelson Date: Mon, 1 Apr 2024 22:19:31 -0600 Subject: [PATCH] disable HTML-escaping behavior globally --- CHANGELOG.md | 1 + src/docstring/docstring_factory.ts | 4 ++++ src/test/docstring/generate_docstring.spec.ts | 16 ++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dc72b8..8258acb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Added doxygen format support ([#120](https://github.com/NilsJPWerner/autoDocstring/issues/120)) (@daluar @PhilipNelson5) +- Disable HTML-escaping behavior globally ([#253](https://github.com/NilsJPWerner/autoDocstring/issues/253)) (@PhilipNelson5) [All Changes](https://github.com/NilsJPWerner/autoDocstring/compare/v0.6.1...master) diff --git a/src/docstring/docstring_factory.ts b/src/docstring/docstring_factory.ts index 381c412..c1d83b8 100644 --- a/src/docstring/docstring_factory.ts +++ b/src/docstring/docstring_factory.ts @@ -2,6 +2,10 @@ import { render } from "mustache"; import { DocstringParts } from "../docstring_parts"; import { TemplateData } from "./template_data"; import { dedent } from "ts-dedent"; +import Mustache = require("mustache"); + +// Disable HTML-escaping behavior globally +Mustache.escape = (text: string) => text; export class DocstringFactory { private template: string; diff --git a/src/test/docstring/generate_docstring.spec.ts b/src/test/docstring/generate_docstring.spec.ts index c557ffe..e9bdf52 100644 --- a/src/test/docstring/generate_docstring.spec.ts +++ b/src/test/docstring/generate_docstring.spec.ts @@ -260,6 +260,22 @@ describe("DocstringFactory", () => { }); }); + context("when there are args", () => { + const template = "{{#args}}{{var}}:{{typePlaceholder}}{{/args}}"; + + it("should format Literals correctly", () => { + const docstringComponents = defaultDocstringComponents; + docstringComponents.args = [ + { var: "var_a", type: 'Literal["A", "B"]' }, + ]; + const factory = new DocstringFactory(template); + + const result = factory.generateDocstring(docstringComponents); + + expect(result).to.equal('"""var_a:${1:Literal["A", "B"]}"""'); + }); + }); + context("when the argsExist tag is used", () => { const template = "{{#argsExist}}Args Exist!{{/argsExist}}";