-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow online version to read from URL params/hash to set various options + markdown text #59
Comments
Hello @0xdevalias, happy to hear you enjoy this tool 😊 and thank you for this proposal. There is no difficulty loading options from the hash (I just did a proof of concept). However, I would avoid the markdown text as it will most of the time exceed the maximum length of a URI, and I fear some markdown content may be corrupted when URL-encoded/decoded. I am also wondering about the design:
I would love to have your opinion on this! Also, could you please expand on your use case and workflow? Is there a reason not to use the command line? |
I made a first proposal that will read the options from the hash on load, and update the hash only upon generate. Would this fit your need? A review is welcome :) |
@derlin For my usecase, the markdown content itself is probably the main thing I am interested in; being able to pass through the other settings was a bit of an afterthought. I'm not 100%, but I believe that other projects may have worked around the 'max length of URL' is specifically by using the hash portion (that isn't sent to the server), rather than the actually GET params. I haven't tested to see if/how large is actually supported in the hash though, so maybe that is a wrong assumption on my part.
@derlin Hrmm, good question. For 1, I am sort of 50/50 on it.. on one hand I could see how someone would expect their already saved defaults to be used as the 'base', and then apply the URL params as overrides on top of that; but on another hand I can see how someone might expect the settings passed in the URL to be applied consistently, regardless of what was configured in localstorage. Given that I would sort of expect the people who would end up using URLs with settings in them to be much lower, and the fact that if they really wanted to they could just apply all the settings in the URL, I think I would personally opt for "if settings are present in the URL, then they override the saved localStorage settings for that session, but aren't persisted to localStorage". For 2, I don't have strong opinions on this one, but given I would expect this to be more of a niche feature, maybe the button to copy options to URL is a good balance of "provide the option for the advanced functionality, but stay out of the way when people don't need it"?
@derlin My most recent thoughts/use case that led to this issue was wanting to create an Alfred 'universal action', so that the highlighted/passed through text could be opened in the browser version of this tool:
While I haven't thought about it too deeply, I think one of the reasons I was opting for the browser version in this instance is just because that matches my current manual workflow for it. I think another reason that I was thinking of avoiding the CLI version in this instance was that I wanted to keep the Alfred workflow 'independent of external dependencies', and not need to rely on externally installing the CLI tool, or needing to package it together. Since it's a personal workflow though, I don't know how much either of those really matters in reality. I could also conceive of usecases where the website supporting it could allow for bookmarklets or similar that could operate in a system independent way; where I wouldn't have the option for using a CLI version; but I admit we're getting into contrived theoretically territory now, and I'm not sure I would practically end up using it much in that way.
@derlin I left a comment on that PR pointing back to this comment, as I think some of what I provided above sort of answers this question. |
This was one tool that I was thinking of that stores settings in the URL hash; though I thought it also saved the 'input' to it, which doesn't seem to be the case: https://gchq.github.io/CyberChef/#recipe=URL_Encode(false)&oenc=65001 But as a test of length, I took all of the raw markdown from one of my larger gists: URL encoded it with Cyber Chef, which ended up being 228,576 characters long: And then manually pasted it as a hash to a URL in Chrome, which I then read back from JavaScript with Though interestingly if I then tried to edit the URL manually, there is a Digging a little deeper, I found this:
Also this:
@derlin Yeah, that is a good point. I didn't really think it through all that deeply when I first suggested URL Encoding it; I think some other things I have seen that use it for more 'arbitrary data' like this probably base64 encode it instead. |
@0xdevalias Thank you for all this information! The more I think about it, the more "hacky" it seems. The hash length and how it is processed differently by multiple browsers... What you would need is a real API. However, This is impossible now, as the website is purely static and hosted on GitHub. I just changed the domain so that it may be possible in the future to migrate to something like divio and add new/non-static features. In the meantime, can you give the CLI a go? (note that an API would be easy to develop with the bitdowntoc CLI: a simple web server calling it in the background and returning the output). I will see what I do with the PR. This is a nice addition, but I am not sure it will be used and I would like to avoid maintaining "dead" features. And as I understand, you would not use it either, right? (Good points about the loading of the settings though, thanks!) |
@derlin Yeah, that's fair enough. A real API was definitely what I was hoping for when I first started looking at this.
@derlin Yeah, I'll try and get it setup in my Alfred workflow when I next get a chance to fiddle with it; and let you know how I go with it.
@derlin Totally understandable. Yeah, I think the main part I would be interested in is being able to pass through the markdown itself. While there is variation among browsers, most of them seem to be quite high thresholds; so I wonder if it would end up being much of an issue in reality? Maybe as a 'power user' type feature? I feel like there are sort of less edgecases in supporting the markdown passthrough than even the settings part; as you could essentially just have it decode the markdown from the hash and then add it to the 'paste markdown here' text box; and wouldn't need to worry about if/how that interacts with the local saved settings. |
Finally got a chance to look at this again, and created the following workflow in Alfred, using a 'Universal Action': The The first 'Run Script' block calls the # Passes the query into bitdowntoc to generate the Markdown Table of Contents, then uses sed to change the URL in the comment + remove the extra lines of spacing
cat <<< "$1" \
| bitdowntoc --profile=GITHUB --indent-spaces=2 --indent-chars=- - \
| gsed -zE '
# Replace the old URL with the new one
s|(<!-- TOC start[^>]*)https://github.com/derlin/bitdowntoc([^>]*>)|\1https://bitdowntoc.derlin.ch/\2|g;
# Remove extra blank line after <!-- TOC start ... -->
s|(<!-- TOC start[^>]*>)\n\n|\1\n|g;
# Remove extra blank line before <!-- TOC end ... -->
s|\n\n(<!-- TOC end[^>]*>)|\n\1|g
' This is the second 'Run Script' block, which extracts just the Table of Contents from the output: cat <<< "$1" | sed -n '/<!-- TOC start/,/<!-- TOC end/p' It could be cool if the CLI supported a 'Table of Contents only' output mode, which would remove the need for the second post-processing script; but all in all, this seems like it should work for my needs pretty well. |
@0xdevalias bitdowntoc now supports the TOC only option 😊. Already live on the Web, will be on the cli in the next release. Let me know what you think a(nd if we can close this issue). |
@derlin Checked the web version and it seems to work well. If I was nit picking I'd say the style of the button doesn't stand out great, but aside from that, all good.
Given earlier discussions around how the full markdown in URL hash seems infeasible, that it's not possible to have an API currently, and that the CLI version + alfred workflow has solved my original needs/want for asking for this, I think it's probably fine to close this issue as |
I tend to use the online hosted version of this tool a lot:
And I was thinking it would be cool if we were able to pass through various options + the markdown text through URL parameters and/or hash. That way I could configure a local shortcut to open the URL with the markdown text pre-filled/etc.
I think there might be limits to the amount of text that can be included in a GET param, so for the markdown text itself, it might make sense to use the hash for that instead maybe?
As an example, something like:
Which would set the specified options and prefill the following markdown:
The text was updated successfully, but these errors were encountered: