Repository: NilsJPWerner/autoDocstring (ts)

Issue:
Argument with Literal strings type hint badly formatted
**Describe the bug**
A clear and concise description of what the bug is.

When passing a Literal type hint containing strings, the docstring badly writes the quotation marks.
Instead of `bar : Literal["A", "B"]` I get `bar : Literal[&quot;A&quot;, &quot;B&quot;]`
Instead of `bar : Literal['A', 'B']` I get `bar : Literal[&#39;A&#39;, &#39;B&#39;]`

**Versions (please complete the following information):**

-   autoDocstring Version: v0.6.1
-   Operating System: Win10
-   Vscode Version: 1.67.2

**Original Code (with line to generate on):**

```python
from typing import Literal

def foo(bar: Literal["A", "B"]):
    # generate on this line
    return bar
```

**Expected Result:**

```python
def foo(bar: Literal["A", "B"]):
    """_summary_

    _extended_summary_

    Parameters
    ----------
    bar : Literal["A", "B"]
        _description_

    Returns
    -------
    _type_
        _description_
    """
    return bar
```

**Actual Result:**

```python
def foo(bar: Literal["A", "B"]):
    """_summary_

    _extended_summary_

    Parameters
    ----------
    bar : Literal[&quot;A&quot;, &quot;B&quot;]
        _description_

    Returns
    -------
    _type_
        _description_
    """
    return bar
```

**Debug log:**
Set `autoDocstring.logLevel` to "Debug", recreate the bug, and then copy the debug logs from the `autoDocstring` output channel.

```
[INFO 12:08:11.420] Generating Docstring at line: 8
[INFO 12:08:11.423] Docstring generated:
    """${1:_summary_}

    ${2:_extended_summary_}

    Parameters
    ----------
    bar : ${3:Literal[&quot;A&quot;, &quot;B&quot;]}
        ${4:_description_}

    Returns
    -------
    ${5:_type_}
        ${6:_description_}
    """
[INFO 12:08:11.423] Inserting at position: 8 0
[INFO 12:08:11.442] Successfully inserted docstring

```


Pull request:
Change the mustache, HTML-escaping behavior
HTML-escaping quotes is a feature of mustache, see janl/mustache.js#13 and the [variables](https://github.com/janl/mustache.js?tab=readme-ov-file#variables) section in the docs. 

> All variables are HTML-escaped by default

The recommendation to disable HTML-escaping is

> If you'd like to change HTML-escaping behavior globally (for example, to template non-HTML formats), you can override Mustache's escape function. For example, to disable all escaping: `Mustache.escape = function(text) {return text;};`.

closes #235

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7dc72b8..334ae93 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 ([#235](https://github.com/NilsJPWerner/autoDocstring/issues/235)) (@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;


Test patch:
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}}";