pub struct Server { /* private fields */ }
Expand description

Markdown preview server.

Listens for HTTP connections and serves a page containing a live markdown preview. The page contains JavaScript to open a websocket connection back to the server for rendering updates.

Implementations

Binds the server to a specified address.

Binding on port 0 will request a port assignment from the OS. Use addr() to query the assigned port.

Returns the socket address that the server is listening on.

Publish new markdown to be rendered by the server.

The new HTML will be sent to all connected websocket clients.

Errors

This method forwards errors from an external renderer, if set. Otherwise, the method is infallible.

Set the directory that static files will be served from.

This can be thought of as the “working directory” of the server. Any HTTP requests with non-root paths will be joined to this folder and used to serve files from the filesystem. Typically this is used to serve image links relative to the markdown file.

By default, the server will not serve static files.

Set the highlight.js theme used for code blocks.

Defaults to “github”.

Set custom CSS links and files to be served with the rendered HTML.

Accepts URLs and absolute paths. URLs will be inserted as <link> tags. The contents of the paths will be read from disk and served in <style> tags.

Set an external program to use for rendering the markdown.

By default, aurelius uses pulldown_cmark to render markdown in-process. pulldown-cmark is an extremely fast, CommonMark-compliant parser that is sufficient for most use-cases. However, other markdown renderers may provide additional features.

The Command supplied to this function should expect markdown on stdin and print HTML on stdout.

Example

To use pandoc to render markdown:

use std::process::Command;
use aurelius::Server;

let mut server = Server::bind("localhost:0")?;

let mut pandoc = Command::new("pandoc");
pandoc.args(&["-f", "markdown", "-t", "html"]);

server.set_external_renderer(pandoc);

Opens the user’s default browser with the server’s URL in the background.

This function uses platform-specific utilities to determine the browser. The following platforms are supported:

PlatformProgram
Linuxxdg-open
OS Xopen -g
Windowsexplorer

Opens a browser with a specified command. The HTTP address of the server will be appended to the command as an argument.

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.