Skip to content
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

Add Rust Markdown parser tutorial #181

Closed
wants to merge 2 commits into from
Closed

Conversation

rita3ko
Copy link
Contributor

@rita3ko rita3ko commented Aug 21, 2020

To do:

  • Get it running 😅
  • Add missing images

@rita3ko rita3ko marked this pull request as ready for review September 12, 2020 19:10
Copy link
Contributor

@kristianfreeman kristianfreeman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@rita3ko rita3ko changed the title Add Rust Markdown parser tutorial [wip] Add Rust Markdown parser tutorial Sep 16, 2020
@adamschwartz
Copy link
Contributor

I’d like to see us take a pass at making it a bit more consistent with the other tutorials. For example how we handle prereqs and also using code block frontmatter for filenames, etc.

Copy link
Contributor

@adamschwartz adamschwartz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see suggested changes below. I expanded on my previous comment with some links to the Docs Engine docs which hopefully makes things a bit clearer!

---

# Build a Markdown Parser with Rust and WebAssembly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s add a "Before you start" section here, like we do in the other tutorials:

import TutorialsBeforeYouStart from "../../_partials/_tutorials-before-you-start.md"

# Build a Markdown parser with Rust and WebAssembly

<TutorialsBeforeYouStart/>

<!-- ... -->

(Note: “parser” also lowercased.)

difficulty: Advanced
---

# Build a Markdown Parser with Rust and WebAssembly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“Parser” → “parser”

In the command line, generate your Workers project by passing in a project name (we'll use rustwasm-markdown-parser), and the template URL to base your project on.

```sh
wrangler generate rustwasm-markdown-parser https://github.com/cloudflare/rustwasm-worker-template/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefix line with at least $. See https://docs-engine-docs.adam.workers.dev/markdown#terminals for examples. If it’s a series of steps requiring a specific set of directors, prefix with ~/ $ to start and then after e.g. cd-ing into rustwasm-markdown-parser, prefix with ~/rustwasm-markdown-parser $ etc.

You can test how your Workers function will look when it's deployed by using the preview service, which you can access with the `wrangler dev` command:

```sh
wrangler dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per previous, should be:

~/rustwasm-markdown-parser $ wrangler dev

Since it’s required that you be in the project directory for wrangler dev to work.


[`wrangler dev`](/cli-wrangler/commands#dev) starts a server on localhost that executes your Worker on incoming HTTP requests. By default, it'll listen on port :8787.

<Aside>The first time you run `wrangler dev` might take a couple minutes to compile to WebAssembly. </Aside>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be on separate lines for parsing:

<Aside>

The first time you run `wrangler dev` might take a couple minutes to compile to WebAssembly. 

</Aside>

See https://docs-engine-docs.adam.workers.dev/markdown#asides

Comment on lines +49 to +54
```toml
## Cargo.toml

[dependencies]
pulldown-cmark = "0.4.0"
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use filenames feature (see https://docs-engine-docs.adam.workers.dev/markdown#filenames):

```toml
---
filename: Cargo.toml
---
[dependencies]
pulldown-cmark = "0.4.0"
```

our `src/lib.rs` to look like this:

```rust
// src/lib.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use filenames feature of code blocks (see https://docs-engine-docs.adam.workers.dev/markdown#filenames).

`dev` or `publish`, you can run the `build` command:

```sh
wrangler build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~/rustwasm-markdown-parser $ wrangler build

To preview this code in the browser, and get runtime errors in your terminal, you can run:

```sh
wrangler dev
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~/rustwasm-markdown-parser $ wrangler dev

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

Successfully merging this pull request may close these issues.

None yet

3 participants