-
Notifications
You must be signed in to change notification settings - Fork 711
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
support regions in @includeCode #2816
base: master
Are you sure you want to change the base?
Conversation
Yes, this seems reasonable. Might want to split the logic out into its own function at this point.
Is there any case in which this would be a better option than using a region? It seems like an objectively worse UX to me... |
I'll probably be extracting a function to its own file for this, indeed.
Agreed. I'm just thinking of the case where you want to include code from a file you don't control or in which you can't add comments to define regions (think JSON, for example, which does't support comments). In this case the line-numbers seem like the only text-based approach (as opposed to using a language-aware AST) that could work… Can I let you decide if it's worth including? |
Ah, that's a very fair point, line numbers is probably worth it at some point |
The holidays are over so I'm back at it Today, but I think I already made a mistake. I tried pulling the latest changes before pushing mine but this PR is still showing more than my own changes… I'm not sure how to make the PR clean from here… Help? Other questions and comments about my actual code changes:
Thanks for any and all feedback. Looking forward to wrapping this up and marking it ready for official review and eventual merging :) |
Not exactly sure how this happened... it looks like some kind of rebase gone wrong as Git thinks you went and modified every commit. If you run
This is fine, I usually toss new ones into https://devina.io/redos-checker to check
This looks pretty reasonable to me, I'm considering going the same route as TypeScript for these names someday which will make them automatically generated, but for now it makes sense. The names are completely subject to change anyways.
It looks like I didn't write unit tests specifically for this as they were used in TypeDoc's site so effectively tested there. There's a test that was added later (search for 2800 in issues.c2.test.ts)
Don't worry about adding translations, they'll just use English until someone who speaks other languages natively adds a translation.
I probably would have left the region tag regexes in the IncludePlugin file, fine where they are though. I tend to only split things out to other files if they are useful in more than one place.
Looks fine to me! I'll take a closer look at the code tomorrow, off to spend more time with family :) |
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.
Apologies for the delay here! Time has a way of slipping away... not going to merge this weekend either, but it's first on my list for next weekend. This is looking really good to me. I especially like the changes you made to the docs! It seems to work well in the playing around I've done so far.
const regionTagsList = regionTagREsByExt[ext]; | ||
let found: string | false = false; | ||
for (const [startTag, endTag] of regionTagsList) { | ||
const start = text.match(startTag(target)); |
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 should regex-escape target
here, there's an escapeRegExp
function in src/lib/utils/general.ts
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.
Good point. Done in my latest commit.
No worries @Gerrit0, I am in no rush :) About the conflicts in CHANGELOG.md, do you want me to remove my changes to the changelog or merge and fix or anything else? |
I can fix it when merging :) I'll probably look at making a few unit tests as well |
I finally got around to pulling this down, writing some unit tests, and just playing with it. Found a couple issues, but it's all merged to my |
@Gerrit0 hey, please don't make a release yet, I'd like to include the sidebar changes as well, since it might change some selectors again, and I don't wanna get cursed by theme maintainers for repeated breaking changes |
... shoot, I forgot about themes, there were only two custom ones for 0.27 published last I looked, neither of which would have been affected by your changes. Now it looks like there are more which will be affected, so that rewrite will have to come with a minor version bump. |
Alright, and btw, it won't be a rewrite. I'll just put the sidebar in a dialog. |
WORK IN PROGRESS / DO NOT MERGE
This is a proof of concept for supporting regions in
@includeCode
tags, meaning you could insert part of a file as a code block by referencing a region of that file.Example
sourceFile.ts
documents/some-page.md
Here is an example: {@includeCode src/sourceFile.ts#regionName} This is useful for reasons.
output:
Here is an example:
This is useful for reasons.
Notes
@includeCode
tag reference #2814@Gerrit0 if this basic strategy seems OK, I would add the following to this PR before merging:
TO DO
//#region NAME
instead of// #region NAME
)@include
tag as wellsite/tags/include.md
/example
)Thoughts? Questions? Advice?
Updates