console_markdown 0.0.3

SDKdartflutter
Platformandroidioswindowslinuxmacos

A console markdown for formatting and color, using chalk as a dependency. No setup required, quick and easy to use.

Pub.dev package GitHub repository

Console Markdown

Change the console's style using markdown. Easy to use, with no setup required.

This package uses an implementation of marked for the Markdown syntax, and chalkdart for the console styling.

Features

  • No setup required
  • Symbol markdown syntax
  • Tags markdown, HTML-like syntax
  • Optional strict markdown syntax, to avoid mistakes

Getting started

Install it using pub:

dart pub add console_markdown

And import the package:

import 'package:console_markdown/console_markdown.dart';

Usage

Apply the markdown to a string using the ConsoleMarkdown.apply() method:

print(ConsoleMarkdown.apply('Hello **World**!'));

You can also use the string.toConsole() extension method:

print('Hello, **world**!'.toConsole());

print(
  '''
    Hello **World**!
    __Looks *pretty* easy__
    
    <console color="red" background="black" bold> Console Markdown </console>
  '''.toConsole();
)

Markdown Cheatsheet

Symbols

SymbolPropertyExampleResult
**bold**text**text
*italic*text*text
__underline__text__text
~~strikethrough~~text~~text
^superscript^text^text
~subscript~text~text
___double-underline___text___
!!blink!!text!!
!!!rapid-blink!!!text!!!
||hidden||text||
^^inverse^^text^^
`dim`text`

Tags

TagPropertyExample
<reset>reset<reset>text
<overline>overline<overline>text</overline>
<br>line break<br>
<b>bold<b>text</b>
<i>italic<i>text</i>
<u>underline<u>text</u>
<uu>double-underline<uu>text</uu>
<s>strikethrough<s>text</s>
<sup>superscript<sup>text</sup>
<sub>subscript<sub>text</sub>

Note: All Symbol property names can be used as a tag.

Colors

The following colors are available as tags:

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • gray

Using the flag background, you can set the background color of the text.

Dynamic Tags

Dynamic TagPropertyExampleDescription
<console>console<console color="red" background="#000000" bold>text</console>All property names above can be used as a tag property.
<rgb(r, g, b)>rgb<rgb(255, 0, 0)>text</rgb>Can be set as a background by adding a background property.
<hex([#]...)>hex<hex(#ff0000)>text</hex>Can be set as a background by adding a background property.
<#...>short hex<#ff0000>text</#>Can be set as a background by adding a background property.

Markdown syntax alternatives

If you're feeling paranoid about performance, you can use simpler versions of the markdown with only certain placeholders.

MarkdownDescription
ConsoleMarkdownSymbolsContains all symbols only.
ConsoleMarkdownBasicContains only the console tag, which can be used to set any of the other properties.
ConsoleMarkdownContains all markdown syntax.

Example

import 'package:console_markdown/console_markdown.dart';

void main() {
  print(
    '''
      Hello **World**!
      __Looks *pretty* easy__

      <console color="red" background="black" bold> Console Markdown </console>
    '''.toConsole()
  );
}