Integrating highlight.js
with CRM eaxmple
#2101
Replies: 12 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! |
Beta Was this translation helpful? Give feedback.
-
I am still a noob but I will try to do that. |
Beta Was this translation helpful? Give feedback.
-
@jstarry How to build |
Beta Was this translation helpful? Give feedback.
-
@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: |
Beta Was this translation helpful? Give feedback.
-
@jstarry Thanks a lot. I went through |
Beta Was this translation helpful? Give feedback.
-
Nice! So you want to add syntax highlighting to static html instead of apply it dynamically in the browser? |
Beta Was this translation helpful? Give feedback.
-
No I want a Webassembly library of |
Beta Was this translation helpful? Give feedback.
-
I see, why do you want to rewrite |
Beta Was this translation helpful? Give feedback.
-
It is just a purist approach. Also, it will help gain momentum for webassembly. |
Beta Was this translation helpful? Give feedback.
-
Excellent, looking forward to it 👍 |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
@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, |
Beta Was this translation helpful? Give feedback.
-
Question
How can I integrate with
highlight.js
for syntax highlighting withpulldown_cmark
in CRM example?Beta Was this translation helpful? Give feedback.
All reactions