GithubHelp home page GithubHelp logo

simonecorsi / go-declarative-markdown Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 719 KB

๐Ÿ“‘ Helps you generate markdown in a declarative way without having to interpolate strings yourself

License: MIT License

Go 99.49% Makefile 0.51%
go golang markdown generator declarative programmatically markdown-generator

go-declarative-markdown's Introduction

Declarative Markdown

Declarative Markdown Gopher Logo

Table of content

About

This package helps in generating markdown in a declarative way without having to handle strings yourself

This README has been generated using this own package! You can see the code example here

Requirements

  • git
  • go 1.16

Installation

go get github.com/simonecorsi/go-declarative-markdown

Usage

package main

import mkd "github.com/simonecorsi/go-declarative-markdown/markdown"

function main() {
  md := mkd.CreateMarkdown("My h1 Header")
  md.Header("About")
  md.Paragraph("Lorem Ipsum")
  md.Render() // save to file or whatever
}

API

CreateMarkdown

CreateMarkdown(title string) *Markdown

Initialize new Markdown instance with h1 title on top.

Returns reference to the Markdown to allow chaining

GetLine

GetLine(lineNumber int) string

Utilities to get a line in the markdown, this is a slice before rendering so LineBreak don't counts

Render

Render() string

Renders all the content add in this markdown instance

Header

Header(text string, weigth int) *Markdown

Creates an heading, you can specify the weigth [1-6]

Returns reference to the Markdown to allow chaining

AddLine

AddLine(text string) *Markdown

Utilities that pushes content to the slices of lines, this is used internally by each other command

Returns reference to the Markdown to allow chaining

Paragraph

Paragraph(text string) *Markdown

Create a generic paragraph of text

Returns reference to the Markdown to allow chaining

Quote

Quote(text string) *Markdown

Create quoted paragraph of text

Returns reference to the Markdown to allow chaining

Code

Code(text string, language string) *Markdown

Creates a snippet of code with syntax highligh

Returns reference to the Markdown to allow chaining

HorizontalLine

HorizontalLine() *Markdown

Creates an horizontal line to dive sections

Returns reference to the Markdown to allow chaining

Image

Image(altText string, filepath string) *Markdown

Creates an image with a title

Returns reference to the Markdown to allow chaining

List

List(items []ListItem, numbered bool) *Markdown

Creates a list of item, either numbered or with dashes, default to dashes

Returns reference to the Markdown to allow chaining

type ListItem struct {
	Label string
	Depth int
}

Task

Task(items []TaskItem, numbered bool) *Markdown

Creates a list with checkboxes

Returns reference to the Markdown to allow chaining

type TaskItem struct {
	Label   string
	Checked bool
}

Table

Table(headers []string, rows [][]string) *Markdown

Creates a table

Returns reference to the Markdown to allow chaining

GenerateToc

GenerateToc(index int) *Markdown

Creates table of content and adds it after the main h1 title, call it before rendering!

Contributing

Project is pretty simple and straight forward for what is my needs, but if you have any idea you're welcome.

This projects uses Conventional Commit Format so be sure to use standard commit format or PR won't be accepted

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Simone Corsi - @im_simonecorsi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.