Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect testRegex link in document #9169

Closed
tiendq opened this issue Nov 12, 2019 · 13 comments
Closed

Incorrect testRegex link in document #9169

tiendq opened this issue Nov 12, 2019 · 13 comments

Comments

@tiendq
Copy link
Contributor

tiendq commented Nov 12, 2019

🐛 Bug Report

testRegex link doesn't work in Configuring Jest document.

To Reproduce

Click testRegex option, both in main content and in sidebar.

Expected behavior

Jump to testRegex section.

@thymikee
Copy link
Collaborator

The hash should be #testregex-string-array-string. Sounds like an opportunity to contribute something to the docs :)

@tiendq
Copy link
Contributor Author

tiendq commented Nov 12, 2019

The hash should be #testregex-string-array-string. Sounds like an opportunity to contribute something to the docs :)

Yeah, it was easy to figure it out, will fix it this evening if no one want to take this tiny opportunity :D

@tiendq
Copy link
Contributor Author

tiendq commented Nov 12, 2019

@thymikee BTW (I know it's out of scope), are testRegex and testMatch identical options? is there any reason to keep both? A teammate reviewed my code a couple of hours ago and he thought using testMatch is simpler than testRegex though I didn't see his point.

@thymikee
Copy link
Collaborator

We plan to unify it: #7185

@tiendq
Copy link
Contributor Author

tiendq commented Nov 12, 2019

It turns out a bigger issue: all options with type[array] are broken because underlying markdown code [array<string>] isn't generated properly.

@MrMavin
Copy link

MrMavin commented Nov 12, 2019

It's something bigger than expected!

The table of contents section is generated by docusaurus by <AUTOGENERATED_TABLE_OF_CONTENTS> snippet. Here you'll find the documentation about this feature.

For some reasons, the generator is having troubles while parsing the titles.

Let me explain:

The heading ### `testRegex` [string | array<string>] is converted as

Text: testRegex [string | array]
Url: #testregex-string-array

But it should be

Text: testRegex [string | array<string>]
Url: #testregex-string-array-string

This means that we're having problems on <string> word. As you might imagine, the special characters < and > are the root issue.

I've tried to escape them, getting the following result:

Heading: ### `testRegex` [string | array\<string\>]
Text: testRegex [string | array<string>]
Url: #testregex-string-array

As you can see, the text is correct but the url is still wrong.

Of course, all the other links that are following the same logic aren't working as expected.

Any ideas?

@tiendq
Copy link
Contributor Author

tiendq commented Nov 12, 2019

@MrMavin You're right, I just looked into the code and figured it out too :)

@tiendq
Copy link
Contributor Author

tiendq commented Nov 12, 2019

@MrMavin One more casearray<string> is generated text [array] but array<string, string> is [array<string, string>]. Both cases are still incorrect links.

@MrMavin
Copy link

MrMavin commented Nov 12, 2019

Found out the problem.

By taking a look at the code responsible to generate the table of contents, which is this one, they're doing a striptags operation on the string before generating the url. This means that <string> is considered as an html tag, so it's removed from the output.

Please have a look at line 39.

For me, there are two solutions to this issue.

The first one is about sending a PR to the Docusaurus repository. I'm thinking about it because I don't know if it's a good idea. Mainly because they're working on version 2, which doesn't seem to implement such feature the same way, and because it's something that if changed it could break things in other projects.

The second one is about refactoring < and > by using HTML entities. <string> becomes &lt;string&gt;. Of course I've tested it and it's working as expected!

What do you think?

@tiendq
Copy link
Contributor Author

tiendq commented Nov 14, 2019

@MrMavin Since Docusaurus only mentions about code block it's not likely they will fix this issue. I think HTML entities is way to go.

@mayankmandloi
Copy link

mayankmandloi commented Nov 19, 2019

@MrMavin please correct me if I am wrong but don't we need to use <string> like text inside back-ticks `<string>` , here &lt; and &gt; will not be converted into < and > it will look like
jest
check the code here

@endiliey
Copy link
Contributor

its a bug that we've fixed

image

should close this

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants