PathrockNetwork Gno Explorer
HomeBlocksTransactionsRealmsPackagesValidatorsAnalytics

PathrockNetwork Gno Explorer — an independent explorer for Gno.land Mainnet (gnoland-1), operated by PathrockNetwork. Not an official Gno.land service.

gnowebarchive RPC

gno.land/p/moul/mdtable/v0

Package
Open in gnoweb ↗

Overview

Kind
Pure package
Name
v0
Namespace
moul / mdtable
Files
3 (gnomod.toml)
Exported functions
n/a — not supported for pure packages by the node (vm/qfuncs)
Module
gno.land/p/moul/mdtable/v0
gno
0.9

Files (3)

  • gnomod.tomltoml
  • mdtable.gnogno
  • mdtable_test.gnogno
mdtable.gnogno
1// Package mdtable provides a simple way to create Markdown tables.2//3// Example usage:4//5//	import "gno.land/p/moul/mdtable/v0"6//7//	func Render(path string) string {8//	    table := mdtable.Table{9//	        Headers: []string{"ID", "Title", "Status", "Date"},10//	    }11//	    table.Append([]string{"#1", "Add a new validator", "succeed", "2024-01-01"})12//	    table.Append([]string{"#2", "Change parameter", "timed out", "2024-01-02"})13//	    return table.String()14//	}15//16// Output:17//18//	| ID | Title | Status | Date |19//	| --- | --- | --- | --- |20//	| #1 | Add a new validator | succeed | 2024-01-01 |21//	| #2 | Change parameter | timed out | 2024-01-02 |22package mdtable2324import (25	"strings"26)2728type Table struct {29	Headers []string30	Rows    [][]string31	// XXX: optional headers alignment.32}3334func (t *Table) Append(row []string) {35	t.Rows = append(t.Rows, row)36}3738func (t Table) String() string {39	// XXX: switch to using text/tabwriter when porting to Gno to support40	// better-formatted raw Markdown output.4142	if len(t.Headers) == 0 && len(t.Rows) == 0 {43		return ""44	}4546	var sb strings.Builder4748	if len(t.Headers) == 0 {49		t.Headers = make([]string, len(t.Rows[0]))50	}5152	// Print header.53	sb.WriteString("| " + strings.Join(t.Headers, " | ") + " |\n")54	sb.WriteString("|" + strings.Repeat(" --- |", len(t.Headers)) + "\n")5556	// Print rows.57	for _, row := range t.Rows {58		escapedRow := make([]string, len(row))59		for i, cell := range row {60			escapedRow[i] = strings.ReplaceAll(cell, "|", "|") // Escape pipe characters.61		}62		sb.WriteString("| " + strings.Join(escapedRow, " | ") + " |\n")63	}6465	return sb.String()66}67

Functions

not supported for pure packages by the node (vm/qfuncs)

Signatures reconstructed verbatim from vm/qfuncs — interface params keep their inline definitions.