lineblocks

package module
v0.0.0-...-0ace3aa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 8 Imported by: 1

README

goldmark-lineblocks

GoDoc

This goldmark parser extension adds support for inline blocks in markdown.

var md = goldmark.New(
    lineblocks.Enable,
)
err := md.Convert(source, os.Stdout)
if err != nil {
    log.Fatal(err)
}

A line block is a sequence of lines beginning with a vertical bar (|) followed by a space. The division into lines will be preserved in the output, as will any leading spaces; otherwise, the lines will be formatted as Markdown. This is useful for verse and addresses:

| The limerick packs laughs anatomical
| In space that is quite economical.
|    But the good ones I've seen
|    So seldom are clean
| And the clean ones so seldom are comical

| 200 Main St.
| Berkeley, CA 94718

The lines can be hard-wrapped if needed.

| The Right Honorable Most Venerable and 
  Righteous Samuel L. Constable, Jr.
| 200 Main St.
| Berkeley, CA 94718

This syntax is borrowed from reStructuredText and Pandoc.

Documentation

Overview

Package lineblocks is a extension for the goldmark (http://github.com/yuin/goldmark).

This extension adds support for line blocks in markdown.

A LineBlocks is a sequence of lines beginning with a vertical bar (|) followed by a space. The division into lines will be preserved in the output, as will any leading spaces; otherwise, the lines will be formatted as Markdown. This is useful for verse and addresses:

| The limerick packs laughs anatomical
| In space that is quite economical.
|    But the good ones I've seen
|    So seldom are clean
| And the clean ones so seldom are comical

| 200 Main St.
| Berkeley, CA 94718

The lines can be hard-wrapped if needed.

| The Right Honorable Most Venerable and Righteous Samuel L.
  Constable, Jr.
| 200 Main St.
| Berkeley, CA 94718

This syntax is borrowed from reStructuredText.

Example
package main

import (
	"log"
	"os"

	lineblocks "github.com/mdigger/goldmark-lineblocks"
	"github.com/yuin/goldmark"
)

func main() {
	var md = goldmark.New(
		lineblocks.Enable,
		// goldmark.WithExtensions(lineblocks.Extension),
	)
	var source = []byte(`
| The limerick packs laughs anatomical
| In space that is quite economical.
|    But the good ones I've seen
|    So seldom are clean
| And the clean ones so seldom are comical`)
	err := md.Convert(source, os.Stdout)
	if err != nil {
		log.Fatal(err)
	}
}
Output:

<div class="line-block">
<div class="line">The limerick packs laughs anatomical</div>
<div class="line">In space that is quite economical.</div>
<div class="line">&nbsp;&nbsp;&nbsp;But the good ones I've seen</div>
<div class="line">&nbsp;&nbsp;&nbsp;So seldom are clean</div>
<div class="line">And the clean ones so seldom are comical</div>
</div>

Index

Examples

Constants

This section is empty.

Variables

Enable is goldmark.Option for line blocks extension.

View Source
var Extension goldmark.Extender = new(defaultExtension)

Extension is a initialized goldmark extension for line blocks support.

View Source
var KindLineBlock = ast.NewNodeKind("LineBlock")

KindLineBlock is a NodeKind of the LineBlock node.

View Source
var KindLineBlockItem = ast.NewNodeKind("LineBlockItem")

KindLineBlock is a NodeKind of the LineBlock node.

View Source
var ParagraphTransformer parser.ParagraphTransformer = new(transformer)

ParagraphTransformer is a ParagraphTransformer implementation that parses and transform line blocks from paragraphs.

Functions

func NewHTMLRenderer

func NewHTMLRenderer(opts ...html.Option) renderer.NodeRenderer

NewHTMLRenderer returns a new sectionHTMLRenderer

Types

type LineBlock

type LineBlock struct {
	ast.BaseBlock
}

A LineBlock struct represents a list of inline text block.

func NewLineBlock

func NewLineBlock() *LineBlock

NewLineBlock return new initialized LineBlock.

func (*LineBlock) Dump

func (b *LineBlock) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*LineBlock) Kind

func (*LineBlock) Kind() ast.NodeKind

Kind implements Node.Kind.

type LineBlockItem

type LineBlockItem struct {
	ast.BaseBlock
	Padding int
}

A LineBlockItem struct represents a list of inline text block.

func NewLineBlockItem

func NewLineBlockItem(padding int) *LineBlockItem

NewLineBlockItem return new initialized LineBlockItem.

func (*LineBlockItem) Dump

func (l *LineBlockItem) Dump(source []byte, level int)

Dump implements Node.Dump.

func (*LineBlockItem) Kind

func (*LineBlockItem) Kind() ast.NodeKind

Kind implements Node.Kind.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL