Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/elsassph/roku-markdown

A simple markdown renderer for Roku
https://github.com/elsassph/roku-markdown

Last synced: about 2 months ago
JSON representation

A simple markdown renderer for Roku

Awesome Lists containing this project

README

        

# Roku markdown renderer

This is a **simple markdown renderer** for Roku apps written in [BrighterScript](https://github.com/rokucommunity/brighterscript).

![Screenshot of the markdown demo app](screenshot.png)

Parser and renderer support a subset of the markdown spec, and strip all inline styles.
The goal is to eventually support images between paragraphs.

There is currently no plan to support full text styling, but might consider tables.

Current support:

- titles, using `# Title` syntax
- paragraphs
- code blocks, using triple-tick or indentation
- quote blocks, using `> That quote`
- horizontal rules, using 3+ characters of `-=*`

## Installation

### Using ropm

```bash
ropm install roku-markdown
```

Suggestion: use a shorter prefix:

```bash
ropm install md@npm:roku-markdown
```

## Usage

See `demo.bs` in the repository sources for an example of usage.

*Following example use unprefixed installation. Replace `rokumarkdown_` with `md_` if you used the prefix as suggested.*

### 1. Declare a renderer view

```xml

```

You can redefine some/all the fonts and colors/alignments:
```xml



```

Full interface:
```xml




































```

**Paddings** are arrays of numbers following CSS rules:

- `[all]`
- `[top-bottom, right-left]`
- `[top, right, bottom, left]`

**Colors** are Roku RRGGBB or RRGGBBAA color string, e.g. `"#FFFFFF33"`

**Backgrounds** are:

- either Roku RRGGBB or RRGGBBAA color string, e.g. `"#FFFFFF33"`,
- or a custom Roku component; the size is provided through `size` field (`[width, height]`), and the text label is appended as a child (see demo).

**Alignments** are Label horizontal alignement values (`left|center|right`)

Titles after H4 are all rendered as H4.

### 2. Parse markdown source and render

**Vanilla BrightScript version**

```vbscript
parser = rokumarkdown_Parser()
data = parser.parse(markdownSrc)

view = m.top.findNode("markdownView")
view.callfunc("render", data)

' view is scrollable and can be focused
view.setFocus(true)
```

If you want an optimised non-interactive clipped render:

```vbscript
view.callfunc("render", data, false)
' view isn't scrollable anymore
```

**BrighterScript version**

```vbscript
parser = new rokumarkdown_Parser()
data = parser.parse(markdownSrc)

view = m.top.findNode("markdownView")
[email protected](data)

' view is scrollable and can be focused
view.setFocus(true)
```

If you want an optimised non-interactive clipped render:

```vbscript
[email protected](data, false)
' view isn't scrollable anymore
```

### 3. Render scrolling decorations

This component will not render a scrollbar:

- `overflows` tells whether the content is bigger than the view,
- you can observe `scrollFraction` to know the state of the scrolling,
- you can use `scrollRatio` to know how much of the content is visible VS hidden.

See the repository demo for an example rendering a scrollbar.

## Building from source

1. Install [NodeJS](https://nodejs.org)
2. install npm dependencies
```bash
npm install
```
3. Transpile to vanilla brightscript (under `/dist`)
```bash
npm run build
```

### Debugging

This repository comes pre-configured to work with the [BrightScript Language](https://github.com/rokucommunity/vscode-brightscript-language) extension for Visual Studio Code. So once you have that plugin installed, debugging your project is as simple as clicking the "Start Debugging" button.