Add all variation for BonzaiMark

pull/66/head
rwxrob 2 years ago
parent 717693ff6f
commit 199a74b181
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -372,11 +372,11 @@ want the specific reasons.
`Z.PrintInWrap(a string)` - shorthand for fmt.Print(Z.InWrap(a string))
`Z.PrintMark(a string)` - shorthand for fmt.Print(Z.Mark(a string))
`
`Z.PrintEmphf(a string, f ...any)` - fmt.Print(Z.Emphf(a string, f ...any))
`Z.PrintWrapf(a string, f ...any)` - fmt.Print(Z.Wrapf(a string, f ...any))
`Z.PrintIndent(a string, f ...any)` - fmt.Print(Z.Indentf(a string, f ...any))
`Z.PrintInWrapf(a string, f ...any)` - fmt.Print(Z.InWrapf(a string, f ...any))
`Z.PrintMarkf(a string, f ...any)` - fmt.Print(Z.Markf(a string, f ...any))
`Z.PrintfEmph(a string, f ...any)` - fmt.Print(Z.Emphf(a string, f ...any))
`Z.PrintfWrap(a string, f ...any)` - fmt.Print(Z.Wrapf(a string, f ...any))
`Z.PrintfIndent(a string, f ...any)` - fmt.Print(Z.Indentf(a string, f ...any))
`Z.PrintfInWrap(a string, f ...any)` - fmt.Print(Z.InWrapf(a string, f ...any))
`Z.PrintfMark(a string, f ...any)` - fmt.Print(Z.Markf(a string, f ...any))
## Acknowledgements

@ -1,6 +1,7 @@
package Z
import (
"fmt"
"regexp"
"strconv"
"unicode"
@ -156,7 +157,7 @@ MAIN:
return blocks
}
// Emph renders BonzaiMark emphasis spans specifically for
// Mark renders BonzaiMark emphasis spans specifically for
// VT100-compatible terminals (which almost all are today):
//
// *Italic*
@ -295,3 +296,73 @@ func Mark(in string) string {
return out
}
// Emphf calls fmt.Sprintf on the string before passing it to Emph.
func Emphf(a string, f ...any) string {
return Emph(fmt.Sprintf(a, f...))
}
// Indentf calls fmt.Sprintf on the string before passing it to Indent.
func Indentf(a string, f ...any) string {
return Indent(fmt.Sprintf(a, f...))
}
// Wrapf calls fmt.Sprintf on the string before passing it to Wrap.
func Wrapf(a string, f ...any) string {
return Wrap(fmt.Sprintf(a, f...))
}
// InWrapf calls fmt.Sprintf on the string before passing it to InWrap.
func InWrapf(a string, f ...any) string {
return InWrap(fmt.Sprintf(a, f...))
}
// Markf calls fmt.Sprintf on the string before passing it to Mark.
func Markf(a string, f ...any) string {
return Mark(fmt.Sprintf(a, f...))
}
// PrintEmph passes string to Emph and prints it.
func PrintEmph(a string) { fmt.Print(Emph(a)) }
// PrintWrap passes string to Wrap and prints it.
func PrintWrap(a string) { fmt.Print(Wrap(a)) }
// PrintIndent passes string to Indent and prints it.
func PrintIndent(a string) { fmt.Print(Indent(a)) }
// PrintInWrap passes string to InWrap and prints it.
func PrintInWrap(a string) { fmt.Print(InWrap(a)) }
// PrintMark passes string to Mark and prints it.
func PrintMark(a string) { fmt.Print(Mark(a)) }
// PrintEmphf calls fmt.Sprintf on the string before passing it to Emph
// and then printing it.
func PrintEmphf(a string, f ...any) {
fmt.Print(Emph(fmt.Sprintf(a, f...)))
}
// PrintWrapf calls fmt.Sprintf on the string before passing it to Wrap
// and then printing it.
func PrintWrapf(a string, f ...any) {
fmt.Print(Wrap(fmt.Sprintf(a, f...)))
}
// PrintIndentf calls fmt.Sprintf on the string before passing it to
// Indent and then printing it.
func PrintIndentf(a string, f ...any) {
fmt.Print(Indent(fmt.Sprintf(a, f...)))
}
// PrintInWrapf calls fmt.Sprintf on the string before passing it to
// InWrap and then printing it.
func PrintInWrapf(a string, f ...any) {
fmt.Print(InWrap(fmt.Sprintf(a, f...)))
}
// PrintMarkf calls fmt.Sprintf on the string before passing it to Mark
// and then printing it.
func PrintMarkf(a string, f ...any) {
fmt.Print(Mark(fmt.Sprintf(a, f...)))
}

@ -13,6 +13,93 @@ func ExampleLines() {
// ["line one" "line two"]
}
// --------------------------- start Blocks ---------------------------
func ExampleBlocks_bulleted() {
in := `
* some thing
* another thing
* another block
* here
`
fmt.Printf("%q\n", Z.Blocks(in)[1])
//Output:
// "* another block\n* here"
}
func ExampleBlocks_numbered() {
in := `
1. some thing
2. another thing
1. another block
2. here
`
fmt.Printf("%q\n", Z.Blocks(in)[1])
//Output:
// "1. another block\n2. here"
}
func ExampleBlocks_paragraph() {
in := `
Simple paragraph
here on multiple
lines
And another one here
with just a bit more.
`
fmt.Printf("%q\n", Z.Blocks(in)[1])
// Output:
// "And another one here with just a bit more."
}
func ExampleBlocks_verbatim() {
// Note that the following begins consistently with three tabs so that
// dedenting works consistently. There are four spaces before Now and
// the verbatim block. Notice that even the blank line within the
// verbatim block must have the exact same indentation and spaced
// verbatim prefix. (If using Vi/m try set :list to display them.)
in := `
Must have another block type first.
Now we can start
a Verbatim
block.
Which can have blank lines, even.
And back to a paragraph block.
`
fmt.Printf("%q\n", Z.Blocks(in)[0])
fmt.Printf("%q\n", Z.Blocks(in)[1])
fmt.Printf("%q\n", Z.Blocks(in)[2])
//Output:
// "Must have another block type first."
// "Now we can start\na Verbatim\nblock.\n\nWhich can have blank lines, even."
// "And back to a paragraph block."
}
// -------------------------- main BonzaiMark -------------------------
func ExampleEmph_basics() {
// Emph observes the rwxrob/term escapes
@ -76,93 +163,329 @@ func ExampleInWrap() {
// " some\n that\n is\n indented\n"
}
func ExampleBlocks_bulleted() {
func ExampleMark() {
in := `
Must have *another* block before verbatim:
* some thing
* another thing
Now we can start
a Verbatim
block.
* another block
* here
Which can have blank lines, even.
And back to a paragraph block.
* **foo**
* bar
And a numbered list
1. Something
2. here
That's really it.
`
fmt.Printf("%q\n", Z.Blocks(in)[1])
fmt.Println("----------------------")
fmt.Print(Z.Mark(in))
fmt.Println("----------------------")
//Output:
// "* another block\n* here"
// ----------------------
// Must have <italic>another<reset> block before verbatim:
//
// Now we can start
// a Verbatim
// block.
//
// Which can have blank lines, even.
//
// And back to a paragraph block.
//
// * <bold>foo<reset>
// * bar
//
// And a numbered list
//
// 1. Something
// 2. here
//
// That's really it.
//
// ----------------------
}
func ExampleBlocks_numbered() {
// ------------------------ Sprintf variations ------------------------
func ExampleEmphf() {
fmt.Println(Z.Emphf(`some *%v* thing`, "italic"))
// Output:
// some <italic>italic<reset> thing
}
func ExampleWrapf() {
col := Z.Columns
Z.Columns = 3
fmt.Println(Z.Wrapf(`some %v here`, 10))
Z.Columns = col
// Output:
// some
// 10
// here
}
func ExampleIndentf() {
in := Z.IndentBy
Z.IndentBy = 3
fmt.Println(Z.Indentf("-----\nindented by %v here", Z.IndentBy))
Z.IndentBy = in
// Output:
// -----
// indented by 3 here
}
func ExampleInWrapf() {
in := Z.IndentBy
col := Z.Columns
Z.IndentBy = 3
Z.Columns = 10
fmt.Println(
Z.InWrapf("-----\nindented by %v here and wrapped at %v",
Z.IndentBy, Z.Columns,
))
Z.IndentBy = in
Z.Columns = col
// -----
// indented
// by 3
// here
// and
// wrapped
// at 10
}
func ExampleMarkf() {
in := `
Must have *%v* block before verbatim:
1. some thing
2. another thing
Now we can start
a Verbatim
block.
1. another block
Which can have blank lines, even.
And back to a %v block.
* **foo**
* bar
And a numbered list
1. Something
2. here
That's really it.
`
fmt.Printf("%q\n", Z.Blocks(in)[1])
fmt.Println("----------------------")
fmt.Print(Z.Markf(in, "another", "paragraph"))
fmt.Println("----------------------")
//Output:
// "1. another block\n2. here"
// ----------------------
// Must have <italic>another<reset> block before verbatim:
//
// Now we can start
// a Verbatim
// block.
//
// Which can have blank lines, even.
//
// And back to a paragraph block.
//
// * <bold>foo<reset>
// * bar
//
// And a numbered list
//
// 1. Something
// 2. here
//
// That's really it.
//
// ----------------------
}
func ExampleBlocks_paragraph() {
in := `
Simple paragraph
here on multiple
lines
// ------------------------- Print variations -------------------------
And another one here
with just a bit more.
func ExamplePrintEmph_basics() {
`
// Emph observes the rwxrob/term escapes
// (see package documentation for more)
fmt.Printf("%q\n", Z.Blocks(in)[1])
term.Italic = `<italic>`
term.Bold = `<bold>`
term.BoldItalic = `<bolditalic>`
term.Under = `<under>`
term.Reset = `<reset>`
Z.PrintEmph("*ITALIC*\n")
Z.PrintEmph("**BOLD**\n")
Z.PrintEmph("***BOLDITALIC***\n")
Z.PrintEmph("<UNDER>\n") // keeps brackets
// Output:
// "And another one here with just a bit more."
// <italic>ITALIC<reset>
// <bold>BOLD<reset>
// <bolditalic>BOLDITALIC<reset>
// <<under>UNDER<reset>>
}
func ExampleBlocks_verbatim() {
func ExamplePrintWrap() {
col := Z.Columns
Z.Columns = 10
Z.PrintWrap(`some thing here that is more than 10 characters`)
Z.Columns = col
// Output:
// some thing
// here that
// is more
// than 10
// characters
}
// Note that the following begins consistently with three tabs so that
// dedenting works consistently. There are four spaces before Now and
// the verbatim block. Notice that even the blank line within the
// verbatim block must have the exact same indentation and spaced
// verbatim prefix. (If using Vi/m try set :list to display them.)
func ExamplePrintInWrap() {
defer func() { Z.IndentBy = Z.IndentBy }()
indent := Z.IndentBy
col := Z.Columns
Z.Columns = 10
Z.IndentBy = 4
fmt.Println("-----")
Z.PrintInWrap("some\nthat is \n indented")
Z.IndentBy = indent
Z.Columns = col
// Output:
// -----
// some
// that
// is
// indented
}
func ExamplePrintMark() {
in := `
Must have another block type first.
Must have *another* block before verbatim:
Now we can start
a Verbatim
block.
Which can have blank lines, even.
And back to a paragraph block.
* **foo**
* bar
And a numbered list
1. Something
2. here
That's really it.
`
fmt.Printf("%q\n", Z.Blocks(in)[0])
fmt.Printf("%q\n", Z.Blocks(in)[1])
fmt.Printf("%q\n", Z.Blocks(in)[2])
fmt.Println("----------------------")
Z.PrintMark(in)
fmt.Println("----------------------")
//Output:
// "Must have another block type first."
// "Now we can start\na Verbatim\nblock.\n\nWhich can have blank lines, even."
// "And back to a paragraph block."
// ----------------------
// Must have <italic>another<reset> block before verbatim:
//
// Now we can start
// a Verbatim
// block.
//
// Which can have blank lines, even.
//
// And back to a paragraph block.
//
// * <bold>foo<reset>
// * bar
//
// And a numbered list
//
// 1. Something
// 2. here
//
// That's really it.
//
// ----------------------
}
func ExampleMark() {
// --------------------- Print(Sprintf) variations --------------------
func ExamplePrintEmphf() {
Z.PrintEmphf(`some *%v* thing`, "italic")
// Output:
// some <italic>italic<reset> thing
}
func ExamplePrintfWrapf() {
col := Z.Columns
Z.Columns = 3
Z.PrintWrapf(`some %v here`, 10)
Z.Columns = col
// Output:
// some
// 10
// here
}
func ExamplePrintIndentf() {
in := Z.IndentBy
Z.IndentBy = 3
Z.PrintIndentf("-----\nindented by %v here", Z.IndentBy)
Z.IndentBy = in
// Output:
// -----
// indented by 3 here
}
func ExamplePrintInWrapf() {
in := Z.IndentBy
col := Z.Columns
Z.IndentBy = 3
Z.Columns = 10
Z.PrintInWrapf("-----\nindented by %v here and wrapped at %v",
Z.IndentBy, Z.Columns,
)
Z.IndentBy = in
Z.Columns = col
// -----
// indented
// by 3
// here
// and
// wrapped
// at 10
}
func ExamplePrintMarkf() {
in := `
Must have *another* block before verbatim:
Must have *%v* block before verbatim:
Now we can start
a Verbatim
@ -170,7 +493,7 @@ func ExampleMark() {
Which can have blank lines, even.
And back to a paragraph block.
And back to a %v block.
* **foo**
* bar
@ -185,7 +508,7 @@ func ExampleMark() {
`
fmt.Println("----------------------")
fmt.Print(Z.Mark(in))
Z.PrintMarkf(in, "another", "paragraph")
fmt.Println("----------------------")
//Output:

Loading…
Cancel
Save