-
-
Notifications
You must be signed in to change notification settings - Fork 882
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
Add fix backtick code block module #5441
base: master
Are you sure you want to change the base?
Add fix backtick code block module #5441
Conversation
Problems:
|
hmm. The regex wasn't the problem. It works on some things, but not always. textContent is very crappy, maybe parsing the json does make more sense. |
That appears only to exist if you wrote the comment I think? Or doesn't exist on a fresh browser in any case |
Ah good call. It appears when you click Sounds like json could work. Do you have a way to grab it from your code? |
Just need to find the correct link, just adding |
…down and it works
Got it working. I don't know exactly what the code is doing still to be honest, but it works for both comments and posts. It doesn't work for post previews in a normal subreddit. Unsure why exactly, it seems |
You can add
Nice! How do I test it out, do I need to do the setup from CONTRIBUTING.md? |
Go to my repo, clone it,
then install the folder from Or using chrome, don't pass in |
Presently it only works on comment pages. I am investigating and it seems that on a subreddits main page (example: Then when you expand it, in the |
It's working! Woo! |
It doesn't work for styled code blocks, i.e.:
Displays as
When it should display as console.log('test'); |
Dang. I knew I shouldn't trust regexes from random people which I don't understand |
Some ideas:
|
|
Any particular reason to avoid dependencies? |
Not my project, I'm just a random dude coming into it. If a dependency should be added that would probably have been brought up by more experienced maintainers discussing this. Anyway, its not the regex's fault, it's that reddit changes
|
Aside: I don't see any reason why we'd need maintainer approval for that; they don't mention it in CONTRIBUTING.md either. That said, I'm happy to leave it alone since this is still a major improvement. Also this regex should handle styled code blocks: |
The current regex is fine - it accepts anything already. The trouble was as I described above. I pushed - you'll note though that multiple code blocks in a row look like trash. I will see what I can do about that. |
Hmm. backticks in four-space code lines are messed up by the regex. I am more and more tempted to just line-by-line parse it as in my first prototype. |
Nice job on the styled MD fix. Seems to match Github's markdown implementation. |
If I understand correctly, you'd like this:
to display as
(minus periods) ? |
Yes. Look at how new reddit renders my comment |
I see. How about enforcing that backticks must start at the beginning of a line?
|
I do think that would be a good idea. I think I tried that regex in the past, but before anything worked, so it slipped my mind. |
Alright. It still does not render everything exactly the same as new reddit, but it seems to be related to behavior of triple backticks becoming single backticks by snudown, not anything I'm doing, which no one uses anyway, so should be fine. And/or is related to new reddit not requiring closing code fence which is a mistake on reddit's part, so I don't care. |
Another option is to only block the case where backticks are preceded by 4 spaces.
This one might be better since it doesn't break things like:
|
Not sure - whatever's more consistent is better I guess. |
That shouldn't be a code block.
I mean commonmark has so many backwards compatibility rules and weird things anyway that what it says isn't exactly too important, but there is no way that should become a code block. |
For example, I do not care that a code fence may be preceded by up to 3 spaces of indentation. |
Okay I think I'm happy now, going to wait to see what someone who can merge this thinks. @honestbleeps ? |
In terms of efficiency: If you visit a thread with 500 comments with code blocks, you'd make 500 ajax requests. That doesn't seem okay. Step 1: Since the HTTP request returns data for a ton of comments, why don't we cache all that data and re-use it later? Step 2: We could add an async mutex to prevent parallel requests. |
Good point. The http request only returns data for 1 comment though, it is limiting it to 1 somehow which is how it always gets the right one. I think, if that is wrong oops. But a mutex sounds like a good idea then |
Iirc the request returns data for a bunch of child comments too, the data is tree shaped. |
Is there any hope to see this merged one day? At this point I'd be OK with the performance hit if it's an opt-in feature. Threads with a huge amount of code blocks are rare anyway, and they won't all be loaded at the same time. |
Please. It's been two years. Add it as an opt-in, completely gut it and just transform any triple-backticks to code tags, I don't care, I have infinite data. The code is right there, it works, it's inefficient, but I want it on my computer without having to custom build RES. |
This PR is incomplete, if you want it merged feel free to raise a new one with the actions completed. We are not going to add a half-complete feature on a project thats KTLO. |
Is the only pending issue the one about performance (sending too many ajax requests)? If so, I'm willing to work on this. |
fixes #5223
One of the greatest pains to using old reddit ever