-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
tools: improve heading type detection in json.js #20074
Conversation
This comment has been minimized.
This comment has been minimized.
cc @nodejs/documentation PTAL I understand that this file is rather not very well researched domain, but the change does not require the familiarity with all the md-2-JSON tooling chain: it is just a refactoring of some RegExps that are used to parse well-known heading types in our API docs, so it can be reviewed without any broader context. |
tools/doc/json.js
Outdated
// To reduse escape slashes in RegExp string components. | ||
const r = String.raw; | ||
|
||
const eventPrefix = r`^Event:\s+`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for \s
? I mean, can there be tabs or new lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I do not think there can be. Do you mean it would be better to use '^Event: +'
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in the fixup commit.
|
||
// To include constructs like `readable\[Symbol.asyncIterator\]()` | ||
// or `readable.\_read(size)` (with Markdown escapes). | ||
const simpleId = r`(?:(?:\\?_)+|\b)\w+\b`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is (?:\\?_)
repeated? Is something like _\__\_
possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have __filename
and __dirname
, so I've thought this was possible.
tools/doc/json.js
Outdated
const classMethodPrefix = r`^Class Method:\s+`; | ||
const maybeClassPropertyPrefix = r`(?:Class Property:\s+)?`; | ||
|
||
const maybeQuote = '[\'"]?'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use `
to avoid escaping?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried, but ESLint throws. It seems this rule does not suffice for this:
Line 217 in 2060787
'quotes': ['error', 'single', { avoidEscape: true }], |
We need "allowTemplateLiterals": true
and maybe I will file a PR with this very case if this is landed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I thought such PR would be a small one) #20214
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
@lpinca Thank you a lot for the review. I will land soon if there are no objections from anybody as I think we may get no more reviews for this. |
I really appreciate all the work you are doing with the docs. |
Landed in 7fcb52c |
PR-URL: #20074 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
PR-URL: #20074 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesIt appears that heading type detection in
tools/doc/json.js
is not accurate because some RegExps are too narrow and some are too wide. Maybe some mean an older source state.This is an incomplete list of examples of false-positive and false-negative results:
Constructor:
prefix or class parent object):I've tried to make RegExp more accurate, but they became more and more complicated, so I've decided to build them from smaller string components so that the final RegExps were more self-explanatory.