This one might be done quite easily by using include_str... but it would be a lot of repetitive lines, since highlight.js has tons of separate files with different language support. It could all be packed into one file and exported, but it would be a large file, with lots of stuff that would never be used.
Currently, the code knows which code languages are being used on the markdown page, so there's no issue in including just the right files. So an "easy" way to solve this issue is something like:
- Create a folder in
res with an import of highlight.js files.
- Create a hashmap, maybe with
lazy_static or once_cell with include_str lines for these.
- Package them up in a struct with a sensible interface to write these script files like we do here:
|
fs::write(output_path.join("main.js"), MAIN_JS). |
|
unwrap_or_else(|e| warn!("{}", e)); |
|
fs::write(output_path.join("main.css"), MAIN_CSS). |
|
unwrap_or_else(|e| warn!("{}", e)); |
|
fs::write(output_path.join("github.css"), GITHUB_CSS). |
|
unwrap_or_else(|e| warn!("{}", e)); |
An interesting, more complicated idea, might be to make this reusable, maybe even pull this concept into a separate crate. Something like an include_dir! proc macro that recursively reads the whole contents of a directory, and does the whole lazy-static hashmap setup above, it just doesn't require somebody to manually go over the individual files in the source. The hashmap that include_dir! spits out could be keyed by a Path. The contents might even be compressed like include_flate does, but that's a separate thing.
This one might be done quite easily by using
include_str... but it would be a lot of repetitive lines, since highlight.js has tons of separate files with different language support. It could all be packed into one file and exported, but it would be a large file, with lots of stuff that would never be used.Currently, the code knows which code languages are being used on the markdown page, so there's no issue in including just the right files. So an "easy" way to solve this issue is something like:
reswith an import ofhighlight.jsfiles.lazy_staticoronce_cellwithinclude_strlines for these.quickmd/src/assets.rs
Lines 88 to 93 in 9e09b02
An interesting, more complicated idea, might be to make this reusable, maybe even pull this concept into a separate crate. Something like an
include_dir!proc macro that recursively reads the whole contents of a directory, and does the whole lazy-static hashmap setup above, it just doesn't require somebody to manually go over the individual files in the source. The hashmap thatinclude_dir!spits out could be keyed by aPath. The contents might even be compressed likeinclude_flatedoes, but that's a separate thing.