rescript-association / reasonml.org

Deprecated in favor of rescript-lang.org
MIT License
125 stars 33 forks source link

Add prelude support #57

Closed ryyppy closed 4 years ago

ryyppy commented 4 years ago

This PR will enable prelude snippet support. What does that mean? Some modules require some shared code to express examples more easily (and to reduce repetitive writing). Such as the pages/belt_docs/set.mdx file.

How to use it?

Preferably in the beginning of the module description, you add your prelude as a codeblock with a re prelude metastring. This will still render the codeblock like any other example, but in the testing script, it will do following extra tasks:

Also this PR fixes an issue with line number parsing / replacement when a syntax parse error occurs.

Fixes #55

nikgraf commented 4 years ago

@ryyppy my only concern is that most people probably won't read the Module description. So they might miss it an now copy & pasting the example will fail. We could add a small link/hint to the prelude the examples that use it, but not sure if it's too noisy.

fhammerschmidt commented 4 years ago

@nikgraf What if we had a copy button which always includes the prelude (when necessary)?

nikgraf commented 4 years ago

@fhammerschmidt I think it's a missleading UX if the copy button contains more than the actual visible text. (maybe that's the reason I also never use them and just select and copy text). If others do that as well they would miss out on the working example.

ryyppy commented 4 years ago

@nikgraf to think about it from a concrete perspective: If I would go ahead and copy the example for let's say, some Set function, and I get a compile error that the CmpInt module is missing, I'd probably go back to the docs page and CMD-F for said module and find the prelude example... I don't think it will cause many troubles (maybe we will get a lot of feedback, then we need to think about it anyways)