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

TOC output when invoking markdown2 as a command through CLI #279

Closed
TomasHubelbauer opened this issue Nov 10, 2017 · 13 comments
Closed

TOC output when invoking markdown2 as a command through CLI #279

TomasHubelbauer opened this issue Nov 10, 2017 · 13 comments

Comments

@TomasHubelbauer
Copy link

Hey I have installed markdown2 using PIP in one of my Docker images and I can invoke it like this: markdown2 input.md > output.html, but I am not able to use markdown2 as a command on Windows nor on WSL when installed through PIP for some reason.

Is there any info on using the TOC extra through CLI? I ran the same script with the TOC extra in my CI pipeline with the Docker image where I am able to invoke markdown2 as a command and pipe the output to a file and it didn't get embedded into the file, so I suppose I can only wrap the invocation in a Python script and write the files myself?

@nicholasserra
Copy link
Collaborator

Looks like the CLI is working for linux for me. With -x you can pass extras.

Sounds like you have two issues:

  1. CLI isn't working on windows
  2. Problem running an extra via CLI in docker?

Let me know if -x gets you going to fix the second issue.

@TomasHubelbauer
Copy link
Author

TomasHubelbauer commented Nov 10, 2017

@nicholasserra I can run this from CLI on the host where I need that capability so it's cool and I don't mind the other machines, but since I am running it from CLI (with -x) there I can't get ahold of the TOC extra there because the TOC HTML gets added to a property on the resulting string when used as a module and there is no such concept when piping this to a file if you know what I am.

When piping the markdown2 output, it's just text, so I can't grab the TOC HTML. So I am curious is there a way that I am just missing or is this really not accessible in any way except from wrapping it in a script and writing both the HTML and the TOC HTML separately myself from Python?

@nicholasserra
Copy link
Collaborator

Gotcha. I wouldn't be surprised if it were not thought out appropriately for CLI use. I'll give it a run and see what I come up with.

@TomasHubelbauer
Copy link
Author

TomasHubelbauer commented Nov 10, 2017

@nicholasserra Thanks! I am using it in a script like this which is super neat right now without a need for a wrapper script so before I get writing one I am just curious if I need to.

@nicholasserra
Copy link
Collaborator

So from what i'm seeing that toc html isn't accessible in any way. I can't really think of a good way to even expose it to the CLI. Maybe it could take some kind of path as an input and then write the file to disk. Not sure, feels kinda dirty. Let me know if you have any ideas.

@TomasHubelbauer
Copy link
Author

Do you think it could inject the TOC HTML into the MD HTML? Perhaps with a placeholder to control where or just default to prepending? This should be opt-in when used as a Python module but default in CLI mode (distinguishable?)

@nicholasserra
Copy link
Collaborator

Assuming CLI vs module is distinguishable, we would need some kind of argument to pass into the CLI to turn on the appending. I'm concerned about cluttering up that space. But if it can be done cleanly i'd probably accept it.

Take a peek at:
https://github.com/trentm/python-markdown2/blob/master/lib/markdown2.py#L393

There's basically just a wrapper around unicode that adds the toc_html property. I could see the append happening there.

@nicholasserra
Copy link
Collaborator

nicholasserra commented Nov 13, 2017

I don't want to default to appending in CLI to maintain backwards compat.

@TomasHubelbauer
Copy link
Author

I'll take a stab at that. I understand the concern about backwards compatibility when using the TOC extra with a CLI, but that is practically a no-op currently (the extra is executed, but you can't reach it) so I think the few people who are using this extra with a CLI probably just added it thinking it would get embedded within the output HTML, found it doesn't and did not remove it. I will of course honor this though and design a CLI switch or maybe a new inline-toc extra if it ends up making more sense.

@TomasHubelbauer
Copy link
Author

Check my PR @nicholasserra. I'm so glad WSL is a thing, because I was able to develop it on Windows using VS Code but compile it and run the script in WSL with build-essential, because currently the repository doesn't seem to be cross-platform.

@TomasHubelbauer
Copy link
Author

This should be closed once #283 is merged.

@nicholasserra
Copy link
Collaborator

Fixed in #283

@nicholasserra
Copy link
Collaborator

I'll probably wait for a couple more fixes to land before next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants