-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Integrating highlight.js
with CRM eaxmple
#1073
Comments
Hey @shivshankardayal, good question! If you're using Since Yew is similar to React, you can see how highlight.js works with React. See this example: https://github.com/bvaughn/react-highlight.js/blob/master/src/Highlight.js#L20 You will want to call I would really like if you added highlight.js to the CRM example so that others can learn too, thank you! |
I am still a noob but I will try to do that. |
@jstarry How to build |
@shivshankardayal check out how to use features here: https://doc.rust-lang.org/cargo/reference/features.html There are instructions in the examples/README.md here: https://github.com/yewstack/yew/blob/8edf136da6ba1955c847c5860ec55623a27c08e9/examples/README.md#running-the-examples Here's how you specify in Cargo.toml:
|
@jstarry Thanks a lot. I went through |
Nice! So you want to add syntax highlighting to static html instead of apply it dynamically in the browser? |
No I want a Webassembly library of |
I see, why do you want to rewrite |
It is just a purist approach. Also, it will help gain momentum for webassembly. |
Excellent, looking forward to it 👍 |
Hi, @shivshankardayal, I also need a static highlight. How about syntect, it can be used as following: use syntect::parsing::SyntaxSet;
use syntect::highlighting::ThemeSet;
use syntect::html::highlighted_html_for_string;
use yew::Html;
fn highlight_html(s: &str) -> String {
let ss = SyntaxSet::load_defaults_newlines();
let ts = ThemeSet::load_defaults();
let syntax = ss.find_syntax_by_token("rs").unwrap_or_else(|| ss.find_syntax_plain_text());
highlighted_html_for_string(&s, &ss, syntax, &ts.themes["base16-ocean.dark"])
}
pub fn highlight_vdom(s: &str) -> Html {
let div = yew::utils::document().create_element("div").unwrap();
div.set_inner_html(highlight_html(s));
Html::VRef(div.into())
} A better way is to re-implement the ast transformation, which can bring greater flexibility |
@GalAster, using
This will increase your WASM binary size by around 2MBs for no good reason (loading unused syntaxes and themes). You should be only loading what you need (see: trishume/syntect#135 (comment)) Also, |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Question
How can I integrate with
highlight.js
for syntax highlighting withpulldown_cmark
in CRM example?The text was updated successfully, but these errors were encountered: