0

I can include external source markdown into the binary with include_str!(),

static HOME: &'static str = include_str!("../content/foo.md");

With this my yew application reads

-rw-r--r-- 1 ecarroll ecarroll 111K Jun 14 19:58 ./static/wasm_bg.wasm

Now if I want to display that markdown as HTML, I can use the comrak module and call markdown_to_html. This does exactly what I want,

 use comrak;
 comrak::markdown_to_html(HOME, &comrak::ComrakOptions::default())

Event though HOME is static str this results in a 1.3M assembly (up from 111K`

-rw-r--r-- 1 ecarroll ecarroll 1.3M Jun 14 19:59 ./static/wasm_bg.wasm

Is there anyway in the language to push this calculation into compile-time and exclude all the comrak stuff from the runtime webassembly?

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • 4
    I didn't understand a thing but if you want build something at compile time look at build.rs – Stargateur Jun 15 '20 at 01:38
  • Yes, build a tool that converts the Markdown into HTML and then embed the resulting HTML into yoir binary (or better, load it from a file). – S.S. Anne Jun 15 '20 at 04:12

1 Answers1

1

You could use a build script (build.rs). The examples page lists "code generation" which you can probably adapt.

phimuemue
  • 34,669
  • 9
  • 84
  • 115