0.2.2 • Published 3 years ago

roku-markdown v0.2.2

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Roku markdown renderer

This is a simple markdown renderer for Roku apps written in BrighterScript.

Screenshot of the markdown demo app

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

ropm install roku-markdown

Suggestion: use a shorter prefix:

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

<rokumarkdown_Renderer id="markdownView" />

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

<rokumarkdown_Renderer id="markdownView" color="#FFFFCC" h1Align="center">
    <Font role="font" uri="pkg:/fonts/Ubuntu_Regular.ttf" size="24" />
    <Font role="h1Font" uri="pkg:/fonts/Ubuntu_Bold.ttf" size="48" />
    <Font role="h2Font" uri="pkg:/fonts/Ubuntu_Bold.ttf" size="36" />
</rokumarkdown_Renderer>

Full interface:

<interface>
    <field id="width" type="int" />
    <field id="height" type="int" />
    <field id="padding" type="array" />
    <field id="itemSpacing" type="int" />
    <field id="font" type="node" />
    <field id="color" type="string" />
    <field id="align" type="string" />
    <field id="quoteFont" type="node" />
    <field id="quoteColor" type="string" />
    <field id="quoteAlign" type="string" />
    <field id="quotePadding" type="array" />
    <field id="quoteBackground" type="string" />
    <field id="codeFont" type="node" />
    <field id="codeColor" type="string" />
    <field id="codeAlign" type="string" />
    <field id="codePadding" type="array" />
    <field id="codeBackground" type="string" />
    <field id="h1Font" type="node" />
    <field id="h1Color" type="string" />
    <field id="h1Align" type="string" />
    <field id="h2Font" type="node" />
    <field id="h2Color" type="string" />
    <field id="h2Align" type="string" />
    <field id="h3Font" type="node" />
    <field id="h3Color" type="string" />
    <field id="h3Align" type="string" />
    <field id="h4Font" type="node" />
    <field id="h4Color" type="string" />
    <field id="h4Align" type="string" />
    <field id="hrColor" type="string" />
    <field id="hrSize" type="int" />
    <field id="animatedScrolling" type="boolean" alias="scroller.animatedScrolling" />
    <field id="scrollFraction" type="integer" alias="scroller.scrollFraction" />
    <field id="scrollRatio" type="integer" alias="scroller.scrollRatio" />
    <field id="overflows" type="boolean" />
    <function name="render" />
</interface>

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

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:

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

BrighterScript version

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

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

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

If you want an optimised non-interactive clipped render:

view@.render(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
  2. install npm dependencies
    npm install
  3. Transpile to vanilla brightscript (under /dist)
    npm run build

Debugging

This repository comes pre-configured to work with the 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.

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago