Skip to content
This repository was archived by the owner on Feb 15, 2022. It is now read-only.

Implement code highlighting #137

Closed
ghost opened this issue Mar 11, 2021 · 10 comments
Closed

Implement code highlighting #137

ghost opened this issue Mar 11, 2021 · 10 comments
Assignees

Comments

@ghost
Copy link

ghost commented Mar 11, 2021

  • Perform a spike to understand how to use highlight.js and how to integrate highlight.js with React. Consult the rescript-lang.org implementation.
  • ...

Note: The list of tutorials has not been finalized. Assume that all tutorials will be ported over for now.

@agarwal agarwal assigned ghost Mar 11, 2021
@agarwal
Copy link
Member

agarwal commented Mar 11, 2021

@avsm Recommended highlight.js.

@ghost
Copy link
Author

ghost commented Apr 27, 2021

Here's one initial hit for integrating highlighting with React elements: https://github.com/wooorm/lowlight .

@ghost
Copy link
Author

ghost commented Apr 28, 2021

Here is the essential of rescript-lang.org's implementation:

@bs.deriving(abstract)
type highlightResult = {value: string}

@bs.module("highlight.js/lib/core")
external highlight: (~lang: string, ~value: string) => highlightResult = "highlight"

let renderHLJS = (~highlightedLines=[], ~darkmode=false, ~code: string, ~lang: string, ()) => {
  let (lang, highlighted) = try (lang, highlight(~lang, ~value=code)->valueGet) catch {
    ...
  }

  <code
    className={"hljs lang-" ++ (lang)}
    dangerouslySetInnerHTML={"__html": highlighted}
  />
}

@ghost
Copy link
Author

ghost commented Apr 29, 2021

I'm leaning towards using rehype-highlight which wraps lowlight. I believe rescript-lang.org uses highlight.js directly, instead of using rehype-highlight because their rendering of markdown files uses mdxjs and it is simpler to override rendering just code blocks using a single library, rather than using a rehype based wrapper and rewriting the internals of mdxjs to make use of rehype-highlight. Alternative, rescript-lang.org could have used the rehype-plugins options when using mdxjs. I'm not sure why that wasn't used.

@ghost
Copy link
Author

ghost commented Apr 29, 2021

There are a few different highlighting implementations. highlight.js is popular and has been successfully used by others, so we will use that for now. It's also convenient that people have implemented wrappers for highlight.js like lowlight.

@ghost ghost mentioned this issue Apr 29, 2021
@ghost
Copy link
Author

ghost commented Apr 29, 2021

Perform a spike to understand how to use highlight.js and how to integrate highlight.js with React. Consult the rescript-lang.org implementation.

This was done in #313 , as well as implementing an MVP of this highlighting.

@ghost
Copy link
Author

ghost commented Apr 29, 2021

The styles are very simple for now. We can tweak them later before going public.

@ghost ghost closed this as completed Apr 29, 2021
@ghost ghost reopened this Jun 24, 2021
@ghost
Copy link
Author

ghost commented Jun 24, 2021

This is being removed, and can be closed again once the implementation is complete in ood.

@ghost ghost assigned tmattio Jun 25, 2021
@rdavison
Copy link
Contributor

Code highlighting is now being done in Ood, therefore it is no longer relevant here.

@ghost
Copy link
Author

ghost commented Sep 9, 2021

@patricoferris Please create an issue in ood to keep this remaining task visible.

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

No branches or pull requests

3 participants