[][src]Struct aurelius::Server

pub struct Server { /* fields omitted */ }

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.

Methods

impl Server[src]

pub fn bind(addr: impl ToSocketAddrs) -> Result<Self>[src]

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.

pub fn addr(&self) -> SocketAddr[src]

Returns the socket address that the server is listening on.

pub fn send(&mut self, markdown: String) -> Result<()>[src]

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.

pub fn set_static_root(&mut self, root: impl Into<PathBuf>)[src]

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.

pub fn set_highlight_theme(&mut self, theme: String)[src]

Set the highlight.js theme used for code blocks.

Defaults to "github".

pub fn set_custom_css(&mut self, stylesheets: Vec<String>) -> Result<()>[src]

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.

pub fn set_external_renderer(&mut self, command: Command)[src]

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);

pub fn open_browser(&self) -> Result<()>[src]

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

pub fn open_specific_browser(&self, command: Command) -> Result<()>[src]

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

Trait Implementations

impl Debug for Server[src]

impl Drop for Server[src]

Auto Trait Implementations

impl !RefUnwindSafe for Server

impl Send for Server

impl Sync for Server

impl Unpin for Server

impl !UnwindSafe for Server

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,