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

cli-static-render: Add option to cli to take an input and return the rendered html #854

Open
4 tasks done
Nova38 opened this issue Nov 29, 2024 · 0 comments
Open
4 tasks done

Comments

@Nova38
Copy link

Nova38 commented Nov 29, 2024

Clear and concise description of the problem

I want to be able to use shiki in non JavaScript project without having to render it in the client side. This would allow it to be used in non-javascript projects to generate static HTML that could then be inserted into The output of the other template engine/documentation tool.

To give an illustrative example: a lot of documentation is generated using the python (sphinx)[https://www.sphinx-doc.org] The highlighting that shiki provides is far better than alternative like pygments. It would be nice to be able to replace the highlighting it does with that of shiki.

If this feature sounds useful I would be happy to work on a pr implementing it

Suggested solution

I think that a good way to be able to achieve this would be to add the following features to either the existing cli package or create a additional cli package for just staticly rendering:

  1. specify the code to be highlighted
    a) a string of text via a flag or piped to stdin
    b) the path to a file
    c) the path to a folder of source files

  2. provide a way to specify the parameters passed to the codeToHtml function by
    a) passing in a json string or json file
    b) provide flags

    • it would potentially be more work to maintain to include all of the options, particularly if needed options are added to the codeToHtml function. In the case that that is more work than is desirable it could implement a sunset of the features, such as the theme and the language

This cli can then be called in another programing language or script by calling the cli with whatever language features they have for Interacting with cli application. For instance in python the subprocesses library.

Alternative

There are a few alternatives I have considered

  1. running a local web server that returns the code that is sent to it with the cdn import of shiki and a function to have it highlighted it on the client side. Then use a headless browser library like playwright to capture the rendered html. It would have to be a headless browser so that it could get the highlighted code after the js runs.
  • pros:
    • only have to manage dependencies/runtimes in one language
  • cons:
    • convoluted
    • potentially required internet access, unless the cdn response is cached
    • headless browsers are a bit overkill and take more resources than should be needed for this use case.
  1. host a node server that returns the rendered result.
  • pros:
    • simple
  • cons:
    • requires multiple packages managers to be used in the same project. (Instead of either globally installing a cli or using no...)
    • packaging it so that others can use or run the project is more complicated

Additional context

No response

Validations

Contributes

  • If this feature request is accepted, I am willing to submit a PR to fix this issue
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

No branches or pull requests

1 participant