janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.52k stars 227 forks source link

Markdown in doc strings behaves different for C functions and Janet functions #808

Closed llmII closed 3 years ago

llmII commented 3 years ago

If I create a docstring lke the following in Janet

``
\t`word` **symbol**
``

versus in C,

"\t`word` **symbol**

I'll have to retest this but for a C function it displays "{italic}word{italic} {bold}symbol{bold}". For Janet it either displays "\tword symbol" or just differently, even if I attempt to escape the '' with "\". Been through a couple of "how can I make it display like in C" and I'll have to do the rundown again but in one instance it just indented it as a code block (no formatting) and in another you get a prefix of 't' with backticks and asterisks preserved verbatim (not changed to formatting) and it's entirely possible there's another way it displayed that I'm not remembering. Sorry for the rushed issue report, I will update this issue with more specifics, even though the main gist of the issue, being that Janet functions markdown docstrings display differently than C functions, will remain the same.

llmII commented 3 years ago

To make it simple (don't have to write a C function and play around), install jsys, then do (import sys) (doc sys/chown). Then look at the source code on/around line 192 in the file src/csys.c. Mimicking that in a Janet docstring does not yield the same results.

llmII commented 3 years ago

Check the output of the following:

(defn t1
``
\t\`example\` **example**

info
``
[] ())

(defn t2
``
\t`example` **example**

info
``
[] ())

(defn t3
``
  `example` **example**

info
``
[] ())

(defn t4
``
    `example` **example**

info
``
[] ())

(doc t1)
(doc t2)
(doc t3)
(doc t4)

A few key things, '\t' doesn't work, manual indentation by 4 columns fails (is a code block, verbatim, not formatted), escaping '\t' just prefixes the italicized example with 't'. I probably tried a few other things earlier today and can't remember them all at this time but '\t' works in C source (like at the end of this), but does not work in Janet source. I think one of the things I experienced that caused no formatting to occur was possibly the trailing '' in a function's name being used as a formatting character up till the next encounter of '' like in #809 so that's possibly where I saw some of the other issues I mentioned with this.

C Source, for example, below:

JANET_FN(cfun_chown, "(chown uid gid path-or-file)",
         "-> _true|throws error_\n\n"
         "\t`uid`          **:number**\n\n"
         "\t`gid`          **:number**\n\n"
         "\t`path-or-file` **:string|:core/file**\n\n"
         "Changes the ownership of the file at `path-or-file` over to "
         "the user defined by `uid` and the group defined by `gid`."
) {
    janet_fixarity(argc, 3);

    uid_t uid = janet_getinteger(argv, 0);
    gid_t gid = janet_getinteger(argv, 1);

    if(janet_checktype(argv[0], JANET_ABSTRACT)) {
        int fd;
        if (-1 != (fd = file_to_fd(argv, 0))) {
            if (0 != fchown(fd, uid, gid)) {
                sys_errno("Failed to chown with file handle");
                return janet_wrap_boolean(0);
            }
        } else {
            janet_panic("Invalid file handle");
        }
    } else {
        const char *where = (char *)janet_getstring(argv, 0);
        if (0 != chown(where, uid, gid)) {
            sys_errnof("Failed to chown with path: %s", where);
            return janet_wrap_boolean(0);
        }
    }

    return janet_wrap_boolean(1);
}
bakpakin commented 3 years ago

You cannot escape \t in long strings. Backtick delimited long strings do not support escape sequences. Use normal quotes instead.