Skip to content

Program outputs without a terminating newline cannot be represented in Markdown code blocks #11

Description

@anko

Description

Tests like the following will always fail, because process.stdout.write does not write a terminating newline, while the out block is parsed as though it had an implicit terminating newline:

<!-- !test program node -->
<!-- !test in name -->

    process.stdout.write('no newline after this')

<!-- !test out name -->

    no newline after this

There is no mention in the Markdown or CommonMark standards on how to represent a code block without a terminating newline, so even if some syntax hack works, it's off-spec behaviour and can't be relied on. The CommonMark spec is feature-frozen, and even if it weren't, previous spec discussions found newlineless code blocks unimportant, because the rendered HTML is the same either way.

Unfortunately, the difference is semantically meaningful for some tests one might want to write in txm.

Potential fix

At the moment, only Markdown code blocks (indented or fenced) are recognised as potential test inputs or outputs. If we add a dependency on an HTML parser (huge, in terms of code size), we could use embedded HTML in the form of <pre><code>no newline after this</code></pre> as an alternative for such cases.

This just seems like a heavy-handed solution, given that the problem is rare, and almost always easy to work around, by having the test print (no newline)\n, to demonstrate the lack of a newline prior to the parens.

I'll have to think about whether it's worth it, or whether to just document the deficiency and workaround; I'm leaving this issue as a reminder and reference.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions