denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
98.13k stars 5.4k forks source link

Doc tests don't play nice with blockquotes in markdown #24164

Open lishaduck opened 5 months ago

lishaduck commented 5 months ago

Version: Deno 1.44.1

Doc tests don't fail to parse if they're in a blockquote.

deno fmt agrees this is how it should be formatted, and it renders correctly in the vscode preview.

In a README.md:

> ```ts
> import { foo } from "./baz"
> ```

deno test --doc provides:

error: The module's source code could not be parsed: Unexpected token `{`. Expected `.` or `(` at file:///Users/.../Developer/libs/README.md$1-4.ts:1:10

  > import { foo } from "./baz"
           ~
MujahedSafaa commented 3 months ago

Hi @caspervonb @dsherret I did a workaround and found that when the content is extracted from the fenced blocks it extracted with the blockquotes which cause the parse error. image image image

I tried to solve the problem using the regex but I didn't find any regex that could extract the ">" from each line of the content. I could solve the issue using a manual extraction for the ">" if all the lines start with this character otherwise I will do nothing. Do you have any suggestions for the issue or other approaches??